Thursday, November 17, 2016

Delete Git Branch Local and Remote

Executive Summary

$ git branch -d 
$ git push origin --delete 

Delete Local Branch

To delete the local branch use:
$ git branch -d branch_name
Note: The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for --delete --force, which deletes the branch "irrespective of its merged status." [Source: man git-branch]

Delete Remote Branch [Updated on 1-Feb-2012]

As of Git v1.7.0, you can delete a remote branch using
$ git push origin --delete 
which might be easier to remember than
$ git push origin :

Friday, September 02, 2016

Gradle Dependencies

https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html
gradle -q api:dependencies --configuration testCompile

Wednesday, August 17, 2016

Externalize Common Gradle Functions


Content of helpers/common-methods.gradle:

// Define methods as usual
def commonMethod1(param){
    return true
}
def commonMethod2(param){
    return true
}

// Export methods by turning them into closures
ext{
    commonMethod1 = this.&commonMethod1
    otherNameForMethod2 = this.&commonMethod2
}
And this is how I use those methods in another script:

// Use double-quotes, otherwise $ won't work
apply from: "http://myhelpers.com/helpers/common-methods.gradle"

// You can also use URLs
//apply from: "https://bitbucket.org/mb/build_scripts/raw/master/common-methods.gradle"

task myBuildTask{    
    def myVar = commonMethod1("parameter1")
    otherNameForMethod2(myVar)    
}

Thursday, August 04, 2016

Trust Relationship and Policies for AWS API Gateway and Lambdas

Your Policy for the lambda should set up everything your lambda is allowed to do. This includes passing a role.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1470153553000",
            "Effect": "Allow",
            "Action": [
                "dynamodb:*"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-west-2:439753510372:table/YoYoDyne_Products"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "lambda:InvokeFunction"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:*:*:*"
            ]
        },
        {
            "Sid": "Stmt1449789105000",
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Your policy also needs to have a trust relationship.
{
   "Version": "2012-10-17",
   "Statement": [
       {
           "Sid": "",
           "Effect": "Allow",
           "Principal": {
               "Service": ["lambda.amazonaws.com", "apigateway.amazonaws.com"]
           },
           "Action": "sts:AssumeRole"
       }
   ]
}

Tuesday, August 02, 2016

Java HTTPS Over VPN: Unrecognized SSL message, plaintext connection?

Many times a VPN will screw around with the IPV4 settings for secure connections.
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
Add these VM options to avoid problems:
-Djsse.enableSNIExtension=false
-Djava.net.preferIPv4Stack=true

Wednesday, June 15, 2016

Find What Process is Running on a Port OSX

17:12:52 ~/data/github/dronze {feature/#58} $ lsof -i :8000
COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    29680 claytongraham  143u  IPv6 0xb9a0c6ac4b96e77f      0t0  TCP *:irdmi (LISTEN)

Monday, June 13, 2016

Minimum Mongo Restore Permissions

So this would work to restore a single database: Backup
sudo mongodump -h localhost -d stuffdb --username restoreSingleDB --password Moon1234 \
  -o stuffdb.20160724.dump
Restore
db.addUser( {
    user: "restoreSingleDB",
    pwd: "Moon1234",
    roles: [ "readWrite", "userAdmin" ]
} )

mongorestore --db  --username restoreSingleDB --password Moon1234 /
So this would work to restore all databases including user data:
db.addUser( {
    user: "restoreAll",
    pwd: "Moon1234",
    roles: [ "readWriteAnyDatabase", "userAdminAnyDatabase" ]
} )

mongorestore --username restoreAll --password Moon1234 /