Skip to content

Instantly share code, notes, and snippets.

@roppa
roppa / json-path-export.js
Created March 1, 2018 14:49
Executable script, takes in target json file, output json file, and a string of the json path you want to export, like 'parent.child.child'
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const from = JSON.parse(fs.readFileSync(path.resolve(process.argv[2])).toString());
const to = path.resolve(process.argv[3]);
const jsonPath = process.argv[4].split('.');
function getValueFromPaths(paths, object) {
0xdA52ef28f5ff83f45439Aca6bf664F4edc581bAF

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

Array

Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@roppa
roppa / socket-client-server.js
Created July 12, 2017 18:29
Node.js socket server and client
const net = require('net');
const PORT = 6000;
const server = net.createServer((connection) => {
console.log('created server');
connection.on('data', (data) => {
connection.write('pong\n');
});
connection.pipe(connection);
@roppa
roppa / .vimrc
Created May 12, 2017 09:56
my vimrc
set autoindent
set indentexpr=off
set expandtab
set tabstop=4
set sw=4
set textwidth=80
set nohls
set noshowmatch
syntax enable
@roppa
roppa / sequential-promise.js
Created August 24, 2016 08:46
Sequential promise processing
'use strict';
/**
* Run through promises sequentially. Useful when breaking 1000s records into manageable chunks
*/
function processFile (filename) {
return new Promise((superResolve, superReject) => {
@roppa
roppa / gist:fcaf2e7dce629ce03465
Created January 21, 2016 14:05
Flatten a multi dimentional array
const flatten = (...args) => {
let result = [];
args.forEach(arg => {
if (Array.isArray(arg)) {
arg.forEach(element => {
if (Array.isArray(element)) {
result = result.concat(flatten(element));
} else {
result.push(element);
}
@roppa
roppa / gist:8e502c4a31bdb8dfaf65
Created January 18, 2016 11:50
Count letters in a string - returns an object with character for key and the character count for value
function countLetters (string) {
let letters = {};
for (let i = 0; i < string.length; i++) {
letters[string[i]] = letters[string[i]] + 1 || 1;
}
return letters;
}
@roppa
roppa / gist:eaa8cbabd36180bf2850
Created January 18, 2016 11:48
Seating permutations - take a list of people and it gives you all possible seating arrangements
let seating = (people) => {
let result = [];
(function permutations (left, right) {
let current;
let before
let after;
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/