Skip to content

Instantly share code, notes, and snippets.

View bas080's full-sized avatar

#!/bin/BasH bas080

View GitHub Profile
@bas080
bas080 / weeks_since_epoch.sql
Created March 4, 2019 23:53
Weeks since epoch
-- 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);
function rejections(promises) {
let failed = []
return Promise.all(promises.map(promise =>
promise.catch(err => {
failed = [err, ...failed]
return err
}))
#!/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}"
}
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)
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)
function next(current = []) {
if (current.length === 0)
return [1]
if (current.length === 1)
return [1, 1]
return [1, ...nextIter(current), 1]
}
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
})
}
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) {
const cons = (a, b) => (
(idx) => {
if(idx === 0) {
return a;
} else if(idx === 1) {
return b;
} else {
throw "invalid index";
}
}
'use strict';
const knex = require('knex');
module.exports = {
knexline,
}
function knexline(model, qb) {
const modelTable = model.identity;