Skip to content

Instantly share code, notes, and snippets.

error_handler = lambda do
"An error occured!"
end
not_found(&error_handler)
error(&error_handler)
class MyMiddleware
def self.call(env)
new({:a => 'b'}).call(env)
end
def initialize(config)
@config = config
end
def call(env)
(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
require 'my_app'
MyApp.set :logger, MyFancyLogger.new
run MyApp
#!/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
my_handler = lambda do
# stuff
end
get '/foo', &my_handler
post '/bar', &my_handler
eschaton :: ~/Projects » cat scratch.rb
# encoding: utf-8
str = "This is ä strïng with ümläuts in it"
regex = / (\p{Alpha}) /
puts __ENCODING__
puts str.encoding
puts regex.encoding
class MyAwesomeMiddleware
def initialize(app)
@app = app
end
def call(env)
return_value = @app.call(env)
do_awesome_post_request_processing
@cypher
cypher / feed.xml
Created April 26, 2011 11:24
Jekyll Atom Feed example
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>The Nuclear Squid</title>
<link href="http://nuclearsquid.com/feed.xml" rel="self"/>
<link href="http://nuclearsquid.com/"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
Rubinius Crash Report #rbxcrashreport
[[Exception]]
A toplevel exception occurred
undefined local variable or method `this_does_not_exist' on an instance of Object. (NameError)
Backtrace:
Kernel(Object)#this_does_not_exist (method_missing) at kernel/delta
/kernel.rb:79
{ } in Object#__script__ at -e:1