Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
kevinhooke / gist:20a26c9ea1de04c4dd9767245b86d41d
Created September 22, 2021 17:36
JavaScript flatten an array of arrays
let arrays = [ [1,2], [2,3], [3,4] ];
let singleArray = [].concat.apply([], arrays);
//singleArray = [1, 2, 2, 3, 3, 4];
@kevinhooke
kevinhooke / gist:068302c33e029435f21b6af6f6da4439
Last active September 15, 2021 21:56
Filter aws cli resource lists for a specific single attribute value
# 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
@kevinhooke
kevinhooke / gist:e39160c71c1c530a9761f5ddabdefe09
Created August 9, 2021 18:09
Kafka Connectors REST apis
# 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
#calls a function setting the value for 'this' within the function
functionName.call(someThisValue, otherParams);
- the first param passed is the value for 'this' when this is referenced within that function
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
@kevinhooke
kevinhooke / gist:55d9b1342815a9b0bfb8d6ecc79bb12c
Created July 7, 2021 00:27
Run app on JVM in debug mode
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8081 -jar YourApp.jar
let example = new Promise(
function(resolve, reject){
let success = do some async task;
if(success){
resolve();
}else{
reject();
}
};
);
@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: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
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