This file contains hidden or 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
-- Depending on what you sonsider the start of the week, you can either subtract 3 or 2 days. The week in which the epoch occured is the 0 week. | |
select CEIL(EXTRACT(DAYS FROM (('1970-01-04'::timestamp - '1970-01-01') - (INTERVAL '3 days'))) / 7); |
This file contains hidden or 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
function rejections(promises) { | |
let failed = [] | |
return Promise.all(promises.map(promise => | |
promise.catch(err => { | |
failed = [err, ...failed] | |
return err | |
})) |
This file contains hidden or 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
#!/bin/bash | |
export PS1='$(jobs-count)$(__git_ps1 | sed "s/ //g")$(git-unpushed)$(basename "$PWD") ' | |
git-unpushed() { | |
local n="$(git log --oneline "@{u}.." 2> /dev/null | wc -l)" | |
test "$n" -gt 0 && echo "{$n}" | |
} |
This file contains hidden or 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
import Data.Char (digitToInt, isDigit) | |
type Position = Int | |
safeAsInt :: String -> Either (Position, Char) Int | |
safeAsInt [] = Right 0 | |
safeAsInt ('-':xs) = fmap negate (safeAsInt xs) | |
safeAsInt (c:xs) | |
| isDigit c = fmap (+ (digitToInt c * (10 ^ length xs))) (safeAsInt xs) | |
| otherwise = Left (length xs, c) |
This file contains hidden or 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
const Bacon = require('baconjs').Bacon | |
const keybindingStream = (keybindings, charStream) => { | |
let chars = '' | |
return charStream.flatMapLatest(char => { | |
chars = chars + char | |
const matching = matchingKeybinding(keybindings, chars) | |
const potentialMatches = potentiallyMatchingKeybindings(keybindings, chars) |
This file contains hidden or 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
function next(current = []) { | |
if (current.length === 0) | |
return [1] | |
if (current.length === 1) | |
return [1, 1] | |
return [1, ...nextIter(current), 1] | |
} |
This file contains hidden or 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
const assert = require('assert') | |
const isEmptyArray = v => Array.isArray(v) && v.length === 0 | |
function sortZeros(arr) { | |
return arr.concat([]).sort((a, b) => { | |
return (a === 0) | |
? 1 | |
: 0 | |
}) | |
} |
This file contains hidden or 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
const side = 1; | |
/** | |
* Returns the next row based on the row that is passed in. | |
*/ | |
function row(input = []) { | |
console.log(input); | |
function recur([first, second, ...rest], next = []) { | |
if (!second) { |
This file contains hidden or 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
const cons = (a, b) => ( | |
(idx) => { | |
if(idx === 0) { | |
return a; | |
} else if(idx === 1) { | |
return b; | |
} else { | |
throw "invalid index"; | |
} | |
} |
This file contains hidden or 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
'use strict'; | |
const knex = require('knex'); | |
module.exports = { | |
knexline, | |
} | |
function knexline(model, qb) { | |
const modelTable = model.identity; |