This file contains 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
class Box[T](val value: T) { | |
def map[B](f: T => B) = new Box(f(this.value)) | |
def flatMap[B](f: T => Box[B]) = f(this.value) | |
def apply[B](f: Box[T => B]) = new Box(f.value(this.value)) | |
} | |
println(new Box("cool").map((a:String) => a.toUpperCase).value) |
This file contains 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
class String | |
def strstr(pattern) | |
0.upto self.size do |i| | |
matches = 0 | |
0.upto pattern.size do |j| | |
if self[i + j] == pattern[j] | |
matches += 1 | |
else | |
break |
This file contains 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
-module(stream). | |
-export([take/2, build/2]). | |
build(K, C) -> | |
[K|fun() -> build(K + C, C) end]. | |
take(S, N) -> | |
take(S, [], N). | |
take([_|_], Out, 0) -> Out; | |
take([K|C], Out, N) -> |
This file contains 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
(defn flip | |
[f] | |
(fn [& argv] | |
(apply f (reverse argv)))) | |
(println ((flip /) 10 2)) |
This file contains 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
class Stream | |
attr_accessor :head | |
def initialize(head, &tail) | |
@head, @tail = head, tail | |
end | |
def tail | |
@tail ? @tail.call : nil | |
end |
This file contains 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
require "sinatra" | |
require "set" | |
connections = Set.new | |
configure do | |
mime_type :event_stream, "text/event-stream" | |
set :server, :thin | |
end |
This file contains 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
class Object | |
def method_depth(name) | |
puts method(name.to_sym).__send__(:caller).drop(1) | |
end | |
end |
This file contains 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 java.util.concurrent.ArrayBlockingQueue | |
class Worker extends Runnable { | |
private val queue = new ArrayBlockingQueue[String](10) | |
def pushWork(s: String) = queue.put(s) | |
def run { | |
while(true) { | |
for { job <- Option(queue.poll) } yield { println(job) } |
This file contains 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
#!/bin/sh | |
exec git diff-index --name-only --cached HEAD -- | egrep -e "\.e?rb$" | xargs -t -n 1 -P 2 /usr/bin/env ruby -c |
This file contains 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
require "cool.io" | |
class MyStatWatcher < Coolio::StatWatcher | |
def initialize(path, interval) | |
super | |
end | |
def on_change | |
puts path |
NewerOlder