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
my_handler = lambda do | |
# stuff | |
end | |
get '/foo', &my_handler | |
post '/bar', &my_handler |
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
#!/usr/bin/env ruby | |
# | |
# Released under MIT License | |
# Copyright (c) 2009 Markus Prinz | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
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
require 'my_app' | |
MyApp.set :logger, MyFancyLogger.new | |
run MyApp |
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
(defn euler5 [] | |
(+ 1 | |
(last | |
(take-while (fn [w] (not | |
(every? #(zero? (rem w %)) (range 1 20) ))) | |
(range 1 1000000000000 1))))) | |
;; Takes about 5 mins on my machine | |
(defn euler5b [] | |
(first (drop-while |
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
class MyMiddleware | |
def self.call(env) | |
new({:a => 'b'}).call(env) | |
end | |
def initialize(config) | |
@config = config | |
end | |
def call(env) |
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
error_handler = lambda do | |
"An error occured!" | |
end | |
not_found(&error_handler) | |
error(&error_handler) |
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
require 'sinatra/base' | |
require 'my_app' | |
run MyApp |
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
# Java Classpath | |
if [[ -d "${HOME}/classes/" ]] | |
then | |
for jar in ${HOME}/classes/*.jar | |
do | |
CLASSPATH="${jar}:${CLASSPATH}" | |
done | |
fi |
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
class Proc | |
# "join" two procs | |
def +(other) | |
Proc.new { self.call; other.call } | |
end | |
end |
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
# Runs the given array of +commands+ in parallel. The amount of spawned | |
# simultaneous jobs is determined by the `j' env variable and defaults to 1. | |
def parallel_execute(commands) | |
@jobs ||= ENV['j'] ? ENV['j'].to_i : 1 | |
queue = Queue.new | |
queue = commands.each { |command| queue << command } | |
Array.new(@jobs) do | |
Thread.new do | |
while command = queue.shift |