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]) { |
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
(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
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
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
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
/* 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
import scala.language.implicitConversions | |
/* | |
So earlier this week I was reading about how scalaz implements the "enhance my library" | |
pattern. It's a pretty nifty way to add methods to existing objects in a type-safe way. | |
However, this is @zip here, so of course I'm gonna use it for something gross. | |
So, I'm a fan of Javascript, inexplicably. Javascript has a… looser… notion of types. | |
In particular, all sorts of things can be true or false! Empty lists are false, full | |
ones are true. Who wouldn't want the following capability? |
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 scalaz._ | |
import Scalaz._ | |
object HowMonadsWork { | |
/* | |
You may have found yourself asking, what is a Monad, anyway? | |
Some kinda burrito-spacesuit-magical-wavy thing, if you ask the internet. | |
The internet isn't very helpful. This probably isn't, either. | |
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 | |
# "(root) " in red if root | |
# Hostname (if SSH_TTY is set) | |
# Directory | |
# Git branch, if in git and available | |
# Last command exit status | |
# $ times shlvl, or # if root |
OlderNewer