This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Came up with this today */ | |
Function.prototype.lift = function(f) { | |
return function() { | |
return this.apply(this, Array.prototype.map.call(arguments, f)); | |
}.bind(this) | |
} | |
/* Why!? Well, suppose you've got some function that takes a bunch of ints... */ | |
// cmp :: Int -> Int -> Int | |
function cmp (a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function id(x) { return x; } | |
function constant(v) { | |
return function () { | |
return v; | |
} | |
} | |
Function.prototype.memoize = function() { | |
var f = this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> implicit class InputStreamAsString(is: InputStream) { | |
| def asString = { | |
| val buff = new Array[Byte](256) | |
| new String(Iterator.continually({ val c = is.read(buff); buff.take(c)}).takeWhile(_.size>0).flatten.toArray) | |
| } | |
| } | |
defined class InputStreamAsString | |
scala> var s = new ByteArrayInputStream("asdfasdfasdfasdfasdf".getBytes("UTF-8")) | |
s: java.io.ByteArrayInputStream = java.io.ByteArrayInputStream@72c454a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.lenses = function () { | |
var lens = null; | |
for (arg in arguments) { | |
var next = Object.lens(arguments[arg]); | |
lens = lens ? lens.compose(next) : next; | |
} | |
return lens | |
} | |
var l = Object.lenses("one", "five") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
$.lens = {}; | |
$.lens.of = function (get, set) { | |
var lens = function (d) { return get(d); } | |
lens.set = set; | |
lens.modify = function (d, f) { return set(d, f(get(d))); } | |
lens.compose = function (other_lens) { | |
return $.lens.of( | |
function (d) { return other_lens(get(d)); }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setps1 { | |
export GIT_PS1_SHOWDIRTYSTATE=true | |
export GIT_PS1_SHOWUNTRACKEDFILES=true | |
# Hostname (if SSH_TTY is set) | |
# Directory | |
# Git branch | |
# Last command exit status | |
# $ | |
export PS1='\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.Queue | |
object Brainfuck { | |
def main(args: Array[String]) { | |
val code = io.Source.fromFile("src.txt") filter ("[]<>.,+-" contains _) toSeq | |
exec(code) | |
} | |
def exec(code: Seq[Char]) { |
NewerOlder