Skip to content

Instantly share code, notes, and snippets.

View babakness's full-sized avatar

Babak B. babakness

View GitHub Profile
@babakness
babakness / README.md
Created June 21, 2017 06:18 — forked from benjie/README.md
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
@babakness
babakness / README.md
Created June 21, 2017 06:18 — forked from benjie/README.md
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
@babakness
babakness / plv8-modules.sh
Created June 22, 2017 02:52 — forked from daviddahl/plv8-modules.sh
plv8-modules
#! /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
babakness / Firebase Database API Cheatsheet
Created January 16, 2018 03:33 — forked from odigity/Firebase Database API Cheatsheet
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.
@babakness
babakness / life-cycle.js
Created February 28, 2018 18:04
Example of component with lifecycle hooks
// 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 {
constructor(){
super()
}
shouldComponentUpdate(){
// return false to skip render
@babakness
babakness / example-partial-application-with-placeholders.js
Last active April 19, 2018 22:16
Simple partial application with placeholders, example for discussion
export class Placeholder {}
export const _ = new Placeholder()
export const isPlaceholder = placeholder => placeholder instanceof Placeholder
export function bind( ...placeholders ) {
return ( ...fillers ) => this.call( this, ...placeholders.map(
item => isPlaceholder( item ) ? fillers.shift() : item
) )
}
@babakness
babakness / post-extract
Created May 21, 2018 22:42
Restrict dokku apps to an ip - WIP
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
APP="$1"
verify_app_name "$APP"
TMP_WORK_DIR="$2"
REV="$3" # optional, may not be sent for tar-based builds
HOSTS="/etc/hosts"
IP4="dokku_apps_ip4"
@babakness
babakness / working-flatten.ts
Created June 22, 2018 05:30
Working Flatten
// 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
babakness / simple-flatten-type.ts
Last active August 6, 2018 16:00
Simple Flatten Type
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;
@babakness
babakness / sample-pipe.ts
Created October 4, 2018 03:32
Sample pipe function using overloads in TypeScript
// 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;