Skip to content

Instantly share code, notes, and snippets.

my_handler = lambda do
# stuff
end
get '/foo', &my_handler
post '/bar', &my_handler
#!/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
require 'my_app'
MyApp.set :logger, MyFancyLogger.new
run MyApp
(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
class MyMiddleware
def self.call(env)
new({:a => 'b'}).call(env)
end
def initialize(config)
@config = config
end
def call(env)
error_handler = lambda do
"An error occured!"
end
not_found(&error_handler)
error(&error_handler)
@cypher
cypher / config.ru
Created February 17, 2010 09:50
Sample sinatra app that uses lenary's partial helper (http://gist.github.com/119874). Tested using Sinatra 0.9.4
require 'sinatra/base'
require 'my_app'
run MyApp
# Java Classpath
if [[ -d "${HOME}/classes/" ]]
then
for jar in ${HOME}/classes/*.jar
do
CLASSPATH="${jar}:${CLASSPATH}"
done
fi
class Proc
# "join" two procs
def +(other)
Proc.new { self.call; other.call }
end
end
# 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