Skip to content

Instantly share code, notes, and snippets.

kevinhooke / gist:28986702107be921974134e707b23baf
Created Sep 22, 2021
JavaScript sort array: strings vs integers
View gist:28986702107be921974134e707b23baf
let arrayOfStrings = [ "bbb", "ccc", "aaa"];
arrayOfStrings.sort(); //sorts as strings in alphabetical ascending order by default
//arrayOfStrings = ["aaa", "bbb", "ccc"]
let arrayOfInts = [3, 4, 1];
//function passed to sort() returns > 0 if b comes after a, or if < 0 then a comes before b
arrayOfInts.sort( (a,b) => a - b );
//arrayOfInts = [1, 3, 4];
kevinhooke / gist:20a26c9ea1de04c4dd9767245b86d41d
Created Sep 22, 2021
JavaScript flatten an array of arrays
View gist:20a26c9ea1de04c4dd9767245b86d41d
let arrays = [ [1,2], [2,3], [3,4] ];
let singleArray = [].concat.apply([], arrays);
//singleArray = [1, 2, 2, 3, 3, 4];
kevinhooke / gist:068302c33e029435f21b6af6f6da4439
Last active Sep 15, 2021
Filter aws cli resource lists for a specific single attribute value
View gist:068302c33e029435f21b6af6f6da4439
# Lambda ARNs
aws lambda list-functions | jq '.Functions[].FunctionArn'
# multiple properies: outputs on separate lines
aws lambda list-functions | jq -r '.Functions[] | .FunctionArn, .FunctionName'
# multiple properties as arrays
aws lambda list-functions | jq -r '.Functions[] | [.FunctionArn, .FunctionName]'
# multiple properties as arrays, converted to csv
View gist:e39160c71c1c530a9761f5ddabdefe09
# list alll connectors
GET connectorhost:8083/connectors
# status for one connector
GET connectorhost:8083/connectors/connector-name/status
# restart - does not restart failed tasks
POST connectorhost:8083/connectors/connector-name/restart
# restart specific task
View gist:e947616387182b7fe00485b6bc392f4e
#calls a function setting the value for 'this' within the function, otherParams);
- the first param passed is the value for 'this' when this is referenced within that function
View gist:55d9b1342815a9b0bfb8d6ecc79bb12c
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8081 -jar YourApp.jar
View gist:3272f9faf8af8a2bb6a9199f37635482
let example = new Promise(
function(resolve, reject){
let success = do some async task;
kevinhooke / gist:07e5a900252fb8dc6ff3c98df60e0b54
Created Jul 2, 2021
Serverless framework Java Lambda - invoke local logger error
View gist:07e5a900252fb8dc6ff3c98df60e0b54
sls invoke local --function functionname
NoSuchMethodError: 'void ...
change aws-lambda-java-log4j2 verion in pom.xml to 1.0.0
kevinhooke / gist:895723ca2991f837785c503916e064f4
Created Jun 10, 2021
JavaScript imports and exports: default and named
View gist:895723ca2991f837785c503916e064f4
- 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 / gist:389b4e69d3f2ea7c95dc248e8cdd91f3
Created May 13, 2021
git list files on a commit and delete files and all history
View gist:389b4e69d3f2ea7c95dc248e8cdd91f3
# 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