Skip to content

Instantly share code, notes, and snippets.

@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).
const after = t => x => cont => {
const id = setTimeout (cont, t, x)
return () => clearTimeout (id)
}
const map = f => run => cont => run(x => cont (f (x)))
const chain = f => run => cont => run(x => f (x) (cont))
const run = chain (x => after (2000) (`${x}C`))
(map (x => `${x}B`)
@Avaq
Avaq / security-techniques.md
Last active November 14, 2017 11:09
A compilation of techniques for creating secure web applications

Restrictors

@Avaq
Avaq / async-problem-callbacks-solution.js
Last active December 20, 2017 12:49
Callback solution to the Async Problem
// pipe :: Array (Any -> Any) -> Any -> Any
const pipe = fs => x => fs.reduce ((y, f) => f (y), x)
// lmap :: (a -> b) -> Array a -> Array b
const lmap = f => xs => xs.map (f)
// append :: a -> Array a -> Array a
const append = x => xs => [...xs, 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 / 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 / directories-my.sql
Last active February 16, 2019 21:23
Nested Directory Structure in SQL
-- Create our directories table.
CREATE TABLE `directories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`lft` int(11) NOT NULL,
`rgt` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `directory_lft` (`lft`),
UNIQUE KEY `directory_rgt` (`rgt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@Avaq
Avaq / ramda-sanctuary.md
Last active March 1, 2019 00:26
Comprehensive Ramda to Sanctuary list
Ramda Sanctuary
add(a, b) add(b, a)
addIndex(f) ``
adjust(f, i, xs) ``
all(f, xs) ``
allPass(fs, x) allPass(fs, x)
always(x) K(x)
and(a, b) and(a, b)
any(f, x) ``
@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 / keybase.md
Created July 24, 2019 10:12
Keybase proof of Github

Keybase proof

I hereby claim:

  • I am avaq on github.
  • I am avaq (https://keybase.io/avaq) on keybase.
  • I have a public key ASAlzUb3ZvdW8CYnTo0SaI0TuaSBUyNS9vxUUFYFbDpgUgo

To claim this, I am signing this object: