Skip to content

Instantly share code, notes, and snippets.

View L8D's full-sized avatar

Tenor L8D

View GitHub Profile
@L8D
L8D / maybe.js
Created October 22, 2014 01:02
Fantasy-land compliant and JIT-optimizable Maybe
// Copyright (c) 2014 Tenor Biel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@L8D
L8D / either.js
Created October 22, 2014 01:14
Fantasy-land compliant and JIT-optimizable Either
// Copyright (c) 2014 Tenor Biel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@L8D
L8D / Rl.hs
Created February 7, 2015 09:24
{-# LANGUAGE TemplateHaskell #-}
module Rl where
import Control.Monad.Trans.State
import Control.Lens
import Text.Read (readMaybe)
import qualified Data.Map as M
import Control.Monad.IO.Class
import Control.Applicative (liftA2)
% comments are like this
% outside of operator precedence, the only special
% syntax is ':-' and ':='. ':=' is used for a type
% annotation. Types are just additional predicate
% calls, but they are restricted to not using IO
% values or ambigious stuff a compiler couldn't
% figure out.
my_predicate := true. % my_predicate is valid under any pretense
function archiveWeeks(tasks) {
return lodash.chain(tasks)
.reverse()
.groupBy({created_at} => new Date(created_at.getFullYear(), created_at.getMonth(), created_at.getDate()))
.map((t, d) => {date: new Date(d), tasks: t})
.groupBy(weekOf) // because I'm lazy
.map((d, w) => {week: w, days: d})
.value();
}
@L8D
L8D / example.hs
Last active August 29, 2015 14:23
findById :: User.Id -> forall s. Tx Postgres s (Maybe User)
findById userId = do
result <- maybeEx [stmt|
SELECT id, email, created_at, updated_at
FROM users
WHERE id = $userId
|]
return case result of
Just row -> toUser row
@L8D
L8D / wm.js
Last active August 29, 2015 14:27 — forked from gajus/wm.js
let wm = new WeakMap();
class Foo {
constructor () {
var privateData = {};
wm.set(this, privateData);
privateData.myProperty = 1;
}
@L8D
L8D / being-fast.md
Last active October 12, 2015 20:58
@L8D
L8D / gist:5498414
Last active December 16, 2015 21:19
Snippet of a javascript date formatter.
return d.getUTCFullYear()
+ '-' + zeroFill(d.getUTCMonth() + 1, 2)
+ '-' + zeroFill(d.getUTCDate(), 2)
+ 'T' + zeroFill(d.getUTCHours(), 2)
+ ':' + zeroFill(d.getUTCMinutes(), 2)
+ ':' + zeroFill(d.getUTCSeconds(), 2)
+ '.' + zeroFill(d.getUTCMilliseconds() * 1000, 6)
+ 'Z';
@L8D
L8D / gist:6148641
Created August 4, 2013 01:14
Public SSH key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSB6JUsqH814A5N78yQv/vy2UvHDUQGSIkknGiwRyQjX5h4aodgM6unvcIo1kZUldDCa4kxoUP1hN2Slb9UNWH/gwvSwmHI5T6M8W6b2kEcv4PX5BBn+V2aNI5KULq3OOevIrv5ofYf0shqRmX39mxLd2UU5tVLGYrx9OdYFK+2aRU6PJfMU8g2z6ArEqIvur81TeFnqdCMcihkM/1SnmBn/7c+/TfvjNm6xBBk2MC5Pw6iSTGi/JkIllMCXfV8FFvs4hYl0vfUowbBFdp5VQNrbYIJ8Qnn09hAilyFTRTlidkgAiAjr78pkClsisUA/M9lSjeD6G/7yhfO8o+Xv9J seed@Alex