Skip to content

Instantly share code, notes, and snippets.

class ResponsePadder
def initialize (app, minlength, pad=' ', &condition)
@app = app
@minlength = minlength
@pad = pad
@condition = condition
end
def call (env)
response = @app.call(env)
fib' :: (Integral a) => a -> (a, a)
fib' 0 = (0, 0)
fib' 1 = (0, 1)
fib' x = (b, a + b)
where (a, b) = fib'(x-1)
fib :: (Integral a) => a -> a
fib x = result
where (_, result) = fib'(x)
class Lupin::Test
dynamic_method :foo do |g|
ast = Lupin::Parser.parse("1+4- -10", :root => :expression).value
Lupin::Compiler.compile(ast, g)
g.ret
end
end
puts Lupin::Test.new.foo #=> 15.0
# Causes Rails to output HTML instead of XHTML.
# Example: <%= image_tag "bacon.png" %>
# Before: <img src="/images/bacon.png" />
# After: <img src="/images/bacon.png">
module ActionView::Helpers::TagHelper
# Force the 'open' argument to always be true.
old_tag = instance_method(:tag)
define_method :tag do |name, options = nil, open = true, escape = true|
old_tag.bind(self).call(name, options, true, escape)
%%{
machine telnet_nvt_common;
alphtype unsigned char;
# Special bytes that must be handled differently from normal text:
CR = "\r"; # Only \0 or \n may follow
IAC = 255; # Telnet command marker
special_byte = CR | IAC;
# The only bytes that may follow a CR:
class Integer
def factor_of? (other)
other % self == 0
end
end
1.upto(100) do |x|
bt = (3.factor_of?(x) ? "" :"not ") + "divisible by 3"
bf = (5.factor_of?(x) ? "" : "not ") + "divisible by 5"
puts "The value #{x} is #{bt} and is #{bf}"