Skip to content

Instantly share code, notes, and snippets.

Avatar

Gerrard Lindsay gerrard00

  • NYC
View GitHub Profile
@gerrard00
gerrard00 / random-jq.sh
Created Nov 25, 2020
Random JQ Examples
View random-jq.sh
# find all paths to a given key recursively
jq 'paths | select(.[-1] == "lastUpdateTime")' persistence-sore-service.json
View quicksort.js
const quicksort = (arr) => {
if (arr.length <= 1) {
return arr;
}
const pivot = arr[0];
const others = arr.slice(1);
return [
...quicksort(others.filter(v => v <= pivot)),
@gerrard00
gerrard00 / spawn-shell.js
Created Apr 8, 2019
Simple code to launch a network shell from node js
View spawn-shell.js
const net = require('net');
const cp = require('child_process');
const sh = cp.spawn('/bin/sh');
const server = net.createServer((client) => {
client.pipe(sh.stdin);
sh.stdout.pipe(client);
sh.stderr.pipe(client);
});
@gerrard00
gerrard00 / toggle_ case.c
Created Apr 8, 2019
Toggle the case of any ascii char by xoring 32 (space character)
View toggle_ case.c
#include <stdio.h>
char toggle_case(char c) {
return c ^ 32;
}
int main(int argc, char ** argv) {
printf("Hello%c\n", toggle_case(*(argv[1])));
}
@gerrard00
gerrard00 / update-launch-json.sh
Last active Feb 26, 2019
Update Visual Studio Code launch.json file to use current version of node from NVM
View update-launch-json.sh
node_path="$(which node)"
temp_file=$(mktemp /tmp/launch-$$.json)
grep -v '^\s*//' < .vscode/launch.json | jq '.configurations[].runtimeExecutable = "'$node_path'"' > $temp_file
mv .vscode/launch.json .vscode/launch.json.bak
mv $temp_file .vscode/launch.json
@gerrard00
gerrard00 / sleep.js
Created Feb 21, 2019
Stupid sleep function for node js
View sleep.js
const sleep = (ms) =>
new Promise(resolve =>
setTimeout(() => resolve(), ms));
@gerrard00
gerrard00 / better-console-log.js
Created Feb 4, 2019
My version of code to include line numbers in console logs for node js
View better-console-log.js
// https://stackoverflow.com/questions/45395369/how-to-get-console-log-line-numbers-shown-in-nodejs
['log','warn','error'].forEach((methodName) => {
const originalMethod = console[methodName];
console[methodName] = (...args) => {
const error = new Error();
originalMethod.apply(
console,
[
(
error
@gerrard00
gerrard00 / standardize-dots.js
Created Dec 13, 2018
Standardizes stuff with leading or trailing dots.
View standardize-dots.js
const fs = require('fs');
const program = require('commander');
function makeTrailingDots(gremlin) {
const lines = gremlin
.split('\n')
.filter(line => line.length);
const lastLineIndex = lines.length - 1;
@gerrard00
gerrard00 / json-to-node-module.js
Created Nov 26, 2018
Convert a json object to a node module...don't ask
View json-to-node-module.js
'use strict';
const fs = require('fs');
const util = require('util');
const contents = fs.readFileSync(0, 'utf8');
const jsonObject = JSON.parse(contents);
const javascriptString = util.inspect(jsonObject, { depth: null });
View neptune-concurrency-2.js
const gremlin = require('gremlin');
const uuidv4 = require('uuid/v4');
const { t: { id }, cardinality } = gremlin.process;
const __ = gremlin.process.statics;
const hostname = process.env.NEPTUNE_HOST;
const testToRun = process.argv[2];
const threadsRequested = process.argv[3] ? Number(process.argv[3], 10) : 5;