Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gerrard00's full-sized avatar

Gerrard Lindsay gerrard00

  • NYC
View GitHub Profile
@gerrard00
gerrard00 / Stow Check
Created February 5, 2016 16:23
A lil' zsh script to check what stow has stowed before you stow. Run it in the root of your dotfiles repo.
#! /bin/zsh
DEFAULT_WARNING="WARNING: in simulation mode so not modifying filesystem."
for folder in */; do
# for folder in */; do
echo "- ${folder}";
# capture stderr, but send stdout to /dev/tty like normal
output="$(stow -n -v ${folder} 2>&1)"
@gerrard00
gerrard00 / fun-with-arguments.js
Last active June 12, 2016 00:18
A little javascript test for rotating arguments
const delimiterMap = {
'[': ']',
'(': ')',
'<': '>',
};
function getArgumentsArray(input) {
let current = '';
const result = [];
let delimiterEnd;
@gerrard00
gerrard00 / fib.c
Created August 4, 2016 17:12
Fib in c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
unsigned long int fib(unsigned long int x);
char *ptr;
unsigned long int input = strtoul(argv[1], &ptr, 10);
unsigned long int result = fib(input);
printf("result: %lu\n", result);
@gerrard00
gerrard00 / pgsl_execfile.sh
Created August 11, 2016 18:50
Show postgresql query results in terminal with a nicer format than psql
pgsql_execfile () {
clear
echo "\n"
tmpfile="$(mktemp).html"
nodemon --exec "psql -U postgres -h localhost -p 5433 -d $1 -f $2 --html -- > $tmpfile && w3m -dump $tmpfile && echo " $2
}
@gerrard00
gerrard00 / sort-strings-backwards.js
Last active August 28, 2016 16:56
Sort an array of strings backwards in js...I don't know why
// an array of strings mangled with this function will sort
// backwards. You can then mangle them again after the sorting
// to get your original words. of course, you could just do sort().reverse(), but
// I was curious. So, completely useless.
const maxUnicodeValue = 0x10FFFF;
function invertString(input) {
let result = '';
for(let c of input) {
const oldCode = c.codePointAt(0);
@gerrard00
gerrard00 / questionResponse.json
Last active December 9, 2016 15:46 — forked from wallyuva/questionResponse.json
Question Response Sample
{
question: {
questionId: '',
response: [
// HISTORICAL
{
score: ''
answerId: ''
},
{
@gerrard00
gerrard00 / javascript-queue.js
Created January 31, 2017 13:59
Simple javascript queue implementation for several test projects.
'use strict';
function Queue() {
return {
entries: [],
enqueue(value) {
this.entries.push(value);
},
dequeue() {
return this.entries.shift();
@gerrard00
gerrard00 / NodeLamdaDockerfile
Created February 22, 2017 16:50
Dockerfile for running a container that can be used to test AWS Lambda functions written in node
FROM amazonlinux
RUN curl -O https://nodejs.org/dist/v4.3.0/node-v4.3.0-linux-x64.tar.gz
RUN tar --strip-components 1 -xzvf node-v* -C /usr/local
RUN rm node-v4.3.0-linux-x64.tar.gz
CMD ["/bin/bash"]
@gerrard00
gerrard00 / addPromiseToCallback.js
Last active February 24, 2017 15:30
Adds a promise property to a callback function
'use strict';
// the wrapper
function addPromiseToCallback(fn) {
const result = function result(err, data) {
fn(err, data);
if (err) {
result.reject(err);
return;
@gerrard00
gerrard00 / randomProcessArray.js
Created February 28, 2017 15:40
Randomly process an array
const input = ['I', 'come', 'from', 'mars'];
// if you don't want to change the array
let i = 0;
// roughly shuffle the indexes
const shuffledIndexes = input.map(() => i++).sort(i => Math.random() * 3 + -1);
for(let j = 0; j < input.length; j++) {
console.log(input[shuffledIndexes[j]]);
}