Skip to content

Instantly share code, notes, and snippets.

@Avaq
Avaq / ClassLoader.php
Last active Dec 18, 2015
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!
View ClassLoader.php
<?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).
View composable-callbacks.js
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 Nov 14, 2017
A compilation of techniques for creating secure web applications
@Avaq
Avaq / async-problem-callbacks-solution.js
Last active Dec 20, 2017
Callback solution to the Async Problem
View async-problem-callbacks-solution.js
// 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]
View dates.js
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 Mar 5, 2018
Functional JavaScript cookbook
View fold.js
//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 Feb 16, 2019
Nested Directory Structure in SQL
View directories-my.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 Mar 1, 2019
Comprehensive Ramda to Sanctuary list
View ramda-sanctuary.md
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 Apr 15, 2019
Exploring an alternative placeholder implementation
View placeholder.md

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 Jul 24, 2019
Keybase proof of Github
View keybase.md

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: