Tuesday, 7 September 2021

git remove remote branch chnages

move to your current branch 

then fire rest comment like below

commit id from you want to revert changes.

b6789988d5d043d47569 your commit1

b6789988d5d043d4756 your commit2

b6789988d5d0b6789988d5d043d47 your commit3

b6789988d5d043d47 changes removed from hare 

 git reset --hard b6789988d5d043d47


then push your reset changes

git push -f origin branchname


https://gitcheatsheet.org/?gclid=Cj0KCQjwwNWKBhDAARIsAJ8Hkhdlxai30BVPljj5WDd9xd6uFTe7HIr406NPx7WvT7WCvSWfEeF3R6EaAmxJEALw_wcB


Tuesday, 22 June 2021

Redis clustering

 https://medium.com/@pubuduboteju95/deep-dive-into-redis-clustering-1d71484578a9

Thursday, 6 May 2021

deny and allow access to s3 bucket

 https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html



{ "Id":"PolicyId2", "Version":"2012-10-17", "Statement":[ { "Sid":"AllowIPmix", "Effect":"Allow", "Principal":"*", "Action":"s3:*", "Resource": [ "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*" ], "Condition": { "IpAddress": { "aws:SourceIp": [ "54.240.143.0/24", "2001:DB8:1234:5678::/64" ] }, "NotIpAddress": { "aws:SourceIp": [ "54.240.143.128/30", "2001:DB8:1234:5678:ABCD::/80" ] } } } ] }


https://s3tools.org/kb/item10.htm



How to restrict access to a bucket to specific IP addresses

To secure our files on Amazon S3, we can restrict access to a S3 bucket to specific IP addresses.

The following bucket policy grants permissions to any user to perform any S3 action on objects in the specified bucket. However, the request must originate from the range of IP addresses specified in the condition. The condition in this statement identifies 192.168.143.* range of allowed IP addresses with one exception, 192.168.143.188.

{
    "Version": "2012-10-17",
    "Id": "S3PolicyIPRestrict",
    "Statement": [
        {
            "Sid": "IPAllow",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::bucket/*",
            "Condition" : {
                "IpAddress" : {
                    "aws:SourceIp": "192.168.143.0/24"
                },
                "NotIpAddress" : {
                    "aws:SourceIp": "192.168.143.188/32"
                }
            }
        }
    ]
}

The IPAddress and NotIpAddress values specified in the condition uses CIDR notation described in RFC 2632. For more information, go to http://www.rfc-editor.org/rfc/rfc4632.txt

Tuesday, 4 May 2021

access S3 bucket without access key and secrete key

 https://stackoverflow.com/questions/44062813/aws-s3-upload-without-access-and-secret-key-in-java

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
              .withCredentials(new InstanceProfileCredentialsProvider(false))
              .build();

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_provider.html
https://stackoverflow.com/questions/52286306/using-ec2-metadata-credentials-in-the-laravel-filesystem

Thursday, 15 April 2021

string-concatenation-vs-stringbuilder-vs-string-format-performance

 https://kylewbanks.com/blog/java-string-concatenation-vs-stringbuilder-vs-string-format-performance



public class TestStrings {

    private static final String PROFILE_PICTURE_URL_BASE = "https://cdn.myapp.com/user/";
    private static final String PROFILE_PICTURE_URL_EXTENSION = ".png";
    private static final String PROFILE_PICTURE_URL = "https://cdn.myapp.com/user/%d.png";

    private static final int NUM_ITERATIONS = 1000000;
    
    public static void main(String[] args) {
        int userId;
        long startTime;
        
        // String Concatentation
        startTime = System.currentTimeMillis();
        for (userId = 0; userId < NUM_ITERATIONS; userId ++) {
            String profilePictureUrl = PROFILE_PICTURE_URL_BASE + userId + PROFILE_PICTURE_URL_EXTENSION;
        }
        System.out.println("String Concatentation: " + (System.currentTimeMillis() - startTime) + "ms");
        
        // StringBuilder
        startTime = System.currentTimeMillis();
        for (userId = 0; userId < NUM_ITERATIONS; userId ++) {
            StringBuilder sb = new StringBuilder(PROFILE_PICTURE_URL_BASE);
            sb.append(userId);
            sb.append(PROFILE_PICTURE_URL_EXTENSION);
            
            String profilePictureUrl = sb.toString();
        }
        System.out.println("StringBuilder: " + (System.currentTimeMillis() - startTime) + "ms");
        
        // String.format
        startTime = System.currentTimeMillis();
        for (userId = 0; userId < NUM_ITERATIONS; userId ++) {
            String profilePictureUrl = String.format(PROFILE_PICTURE_URL, userId);
        }
        System.out.println("String.format: " + (System.currentTimeMillis() - startTime) + "ms");
    }
}

Monday, 12 April 2021

Making dynamic query

 https://stackoverflow.com/questions/8549619/mysql-dynamically-build-query-string-in-a-stored-procedure-based-on-logic



CREATE  PROCEDURE `activate_games_pawan`(IN `gameId` INT(20))

BEGIN   

DECLARE whereCondition varchar(200);

CASE WHEN gameId>0 THEN

   SET @whereCondition =CONCAT(" ","sh_games.game_id=",gameId);

  SELECT @whereCondition;

  ELSE

  SET @whereCondition=1;

    SELECT @whereCondition;

  END CASE;

 SET @query=CONCAT("SELECT * FROM sh_games where ", @whereCondition);

  select @query;

PREPARE stmt FROM @query;

EXECUTE stmt;

DEALLOCATE PREPARE stmt;

END

Wednesday, 7 April 2021

Delete duplicate rows from mysql

  SET SQL_SAFE_UPDATES = 0;


    DELETE t1  FROM sh_learning_material AS t1

INNER JOIN sh_learning_material AS t2 

WHERE 

t1.id<t2.id AND

    t1.company_id = t2.company_id;