Command | Description | Example | Source |
---|---|---|---|
git reset --hard HEAD^ | Delete last local commit | https://sethrobertson.github.io/GitFixUm/fixup.html#remove_last | |
git log origin/master..HEAD | Check local commits which aren't pushed | https://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits | |
git diff origin/master..HEAD | Diff local commits which aren't pushed | ||
git diff <commit_id> <remote> /<branch> |
Diff a commit to remote branch | git diff 0664e297fed39f65e58e9bfb2801377d21f9157a origin/master | |
git diff <commit_id>^ <commit_id> | Diff a commit to previous commit | https://stackoverflow.com/questions/17563726/how-to-see-the-changes-in-a-commit | |
git log <commit_id> -<number> |
Log a limited number of previous changes of a commit | git log d08bcd673e1749bf1eb6f38f32684a712b7444fe -2 | https://git-scm.com/docs/git-log |
git fetch origin | |||
git reset --hard origin/master | |||
git clean | Reset local branch to exactly match remote | https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head | |
git pull --rebase | Pull (fetch + rebase) |
Flag | Description |
---|---|
-d | Include directories |
-n | Dry run only |
-i | Interactive mode |
-e | Exclude a pattern |
Command | Alt | Comments |
---|---|---|
Expand-Archive '.\file.zip' '.\unziped' | ||
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess | netstat -a -b -n -o | find "redis" |
taskkill /F /PID pid_number | ||
jar -xf .\redis-client.jar | ||
echo $Env:PATH | echo %PATH% | dir %HOMEPATH% |
mvn install:install-file -Dfile=<path-to-file> |
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> |
|
cat for Windows: type file.txt | ||
kill $(ps aux | grep 'java' | awk '{print $2}') | ||
Invoke-WebRequest -Uri "http://localhost:8080/task/add" -Body '{"first": 2, "second": 3}' -ContentType "application/json" -Method Post | ||
curl http://localhost:8080/task/add -H "Content-Type: application/json" -d '{"first": 4, "second": 5}' | ||
curl -X PUT http://localhost:8080/task/add -H "Content-Type: application/json" -d '{"first": 4, "second": 5}' | ||
maven-local-install() { mvn install:install-file -Dfile=$PWD/target/$1-$2.jar -DgroupId=com.davidagood -DartifactId=$1 -Dversion=$2 -Dpackaging=jar cp pom.xml ~/.m2/repository/$1/$2/$1-$2.pom } |
Description | Command | Alt | Refernece | Commments |
---|---|---|---|---|
chmod 400 ~/Downloads/pizza-keys.pem | ||||
ssh -i ~/Downloads/pizza-keys.pem ec2-user@<ip_address> | ||||
scp -r -i ~/Downloads/pizza-keys.pem ./pizza-luvrs ec2-user@<ip_address>:/home/ec2-user/pizza-luvrs | Remove destination folder name to overwrite existing contents at that location | |||
sudo yum update | ||||
curl -sL https://deb.nodesource.com/setup_12.x | bash - | curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash - | |||
sudo yum install -y nodejs | ||||
ab -n 100 -c 5 http://pizza-load-balancer-1476197772.us-east-1.elb.amazonaws.com/ |
aws dynamodb create-table --table-name MyTable --attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH AttributeName=SK,KeyType=RANGE --billing-mode PAY_PER_REQUEST --endpoint-url http://localhost:4566
With Global Secondary Index (GSI):
aws dynamodb create-table --table-name MyTable --attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S AttributeName=GSI1PK,AttributeType=S AttributeName=GSI1SK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH AttributeName=SK,KeyType=RANGE --global-secondary-indexes 'IndexName=GSI1,KeySchema=[{AttributeName=GSI1PK,KeyType=HASH},{AttributeName=GSI1SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' --billing-mode PAY_PER_REQUEST --endpoint-url http://localhost:4566
Using JSON file:
aws dynamodb create-table --cli-input-json file://create-table.json --e
ndpoint-url http://localhost:4566
create-table.json
{
"TableName": "SingleTableDesign",
"AttributeDefinitions": [
{
"AttributeName": "PK",
"AttributeType": "S"
},
{
"AttributeName": "SK",
"AttributeType": "S"
},
{
"AttributeName": "GSI1PK",
"AttributeType": "S"
},
{
"AttributeName": "GSI1SK",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "PK",
"KeyType": "HASH"
},
{
"AttributeName": "SK",
"KeyType": "RANGE"
}
],
"LocalSecondaryIndexes": [],
"GlobalSecondaryIndexes": [
{
"IndexName": "GSI1",
"KeySchema": [
{
"AttributeName": "GSI1PK",
"KeyType": "HASH"
},
{
"AttributeName": "GSI1SK",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
}
}
],
"BillingMode": "PAY_PER_REQUEST"
}
aws dynamodb put-item --table-name python-test --item '{"PK": {"S": "List"}, "SK": {"S": "List"}, "Value": {"L": [{"S": "0"}]}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[0] = :value" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "00" }}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[10] = :value" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "1" }}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[-10] = :value" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "-10" }}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[5] = 5" --expression-attribute-names '{"#Value": "Value"}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[10] = :value, #Value[20] = :value2" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "first" }, ":value2": {"S": "second"}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[20] = :value, #Value[10] = :value2" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "first-2" }, ":value2": {"S": "second-2"}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value = list_append(#Value, :values)" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":values": {"L": [{"S": "list_appen"}, {"S": "123"}]}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value = list_append(:values, #Value)" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":values": {"L": [{"S": "-1"}]}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[0] = if_not_exists(#Value[0], :value)" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "overwrite-0" }}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "List"}, "SK": {"S": "List"}}' --update-expression "SET #Value[100] = if_not_exists(#Value[1000], :value)" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":value": {"S": "overwrite-?" }}'
aws dynamodb put-item --table-name python-test --item '{"PK": {"S": "SET"}, "SK": {"S": "SET"}, "Value": {"SS": ["0"]}}'
aws dynamodb update-item --table-name python-test --key '{"PK": {"S": "SET"}, "SK": {"S": "SET"}}' --update-expression "SET #Value = list_append(#Value, ":values")" --expression-attribute-names '{"#Value": "Value"}' --expression-attribute-values '{":values": {"SS": ["1"]}}'
- Deploy Example
aws cloudformation deploy --template-file ./hbfl.start.template --stack-name hbfl-stack --parameter-overrides ImageIdParameter=ami-0323c3dd2da7fb37d VPCIdParameter=vpc-0a358a64ae71dc0eb SubnetListParameter=subnet-0fd30ed5b383a78fb,subnet-043f91637234fc4bf --capabilities CAPABILITY_IAM
- Note that re-running
aws cloudformat deploy
can be used for updates; It will use all the previous parameters and you can add overrides as needed
- Deploy Dry Run
aws cloudformation deploy ... --no-execute-changeset
- The output of this command will include the command to inspec the changeset:
aws cloudformation describe-change-set --change-set-name <cloudformation_changeset_arn>
- Execute Changeset
- aws cloudformation execute-change-set --change-set-name <cloudformation_changeset_arn>
brew install awsebcli
eb init
eb create
eb updated
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Resource": [
"<role_arn>"
]
}
]
}
https://www.trek10.com/blog/improving-the-aws-force-mfa-policy-for-iam-users
~/.aws/config
[default]
region = us-east-1
output = json
[profile local]
source_profile=default
dynamodb_endpoint_url=http://localhost:8000
[profile sso-stg]
sso_start_url = https://d-<account-id>.awsapps.com/start
sso_region = us-east-1
sso_account_id = <sso-account-id>
sso_role_name = <role-name>
region = us-east-1
output = json
[profile microtrader-admin]
source_profile = microtrader
role_arn = <arn_of_role_to_assume>
region = us-east-1
mfa_serial = <iam_user_mfa_device_arn>
~/.aws/credentials
[default]
aws_access_key_id = <id>
aws_secret_access_key = <key>
[local]
aws_access_key_id = dummy
aws_secret_access_key = dummy
[microtrader]
aws_access_key_id = <id>
aws_secret_access_key = <key>
Then to use the profile, export AWS_PROFILE=microtrader-admin
. When you run a command
it should prompt you for an MFA token.
aws ecr get-login --no-include-email --region us-east-1
- Run the resulting command or just run it in an
eval $()
docker build -t dockerproductionaws/microtrader-base .
docker tag dockerproductionaws/microtrader-base:latest <aws_ecr_url>/dockerproductionaws/microtrader-base:latest
docker push <aws_ecr_url>/dockerproductionaws/microtrader-base:latest
- ECS agent log location:
var/log/ecs
- ECS agent introspection endpoint:
curl -s localhost:51678/v1/metadata | jq
- ECS agent tasks endpoint:
curl -s localhost:51678/v1/tasks | jq
echo ECS_CLUSTER=cluster_name_here > /etc/ecs/ecs.config
#!/bin/bash
cd /home/ec2-user/pizza-luvrs
echo "starting pizza luvrs"
npm start
docker inspect -f '{{json .HostConfig.Binds}}' ecs-agent | jq
See notes about setting environment variables here.
Note that defaults are used when running on localhost
. Override a default in the run
command like this: -e POSTGRES_PASSWORD=secret
docker run -d --name <name> -v <volume_name>:/var/lib/postgresql/data -p 5432:5432 postgres:latest
- Or with env overrides:
docker run -d --name <name> -e POSTGRES_USER=<user> -e POSTGRES_PASSWORD=<password> -e POSTGRES_DB=<database_name> -v <volume_name>:/var/lib/postgresql/data -p 5432:5432 postgres:latest
- Or with env overrides:
docker logs -f <name>
docker exec -it <name> psql -U postgres
\l
to list databasesCREATE DATABASE test;
\c test
to change to test databaseINSERT INTO relation(id, parentId, childId) VALUES (2, 2, 3);
INSERT INTO relation(id, parentId, childId, createdAt) VALUES (1, 1, 2, timezone('UTC'::text, now()));
SELECT * FROM relation;
If installed with brew on MacOS, qualify commands with /usr/local/bin/
, e.g. /usr/local/bin/kafka-topics
- Start Zookeeper
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
- Start Kafka
kafka-server-start /usr/local/etc/kafka/server.properties
- Test Zookeeper connection
telnet localhost 2181
nc -vz localhost 2181
- Create Topic
kafka-topics --create --topic my_topic --zookeeper localhost:2181 --replication-factor 1 --partitions 1
- Logs Location:
/usr/local/var/lib/kafka-logs/
- List Topics:
kafka-topics --list --zookeeper localhost:2181
- Produce a message from command line:
kafka-console-producer --broker-list localhost:9092 --topic my_topic
- Consumer messages from command line:
kafka-console-consumer --bootstrap-server localhost:9092 --topic my_topic --from-beginning
- Get topic details (e.g. partition count, replication factor, leader, replicas):
kafka-topics --describe --topic my_topic --zookeeper localhost:2181
- Running multiple brokers on one machine:
- https://www.michael-noll.com/blog/2013/03/13/running-a-multi-broker-apache-kafka-cluster-on-a-single-node/
- In summary, create copies of the
server.properties
file and give unique values tobroker.id
listeners
log.dirs
- Then run
kafka-server-start
pointing to the modifiedserver.properties
file
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
#!/bin/bash
set -e
# Add initialisation logic here
# Run application
exec "$@"
Compress-Archive -LiteralPath node_modules, index.js -DestinationPath yourfilename.zip
- Upgrade Gradle wrapper:
./gradlew wrapper --gradle-version 6.6.1
- Print Java Source Files
println "sourceSets.main.allSource.files: " + sourceSets.main.allSource.files
- Example output:
sourceSets.main.allSource.files: [/home/dgood/IdeaProjects/cdk-java-starter/lambda/src/main/resources/a.txt, /home/dgood/IdeaProjects/cdk-java-starter/lambda/src/main/java/com/davidagood/cdkjava/ExampleHandler.java]
- Print all configurations
println "configurations: " + configurations
- Example output:
configurations: [configuration ':lambda:annotationProcessor', configuration ':lambda:apiElements', configuration ':lambda:archives', configuration ':lambda:compile', configuration ':lambda:compileClasspath', configuration ':lambda:compileOnly', configuration ':lambda:default', configuration ':lambda:implementation', configuration ':lambda:lambdaResources', configuration ':lambda:outputAnnotationProcessor', configuration ':lambda:outputCompile', configuration ':lambda:outputCompileClasspath', configuration ':lambda:outputCompileOnly', configuration ':lambda:outputImplementation', configuration ':lambda:outputRuntime', configuration ':lambda:outputRuntimeClasspath', configuration ':lambda:outputRuntimeOnly', configuration ':lambda:runtime', configuration ':lambda:runtimeClasspath', configuration ':lambda:runtimeElements', configuration ':lambda:runtimeOnly', configuration ':lambda:testAnnotationProcessor', configuration ':lambda:testCompile', configuration ':lambda:testCompileClasspath', configuration ':lambda:testCompileOnly', configuration ':lambda:testImplementation', configuration ':lambda:testRuntime', configuration ':lambda:testRuntimeClasspath', configuration ':lambda:testRuntimeOnly']
The deafult path has changed across implementations/versions and it's difficult to look up the historical or even current default path... Here are some common default paths for Swagger API docs:
/swagger/index.html
/swagger-ui/index.html
/swagger.html
/swagger-ui.html