Skip to content

Instantly share code, notes, and snippets.

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 / 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:
@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]]];
# 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"
aerial
android-file-transfer
appcleaner
atom
bbc-iplayer-downloads
betterzipql
calibre
cheatsheet
colorpicker-skalacolor
disk-inventory-x
autoconf
libtool
ruby
automake
libyaml
sqlite
boost
lua
thefuck
cctools
@oliverjam
oliverjam / basic-rot13.js
Created March 26, 2017 22:03
null created by oliverjam - https://repl.it/GfI5/0
const str = "SERR PBQR PNZC";
function rot13(string) {
return string.split('')
.map(word => {
return word.split('')
.map(letter => {
const letterCode = letter.charCodeAt(0);
if (! (letterCode >= 65 && letterCode <= 90)) return letter;
if (letterCode <= 77) return String.fromCharCode(letterCode + 13);
@oliverjam
oliverjam / Interlace Arbitrary Strings.js
Created November 24, 2016 13:36
Interlace Arbitrary Strings created by oliverjam - https://repl.it/E7Hk/1
function combineStrings() {
let result = '';
if (arguments.length > 0) {
const args = [...arguments];
const maxLength = args.map(item => item.length).reduce((a, b) => Math.max(a, b));
for (let i = 0; i < maxLength; i++) {
args.forEach(item => {
result += item.charAt(i);
});
}
@oliverjam
oliverjam / EJ: C5 P4.js
Created November 9, 2016 14:05
EJ: C5 P4 created by oliverjam - https://repl.it/ETEO/2
function every(arr, f) {
for (let i = 0; i < arr.length; i++) {
if (!f(arr[i])) return false;
}
return true;
}
function some(arr, f) {
for (let i = 0; i < arr.length; i++) {
if (f(arr[i])) return true;
@oliverjam
oliverjam / EJ: C5 P2.js
Created November 8, 2016 19:32
EJ: C5 P2 created by oliverjam - https://repl.it/ES00/2
function average(array) {
function plus(a, b) { return a + b; }
return array.reduce(plus) / array.length;
}
var byName = {};
ancestry.forEach(function(person) {
byName[person.name] = person;
});