Skip to content

Instantly share code, notes, and snippets.

@L8D
L8D / median.rb
Last active Feb 21, 2018
Median of array in ruby
View median.rb
def median_of a
return nil if a.empty?
sorted = a.sort
len = sorted.length
(sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
end
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 signal.js
function Signal(sub) {
this.sub = sub;
}
Signal.prototype = {
/**
* Applies the given function over each event.
*/
map: function(fn) {
var sub = this.sub;
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');
@L8D
L8D / test.js
Last active Jan 4, 2016 — forked from oroce/test.js
View test.js
var gimmeFullscreenMethod = function() {
'use strict';
var el = document.documentElement, open, cancel, video;
open = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
cancel = el.exitFullscreen || el.webkitExitFullscreen || el.mozExitFullscreen || el.msExitFullscreen;
if (open) {
return {
@L8D
L8D / hi.bf
Last active Jan 3, 2016
Output: "hi\n"
View hi.bf
+++++ +++++ [ > +++++ +++++ > + << - ] > ++++ . + . > .
@L8D
L8D / bf.sh
Last active Jan 3, 2016
Script to compose optimize.hs, compile.hs and GCC.
View bf.sh
#!/usr/bin/env bash
cat $1 | ./compile | gcc --std=c99 -x c -o $2 -
@L8D
L8D / bfasm.hs
Last active Jan 3, 2016
BFA Assembler in Haskell
View bfasm.hs
import Data.Char (isSpace)
import Data.Maybe (listToMaybe, fromMaybe)
maybeRead :: Read a => String -> Maybe a
maybeRead = fmap fst . listToMaybe . reads
parseLine :: String -> (Int, String)
parseLine = uncurry ((,) . fromMaybe 1 . maybeRead) . break isSpace
makeLine :: (Int, String) -> String
@L8D
L8D / compile.hs
Last active Jan 3, 2016
Brainf*ck-to-C compiler
View compile.hs
{-# LANGUAGE OverloadedStrings #-}
codeChar :: Char -> String
codeChar c = case c of
'+' -> "++*p;"
'-' -> "--*p;"
'>' -> "++p;"
'<' -> "--p;"
'.' -> "fputc(*p, mode ? f : stdout);"
'|' -> "fflush(mode ? f : stdout);"
@L8D
L8D / compile.js
Last active Jan 3, 2016
Brainf*ck compiler using C as a midpoint.
View compile.js
#!/usr/bin/env node
var fs = require('fs'),
spawn = require('child_process').spawn,
argv = require('optimist').argv;
var gcc = spawn('gcc', [
'--std=c99',
'-o', argv.o || argv._[0] ? argv._[0].split('.')[0] : 'a.out',
'-x', 'c',
'-'
You can’t perform that action at this time.