Skip to content

Instantly share code, notes, and snippets.

View rares's full-sized avatar
🌑

(╯°□°)╯︵ ┻━┻ rares

🌑
View GitHub Profile
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)
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
-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) ->
(defn flip
[f]
(fn [& argv]
(apply f (reverse argv))))
(println ((flip /) 10 2))
class Stream
attr_accessor :head
def initialize(head, &tail)
@head, @tail = head, tail
end
def tail
@tail ? @tail.call : nil
end
require "sinatra"
require "set"
connections = Set.new
configure do
mime_type :event_stream, "text/event-stream"
set :server, :thin
end
class Object
def method_depth(name)
puts method(name.to_sym).__send__(:caller).drop(1)
end
end
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) }
@rares
rares / gist:855726
Created March 4, 2011 21:21
pre-commit syntax hook
#!/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
require "cool.io"
class MyStatWatcher < Coolio::StatWatcher
def initialize(path, interval)
super
end
def on_change
puts path