Skip to content

Instantly share code, notes, and snippets.

View notahat's full-sized avatar

Pete Yandell notahat

View GitHub Profile
@notahat
notahat / capybara_support.rb
Created May 24, 2011 01:58
Make RSpec and Capybara give backtraces for controller exceptions
# Put this in spec/support
# Make sure we get stack traces for controller and view exceptions.
ActionController::Base.class_eval do
def rescue_action_without_handler(exception)
raise exception
end
end
@notahat
notahat / factorial.rb
Created November 16, 2010 05:34
Ruby 1.9 lambda calculus fun
alias λ lambda
λ {|f| λ {|x| f[λ {|y| x[x][y] } ] }[λ {|x| f[λ {|y| x[x][y] }] }] }[λ {|f| λ {|n| n == 0 ? 1 : n * f[n-1] } }][6]
@notahat
notahat / kata.rb
Created September 27, 2010 23:26
def kata(digits = [], sum = 0, has_pair = false)
if sum < 15
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result +
kata(digits + [digit], sum + digit, has_pair) +
kata(digits + [digit, digit], sum + digit + digit, true)
end
elsif sum == 15 && has_pair
[digits]
@notahat
notahat / kata.rb
Created September 27, 2010 23:06
def kata(digits = [], has_pair = false)
if digits.inject {|sum, digit| sum + digit } == 15
has_pair ? [digits] : []
else
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true)
end
end
end
# This is a replacement for Ruby's backtick operator that avoids shell
# injection attacks.
#
# In web apps that allow file uploading, it's common to run shell commands that
# operate on those files. For example, you might do this:
#
# `convert -resize 100x100 '#{image_filename}'`
#
# The problem is that a carefully crafted filename could cause trouble.
diff --git a/sysdeputil.c b/sysdeputil.c
index 66dbe30..9dc8a5e 100644
--- a/vsftpd-2.3.2/sysdeputil.c
+++ b/vsftpd-2.3.2/sysdeputil.c
@@ -64,10 +64,6 @@
#include <utmpx.h>
/* BEGIN config */
-#if defined(__APPLE__)
- #undef VSF_SYSDEP_HAVE_UTMPX
# Here's some more hints at what's coming in Machinist 2.
Machinist::Collection.blueprint(:stuff) do
user
posts 3, :author => user
posts.each do |post|
comments 3, :post => post
end
end
class A
def hello
"A#hello"
end
def method_missing(method, *args)
"A#method_missing"
end
protected :hello
if RUBY_VERSION.starts_with?("1.8")
# This is a partial implementation of Fibers for Ruby 1.8 (they're normally
# a 1.9 only feature.)
#
# It does just enough to let me use it for testing some communications code.
# In particular, you can only have one Fiber alive at any given time!
#
# It uses continuations, so is probably pretty slow and memory hungry.
This is a note stemming from a Twitter conversation with Alexis Richardson (@monadic). I was
complaining that the message queueing software I'd looked at solved a performance problem I
didn't have, and ignored an admin problem I did have. He challenged me to write up my
particular use case for the RabbitMQ engineers to think about.
This is very much a wish-list. Ideally I'd like a queueing solution to massage my back, and
make me hot chocolate too. The practical solution, however, probably lies somewhere between
this document and current message queueing systems.
# Message Queueing Meets SMS