Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am L8D on github.
  • I am l8d (https://keybase.io/l8d) on keybase.
  • I have a public key whose fingerprint is 4832 9B22 CE81 B2BF 5C92 C2BE 59BC FB0F CFAF 17CF

To claim this, I am signing this object:

View test1.js
var http = require('http');
var fs = require('fs');
// write out numbers
function writeNumbers(res) {
var counter = 0;
}
// increment global, write to client
for (var i = 0; i < 100; i++) {
counter++;
res.write(counter.toString() + '\n');
View being-fast.md
@L8D
L8D / app.js
Last active Aug 28, 2015
Setting ExpressJS server timeout using best practices
View app.js
var express = require('express'),
http = require('http'),
app = express();
var server = http.createServer(app);
var timeout = 0;
server.setTimeout(timeout, function() {
server.listen(app.get('port'), function() {
View async.js
function findOrCreate(id) {
return Promise.try(function() {
return db.find(id);
}).then(function(result) {
if (result == null) {
return db.create(id);
} else {
return result;
}
});
@L8D
L8D / wm.js
Last active Aug 29, 2015 — forked from gajus/wm.js
View wm.js
let wm = new WeakMap();
class Foo {
constructor () {
var privateData = {};
wm.set(this, privateData);
privateData.myProperty = 1;
}
View example.hs
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
View butchered.js
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();
}
View spec-zvi
% 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
View Rl.hs
{-# 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)
You can’t perform that action at this time.