Skip to content

Instantly share code, notes, and snippets.

@Avaq
Avaq / security-techniques.md
Last active November 14, 2017 11:09
A compilation of techniques for creating secure web applications

Restrictors

@Avaq
Avaq / request.js
Last active November 24, 2020 14:42
Request adapted to work with Fluture
'use strict';
const request = require('request');
const Future = require('fluture');
module.exports = o => Future((l, r) => {
const socket = request(o, (err, res) => err ? l(err) : r(res));
return () => socket.abort();
});
@Avaq
Avaq / SKI.js
Last active April 23, 2020 18:36
Combinatory Fun
const S = f => g => x => f(x)(g(x))
const K = x => y => x
const I = S(K)(K)
const B = S(K(S))(K)
const C = S(S(K(B))(S))(K(K))
const A = S(K(I))
const T = C(A)
const W = S(S)(K(I))
@Avaq
Avaq / placeholder.md
Last active April 15, 2019 16:04
Exploring an alternative placeholder implementation

I published a library which implements this idea; furry.

# From To Normal Alternative
1 a → b → c a → c f(_, b)(a) f(_, b)(a)
2 a → b → c b → a → c nope f(_)(b, a)
3 a → b → c → d b → d f(a, _, c)(b) f(a, _, c)(b)
4 a → b → c → d a → b → d f(_, _, c)(a, b) f(_, _, c)(a, b)
5 a → b → c → d a → c → d f(_, b)(a, c) f(_, b, _)(a, c)
@Avaq
Avaq / fold.js
Last active March 5, 2018 12:28
Functional JavaScript cookbook
//Combinators
const I = x => x;
//List manipulation
const head = xs => xs[0];
const tail = xs => xs.slice(1);
const append = x => xs => [...xs, x];
//Iteration
const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y;
@Avaq
Avaq / combinators.js
Last active March 18, 2024 20:49
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@Avaq
Avaq / dates.js
Last active December 20, 2017 13:04
new Date('12 dec, 20111') //-> +020111-12-11T23:00:00.000Z
new Date(-1, 1) //-> -000001-01-31T23:00:00.000Z
new Date(-1, -1) //-> -000002-11-30T23:00:00.000Z
new Date(-10, 1) //-> -000010-01-31T23:00:00.000Z
new Date('12 dec, 000201') //-> 0201-12-11T23:00:00.000Z
new Date('12 dec, 201') //-> 0201-12-11T23:00:00.000Z
new Date('1212 dec') //-> 1212-11-30T23:00:00.000Z
new Date('1212 2 dec 2') //-> 1212-12-01T23:00:00.000Z
new Date('1212 2 dec 4') //-> 1212-12-01T23:00:00.000Z
new Date('1212 2 dec') //-> 1212-12-01T23:00:00.000Z
@Avaq
Avaq / pull-private.sh
Created November 4, 2014 12:25
Exporting and importing GPG keys over SSH
ssh user@remote gpg --export-secret-key KeyId | gpg --allow-secret-key-import --import
@Avaq
Avaq / ClassLoader.php
Last active December 18, 2015 02:48
A FIG PSR-0 class loader heavily inspired on the official SplClassLoader. This version has a lot of improvements over the original. Be sure to star this gist if you liked it and leave your suggestions in the comment section beloowwwww!
<?php
/**
* Avaq's PSR-0 ClassLoader.
*
* @author Avaq <aldwin.vlasblom@gmail.com>
*
* A FIG PSR-0 class loader heavily inspired on
* [the official SplClassLoader](https://gist.github.com/jwage/221634) and originally
* developped for use in the [Forall framework](https://github.com/ForallFramework).