Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
kevinhooke / gist:07e5a900252fb8dc6ff3c98df60e0b54
Created July 2, 2021 22:34
Serverless framework Java Lambda - invoke local logger error
sls invoke local --function functionname
NoSuchMethodError: 'void com.amazonaws.services.lambda.runtime.LambdaLogger.log ...
Per https://github.com/serverless/serverless/issues/5155
change aws-lambda-java-log4j2 verion in pom.xml to 1.0.0
@kevinhooke
kevinhooke / gist:092ccacfa48e1fa1b804581afc1ccb5a
Last active June 21, 2021 17:11
DynamoDB keys and indexes
Primary keys - 2 types:
- Partition key: unique value, internally is hashed to determine which partition item is stored in
- Partition and sort key: composite key of an id and an attribute that sorts items by this value
- sort key is also called a range attribute
- the combination of partition id and sort key must be unique, but partition id can exist for multiple rows
- allows storing multiple rows for a specific id, for example:
if employeeid = partition key and employee_info = sort key
employeeid=1, employee_info=contactinfo
@kevinhooke
kevinhooke / gist:895723ca2991f837785c503916e064f4
Created June 10, 2021 16:50
JavaScript imports and exports: default and named
- a module can only have one default export:
export default A = //something
... and can be imported with any name:
import A from './A.js';
import B from './A.js';
import someothername from './A.js'
- named exports are imported by their exact name only, a module can have zero, one or more named exports
@kevinhooke
kevinhooke / gist:389b4e69d3f2ea7c95dc248e8cdd91f3
Created May 13, 2021 00:41
git list files on a commit and delete files and all history
# diff changed files against previous commit - this doesn't show anything for a first commit
git diff-tree --no-commit-id --name-only -r commithash
# list all files on a commit
git ls-tree --name-only -r commithash
# delete a file from all commit history
git filter-branch --tree-filter "rm -f filename" HEAD
React fragments https://reactjs.org/docs/fragments.html
- group a list of child elements without grouping them wihin a containing parent element in the DOM where that
would be invalid. An example is a list of <td> elements rendered by a component. If the parent component renders a <tr>,
if the child element wrapped these in a <div> that would be invald HTML structure, but they can be logically grouped
as a fragment instead, using <React.Fragrment>, or the <> </> JSX shorthand
React Context: https://reactjs.org/docs/context.html
- used to automatically pass props down to all child elements without passing the props manually from one child to the next
Fast Forward
- when no other changes made to master between the last change and the change you are about to merge on your branch,
master is 'fast forwarded' to point to your last commit that you are merging into master (no other changes to merge)
Merging a branch
- checkout target branch: git checkout targetname
- merge source into the target: git merge sourcename
# switch branches
git branch branchname
# chekout files on branch
git checkout branchname
# both of the above combined
git checkout -b branchname
#rename a branch
@kevinhooke
kevinhooke / gist:61eeb5ed3162fa77c7286682d1bb0170
Created April 3, 2021 00:58
JAX-RS Jersey vs Spring RestController annotations
JAX-RS Jersey Spring RestController
------------- ---------------------
@Path("/examplepath") @RestController
@RequestMapping("/examplepath")
@GET("/item") @GetMapping("/item")
@Produces(MediaType.APPLICATION_JSON)
@QueryParam("id") @RequestParam("id") // e.g. /example?id=123
@PathParam("id") @PathVariable("id") //e.g. /example/{id}/detail
@kevinhooke
kevinhooke / gist:a30de2d5ea9d9986cdf306775063323e
Created March 26, 2021 00:35
Configuring ~/.ssh/config file for accessing multiple git repos with different keys
Edit ~/.ssh/config and for each repo add the following block:
host hostname-of-repo
user your-id-for-this-repo
identityfile ~/.ssh/filename-of-key
@kevinhooke
kevinhooke / gist:b3ef76e5f4a921bf98670d8991cd28b3
Last active March 10, 2021 21:57
aws cli dynamodb put-item and get item
aws --endpoint-url=http://localhost:4566 dynamodb put-item --table-name exampletable --item '{
"LastName" : { "S" : "test1" }
}' \
--return-consumed-capacity TOTAL
#query table with only a hash key
aws --endpoint-url=http://localhost:4566 dynamodb query --table-name exampletable \
--key-condition-expression "LastName = :v1" \
--expression-attribute-values '{
":v1" : {"S": "test1"}