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 / better-console-log.js
Created February 4, 2019 18:09
My version of code to include line numbers in console logs for node 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 December 13, 2018 19:37
Standardizes stuff with leading or trailing dots.
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 November 26, 2018 20:32
Convert a json object to a node module...don't ask
'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 });
@gerrard00
gerrard00 / neptune-concurrency-2.js
Created November 13, 2018 17:56
Neptune Concurrency 2
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;
@gerrard00
gerrard00 / regexmatchesgenerator.js
Created July 11, 2018 18:12
JavaScript Generator Function for RegEx Capture Groups
function* getMatches(regex, text) {
let match;
while((match = regex.exec(text)) != null) {
yield match.slice(1);
}
}
const assignmentRegEx = /^(.*)\s+=\s+(.*)\.$/gm;
// const limit = 1000000;
// const limit = Number.MAX_SAFE_INTEGER;
const limit = 1000000000;
let lastBarLength = 0;
let lastBar = '';
console.log('start');
for(let i = 0; i < limit; i++) {
@gerrard00
gerrard00 / loadxml.cs
Created September 13, 2017 05:57
Xml Compression tests
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace Test
{
class Test
{
static void Main()
@gerrard00
gerrard00 / install-vim-and-tmux.sh
Created May 27, 2017 15:22
Install newer Vim and Tmux on CentOs
# vim
yum group install "Development Tools" -y
yum install ncurses-devel -y
yum install unzip -y
yum install wget -y
yum install make -y
# prereqs copied from YouCompleteMe repo, probably overkill
yum install -y python python-devel
# yum install -y python3 python3-devel
wget -O vim-master.zip https://github.com/vim/vim/archive/master.zip
@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]]);
}
@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;