This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :: (String, String) => String | |
const spawn = require('child_process').spawnSync; | |
// :: String => [String] | |
const getRules = raw => raw | |
.split('\n') | |
.map(line => line.trim()) | |
.filter(line => !!line) | |
.filter(line => line[0] !== '/' && line[0] !== '✖') | |
.map(line => line.match(/[a-z-]+$/)[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array = ordered + indexed + duplicate values | |
// a.k.a. List | |
const arr = [1, 2, 3] | |
// size | |
arr.length //=> 3 | |
// random-access | |
arr[1] // 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FP Lenses | |
const lens = get => set => ({ get, set }); | |
const view = lens => obj => lens.get(obj); | |
const set = lens => val => obj => lens.set(val)(obj); | |
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj); | |
const lensProp = key => lens(prop(key))(assoc(key)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Tight coupling from A to B => A needs B to be defined, callable and adhere to an interface | |
// No coupling from B to A => B does not need A in any way (pure fn) | |
function a() { | |
b() | |
} | |
function b() {} | |
} | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def application(environ, start_response): | |
import sys | |
path = 'YOUR_WWW_ROOT_DIRECTORY' | |
if path not in sys.path: | |
sys.path.append(path) | |
from pyinfo import pyinfo | |
output = pyinfo() | |
start_response('200 OK', [('Content-type', 'text/html')]) | |
return [output] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// blob = file contents, identified by hash | |
const blobs = { | |
'73d8a': 'import x from "y"; console.log("some file contents")', | |
'9c6bd': 'D8 A1 31 0F ...', | |
'547d4': '# Readme\nThis is documentation', | |
'a0302': '# Readme\nThis is some updated documentation', | |
} | |
// tree = references to blobs and trees, identified by hash | |
const trees = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imperative: 'what' + 'how' | |
const makes1 = [] | |
for (let i = 0; i < cars.length; i += 1) { | |
makes1.push(cars[i].make) | |
} | |
// Declarative: only 'what' | |
const makes2 = cars.map((car) => car.make) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Producer | |
const range = (min, max, acc = []) => { | |
if (max < min) throw new Error('not supported!') | |
if (min >= max) return acc | |
return range(min + 1, max, acc.concat(min)) | |
} | |
// Consumer | |
const lt100 = range(0, 100) | |
//=> [1, 2, 3, 4, ..., 97, 98, 99] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MY_CONSTANT = 42 | |
// Implementation of a class | |
var MyClass = function () { | |
// constructor | |
} | |
MyClass.prototype.getAnswer = function () { | |
return MY_CONSTANT | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interface of a primitive variable: its name and type | |
const DEFAULT_DB_HOST = 'localhost' | |
// Interface of a container variable: its name, types and structures | |
const config = { | |
user: 'readuser', | |
pass: '******', | |
db: 'test-env', | |
} |