Skip to content

Instantly share code, notes, and snippets.

@proprietary
proprietary / functionalFibs.js
Last active January 10, 2016 21:20
Showing off cool ES6/7 features
/* This would be slow as hell in practice
* because the algorithm is quadratic; the list
* is recomputed every time. But oh, the
* simplicity is refreshing.
*
* Exercise for you, gist reader: implement
* this same thing with Immutable.js.
*/
function fibs([...nums], max) {
/* Demo of fibs in an imperative style
* Made for benchmarking against a functional
* style equivalent code
*/
function fib(max) {
var ret = [0];
var last = 0;
var next = 1;
var temp;
@proprietary
proprietary / sqlite3GetColumnIndexByName.c
Created January 16, 2016 07:29
sqlite3 how to get column index by column name
#include <stdlib.h>
#include "../sqlite3/sqlite3.h"
#include "domain.h"
/* okay this function is stolen; the rest are MINE */
unsigned long
djb2Hash(unsigned char *str)
{
unsigned long hash = 5381;
int c;
@proprietary
proprietary / queryString.js
Created January 26, 2016 06:15
utility functions for query strings in javascript
function serializeQuery (queryObj) {
return '?' + Object.keys(queryObj)
.reduce(function (r, q) {
r.push(encodeURIComponent(q) + '=' + encodeURIComponent(queryObj[q]))
return r
}, [])
.join('&')
}
function readQuery (queryStr_) {
@proprietary
proprietary / milliseconds since epoch in MySQL
Created January 26, 2016 08:58
how to get milliseconds in MySQL
select round(unix_timestamp(sysdate(3))*1000);
// Apache2.0 license
// Copyright (c) 2016 Zeleke Snyder
import { chunk } from 'lodash'
export const packIntoStr = function ([...bytes]) {
// Pack bytes into string
var bytesLen = bytes.length
var m = 4 - (bytesLen % 4) // remaining to make it fit
@proprietary
proprietary / cvimrc
Last active March 18, 2016 06:54
cvimrc
set autoupdategist
set nosmoothscroll
set noautofocus
set typelinkhints
let searchlimit = 30
let scrollstep = 80
let barposition = "bottom"
set linkanimations
set scalehints
set nativelinkorder
@proprietary
proprietary / leftpad.cc
Last active April 14, 2016 13:16
making fun of that "left-pad" package in NPM…except this is actually potentially useful
// $ clang++ -std=c++11 -O3 leftpad.cc -o leftpad
// $ ./leftpad
#include <string.h>
#include <stdio.h>
namespace leftpad {
enum Dirn {
Left = 0,
Right = 1,
@proprietary
proprietary / updater.clj
Created July 27, 2017 05:46
rough draft of a clojure macro automating the U in CRUD
(defn get-columns
[_]
#{"part_id" "name" "image_paths"})
(defn update
[_ _ _]
"UPDATED!!")
(defmacro UPDATER
[table]
const Y = f => (x => x(x))(x => f(v => x(x)(v)))
// example
let factorial = Y(fact => n => n === 1 ? 1 : n*fact(n-1))
factorial(4) // => 24