Skip to content

Instantly share code, notes, and snippets.


Babak B. babakness

View GitHub Profile
babakness / create-class-like-functions.js
Last active Oct 5, 2018
Helpers for creating class like functions that can be invoked without new
View create-class-like-functions.js
const assoc = ( prop, value, obj ) =>
Object.assign( {}, obj, { [prop]: value })
const reducer = ( $values, accumulate, [key,val] ) => assoc( key, val.bind( undefined, ...$values ), accumulate )
export const bindValuesToMethods = ( $methods, ...$values ) =>
Object.entries( $methods ).reduce( reducer.bind( undefined, ...$values ), {} )
export const prepareInstance = (instanceMethods, staticMethods = ({}) ) => Object.assign(
babakness / sample-pipe.ts
Created Oct 4, 2018
Sample pipe function using overloads in TypeScript
View sample-pipe.ts
// Example taken from @type/ramda at the time of this writing.
pipe<T1>(fn0: () => T1): () => T1;
pipe<V0, T1>(fn0: (x0: V0) => T1): (x0: V0) => T1;
pipe<V0, V1, T1>(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1;
pipe<V0, V1, V2, T1>(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1;
pipe<T1, T2>(fn0: () => T1, fn1: (x: T1) => T2): () => T2;
pipe<V0, T1, T2>(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2;
pipe<V0, V1, T1, T2>(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2): (x0: V0, x1: V1) => T2;
View simple-flatten-type.ts
type Flatten<T> = T extends any[] ? T[number] : T;
// If you want to flatten no lower than one level
type FlattenArray<T> = T extends any[][] ? T[number] : T;
View working-flatten.ts
// classes
class Just<A> {
readonly _A!: A
constructor(readonly value: A) {}
fold<B>(whenNothing: B, whenJust: (a: A) => B): B {
return whenJust(this.value)
map<B>(fn: (a: A) => B): Maybe<B> {
return Maybe.of(fn(this.value))
babakness / post-extract
Created May 21, 2018
Restrict dokku apps to an ip - WIP
View post-extract
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
verify_app_name "$APP"
REV="$3" # optional, may not be sent for tar-based builds
babakness / example-partial-application-with-placeholders.js
Last active Apr 19, 2018
Simple partial application with placeholders, example for discussion
View example-partial-application-with-placeholders.js
export class Placeholder {}
export const _ = new Placeholder()
export const isPlaceholder = placeholder => placeholder instanceof Placeholder
export function bind( ...placeholders ) {
return ( ...fillers ) => this,
item => isPlaceholder( item ) ? fillers.shift() : item
) )
babakness / life-cycle.js
Created Feb 28, 2018
Example of component with lifecycle hooks
View life-cycle.js
// How to have render props that bind `this` context to functions that need them
// (note: not arrow functions)
// Example illustrates hooks at all stages
export class LifeCycle extends Component {
// return false to skip render
View Firebase Database API Cheatsheet
There is no way to store an empty object/array/null value.
There are also no actual arrays. Array values get stored as objects with integer keys.
(If all keys are integers, it will be returned as an array.)
Basically, it's one giant tree of hashes with string keys.
Simply write a value to any location, and the intermediary locations will automatically come into existance.
── Classes ──
DataSnapshot : Container for a subtree of data at a particular location.
#! /bin/bash
sudo apt-get install npm
cd /var/django
npm install moment moment-timezone
sudo -u postgres psql -d template1 -c "create extension plv8;"
sudo -u postgres psql -d template1 << EOF
babakness /
Created Jun 21, 2017 — forked from benjie/
Easy plv8 on OSX

Heroku runs plv8 v1.4.2 (checked on 1st April 2016). On OSX it's easiest to install v1.4.3 since that allows V8 3.15 which is available via homebrew. (1.4.2 wants V8 3.14.5).

To install:

brew install v8-315
pip install pgxnclient
LIBRARY_PATH="/usr/local/opt/v8-315/lib" CPATH="/usr/local/opt/v8-315/include" pgxnclient install plv8=1.4.3