Skip to content

Instantly share code, notes, and snippets.

View L8D's full-sized avatar

Tenor L8D

View GitHub Profile
@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
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();
}
% 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
@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)
function Signal(sub) {
this.sub = sub;
}
Signal.prototype = {
/**
* Applies the given function over each event.
*/
map: function(fn) {
var sub = this.sub;
@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 / 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 / fun.js
Created October 10, 2014 05:39
Basic Church-encoded data structures written in lazy-evaluable JavaScript
function compose(f) {
return function(g) {
return function(x) {
return f(g(x));
};
};
}
// allTheNumbersFrom(Zero) -> 0, 1, 2, 3...
function allTheNumbersFrom(number) {
@L8D
L8D / rxreact.js
Created September 24, 2014 07:58
var Game = React.createClass({
render: function() {
var x = this.props.x,
y = this.props.y;
return (
<svg width={Math.max(x + 10, 200)} height={height: Math.max(y + 10, 200)}>
<circle cx={50} cy={50} r={2} fill="#000" />
<circle cx={x} cy={y} r={2} fill="#000" />
<line x1={50} y1={50} x2={x} y2={y} stroke="#000" />
@L8D
L8D / server.js
Created September 23, 2014 02:35
var parser = require('body-parser')
, config = require('./config')
, express = require('express')
, morgan = require('morgan')
, _ = require('lodash')
, path = require('path')
;
var app = module.exports = express();