Skip to content

Instantly share code, notes, and snippets.

@ericabell
ericabell / diff.js
Last active September 13, 2017 21:58
Difference in paths
// Given two absolute paths on a file system, write a function to determine the difference between them.
// For example, `/a/b/c` and `/a/d` should yield `../../d`.
// `/a/b/c` and `/e/f` => `../../../e/f`
// `/` and `/a/b/c` => `/a/b/c`
// `/a/b/c` and `/` => `../../../`
function difference(path1, path2) {
// break the paths into lists and discard the first empty element
@ericabell
ericabell / app.js
Created August 29, 2017 03:19
I think the map method runs synchronously
let myBigArray = []
for(let i=0; i<2000000; i++) {
myBigArray.push(i);
}
console.log('Done filling the array.');
let myNewBigArray = myBigArray.map( (e) => {
return e+2;
@ericabell
ericabell / user-input-addition.js
Created August 13, 2017 16:41
Read a series of numbers from the terminal, compute their sum when input stream closes
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'Enter numbers sep by newlines. Ctrl-d when done> \n'
});
let inputStack = [];
@ericabell
ericabell / 0_reuse_code.js
Created June 25, 2017 16:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import pandas
import requests
from bs4 import BeautifulSoup
page = requests.get('http://www.politico.com/2012-election/results/president/wisconsin/')
soup = BeautifulSoup(page.text, "html.parser")
for body in soup("tbody"):
body.unwrap()
@ericabell
ericabell / format_text.py
Created March 3, 2017 17:55
fix word wrap in file
import textwrap
f = open('sample_input_text.asc','r')
contents = f.read()
split_contents = contents.splitlines()
for line in split_contents:
dedent_line = textwrap.dedent( line )
@ericabell
ericabell / rsa.py
Created January 15, 2017 02:35
A simple RSA implementation in Python
'''
620031587
Net-Centric Computing Assignment
Part A - RSA Encryption
'''
import random
'''
@ericabell
ericabell / qtext.bash
Last active November 12, 2015 11:49
Fix latex for sage script
qtext() {
cp $1 $1.bak
sed -i -e 's/^/q_text.append(r"/' $1
sed -i -e 's/$/")/' $1
}
@ericabell
ericabell / calc_exams.sty
Created September 19, 2015 11:36
Latex Style File for Calculus Exams
%
% advanced_calc.sty
%
% This is the LaTex style file for Calculus Exams and Handouts.
%
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\RequirePackage{tikz}
\usetikzlibrary{plotmarks}
\RequirePackage{pgfplots}
@ericabell
ericabell / gist:e6c1647225121120be45
Created November 15, 2014 13:02
easy way to get a unit vector
def unit(v):
mag = sqrt(v[0]*v[0]+v[1]*v[1])
return (v[0]/mag, v[1]/mag)
VF = plot_vector_field(unit([-y,-x]),[x,-2,2],[y,-2,2])