Skip to content

Instantly share code, notes, and snippets.

aerial
android-file-transfer
appcleaner
atom
bbc-iplayer-downloads
betterzipql
calibre
cheatsheet
colorpicker-skalacolor
disk-inventory-x
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# fpath+=("/usr/local/share/zsh/site-functions")
# autoload -U promptinit; promptinit
# prompt pure
# Path to your oh-my-zsh installation.
export ZSH=/Users/oliverjam/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
@oliverjam
oliverjam / Recursive nested array count.js
Created June 10, 2017 14:56
Recursive nested array count created by oliverjam - https://repl.it/If1v/0
function deepCount(arr) {
return arr.reduce((acc, item) => {
acc += 1;
if (Array.isArray(item)) acc += deepCount(item);
return acc;
}, 0);
}
const a = [1, [2, 3, [4, 5, 6]]];
@oliverjam
oliverjam / Python Pi calculator.py
Created June 15, 2017 15:07
Python Pi calculator created by oliverjam - https://repl.it/InIh/0
from decimal import getcontext, Decimal
getcontext().prec = 20
def calculatePi():
pi = Decimal(3)
i = Decimal(2)
while i < 20000000:
divisor = Decimal(4) / Decimal(i * (i + 1) * (i + 2))
if i % 4 == 0:
function calculatePi(dp = 200000) {
let pi = 3;
let i = 2;
while (i < dp) {
const divisor = 4 / (i * (i + 1) * (i + 2));
if (i % 4 === 0) {
pi -= divisor;
} else {
pi += divisor;
console.log(i + ' ' + pi);
@oliverjam
oliverjam / index.js
Created July 18, 2017 14:23
requirebin sketch
const bel = require('bel');
function li(items) {
return bel`<ul>${items.map(item => bel`<li>${item}</li>`)}</ul>`
}
document.body.appendChild(li(['1', '2']));
@oliverjam
oliverjam / Recursive loop.js
Created July 31, 2017 09:59
Recursive loop created by oliverjam - https://repl.it/Jpzk/0
function loop(start, end, increment) {
console.log(start);
if (start === end) return;
loop(start + increment, end, increment);
}
loop(0, 10, 1);
@oliverjam
oliverjam / Functional Fun - Monad Madness.js
Created August 3, 2017 16:31
Functional Fun - Monad Madness created by oliverjam - https://repl.it/Jvn3/0
// inc :: Number -> (Number,String)
const inc = x => y => [y + x, `${inc.name}${x} was called.`];
const inc1 = inc(1);
// dec :: Number -> (Number,String)
const dec = x => y => [y - x, `${dec.name}${x} was called.`];
const dec1 = dec(1);
// unit :: Number -> (Number,String)
const unit = x => [x, ''];
@oliverjam
oliverjam / Functional Fun - Cool Currying.js
Created August 3, 2017 16:34
Functional Fun - Cool Currying created by oliverjam - https://repl.it/Jvni/0
const get = prop => object => object[prop];
const objects = [
{ id: 1 },
{ id: 2 },
{ id: 3 },
];
objects.map(get('id'));
@oliverjam
oliverjam / simple-pipe.js
Created September 26, 2017 22:30
Simple pipe created by oliverjam - https://repl.it/Lfew/3
// pipe takes an arbitrary number of functions as arguments
// It returns a new function waiting for a value to be passed in
function pipe(...fns) {
return function(val) {
let finalResult;
for (fn of fns) {
// Call each function in turn with val (the first time) or the previous result
finalResult = fn(finalResult || val);
}
return finalResult;