Skip to content

Instantly share code, notes, and snippets.

View object-watch.js
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@roppa
roppa / conform.js
Last active Aug 29, 2015
Make all objects in an array have the same attributes
View conform.js
/**
Conform. We have a collection of objects with the possibility of having unique attributes.
We would like to ensure that each object in the collection has the same attributes. Handy for passing objects
to a CSV function that expects all objects to conform:
Example: var coll = [{a : "a", b : ""}, {a : "a", c : "c"}, {a : "a", d : "d", f : "f"}];
conform(coll);
@param array array of objects.
*/
View The Technical Interview Cheat Sheet.md

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.
View how_to_make_a_script.md

How to make a script to run in your terminal

  • Locate the path to the interpreter for the language you are writing in with the which command.

      which node
      which python
      which bash
      which ruby
    
  • Add that path as an interpreter directive (using #!) on the first line of your script. For example if which node returned /usr/local/bin/node, the first line of your script should be:

@roppa
roppa / gist:eaa8cbabd36180bf2850
Created Jan 18, 2016
Seating permutations - take a list of people and it gives you all possible seating arrangements
View gist:eaa8cbabd36180bf2850
let seating = (people) => {
let result = [];
(function permutations (left, right) {
let current;
let before
let after;
@roppa
roppa / gist:8e502c4a31bdb8dfaf65
Created Jan 18, 2016
Count letters in a string - returns an object with character for key and the character count for value
View gist:8e502c4a31bdb8dfaf65
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:fcaf2e7dce629ce03465
Created Jan 21, 2016
Flatten a multi dimentional array
View gist:fcaf2e7dce629ce03465
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 / sequential-promise.js
Created Aug 24, 2016
Sequential promise processing
View sequential-promise.js
'use strict';
/**
* Run through promises sequentially. Useful when breaking 1000s records into manageable chunks
*/
function processFile (filename) {
return new Promise((superResolve, superReject) => {
@roppa
roppa / .vimrc
Created May 12, 2017 — forked from substack/.vimrc
my vimrc
View .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 / socket-client-server.js
Created Jul 12, 2017
Node.js socket server and client
View socket-client-server.js
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);
You can’t perform that action at this time.