Skip to content

Instantly share code, notes, and snippets.

// Adapted from andai.tv/bonsai/
const pipe = (...fns) => (x) => fns.reduce((x, fn) => fn(x), x);
// const output = document.getElementById("output");
const ROWS = 30;
const COLS = 40;
const LIFE = 28;
const MAX_BRANCHES = 1024;
let branches = 0;
{
const compose = (...fns) => (val) => fns.reduceRight((x, fn) => fn(x), val);
const sum = (result, item) => result + item;
const mult = (a, b) => a * b;
function wrap(xf){
return {
// 1. We require init as arg, so do not need here
init: function(){
throw new Error('init not supported');
@PartyLich
PartyLich / gitclean.sh
Last active December 3, 2019 18:19 — forked from ericelliott/gitclean.sh
gitclean.sh - cleans merged/stale branches from origin
#!/bin/bash
# targetBranch=${2:-$(git rev-parse --abbrev-ref HEAD)}
# echo "target branch is '$targetBranch'"
remote=${1:-origin}
git remote prune $remote
# get remote merged branches
git branch -r --merged master | \
# remove master or develop case-insensitive
egrep -iv '(master|develop|dev)' | \
# replace remote/ with '' (nothing)
@PartyLich
PartyLich / sherlockanagrams.js
Created November 19, 2019 15:36
Hackerrank Sherlock and Anagrams
// I opened the page one day and wrote the solution on another. I had forgotten it was in the dict/hashmap section...
const sum = (acc, next) => acc + next;
const matches = (val, i, arr) => {
let count = 0;
for (++i; i < arr.length; i++) {
if (val == arr[i]) count++;
}
return count;
};
@PartyLich
PartyLich / exercise-web-crawler.go
Last active November 8, 2019 20:35
Tour of Go -> Exercise: Web Crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@PartyLich
PartyLich / fcc-algo-pairwise.js
Created August 29, 2019 15:12
FreeCodeCamp => Algorithms: Pairwise
/**
* @param {number} prev
* @param {number} next
* @return {number} the sum of prev and next
*/
const add = (prev, next) => prev + next;
/**
* Generate index pair combinations, arr.length choose 2
* @param {array} arr
@PartyLich
PartyLich / fcc-algo-noRepeat.js
Last active August 29, 2019 15:15
FreeCodeCamp => Algorithms: No Repeats Please
/**
* @param {array} arr array to insert into
* @param {number} i index for insertion
* @param {object} val value to be inserted
* @return {array} a new array with val inserted at i
*/
const insert = (i, arr, val) => [...arr.slice(0, i), val, ...arr.slice(i)];
/**
* @param {string}
@PartyLich
PartyLich / farAway.js
Last active August 23, 2019 01:15
So far away from me
(function farAway() {
const me = {
about: 'Famous musician, looks like Buddy Holly',
birthday: new Date('June 13, 1970'),
hobbies: ['knitting'],
favoriteFood: 'burnt lamb',
}
let you = {
are: function (attr) {return Object.assign({},this, attr)}
know: function (subject) { this.knows.push(subject); }
@PartyLich
PartyLich / mrGreen.js
Last active August 22, 2019 20:48
Make you stay out all night long
(function MrGreen() {
class Person {
constructor () {
this.feeling = 5;
this._love = null;
}
get love() { return this._love; }
set love(person) {
this._love = person;
@PartyLich
PartyLich / opera.js
Last active August 21, 2019 14:35
Scaramouche! Scaramouche! Will you do the fandango?
(function Opera() {
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
const open = (obj = {}) => Object.assign({}, obj, {open: true});
const lookUpTo = (target) => (obj) =>
Object.assign({}, obj, {lookingAt: target});
const see = (obj) => Object.assign({}, obj, {canSee: true});
if (isRealLife || isFantasy) {