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
# 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 |
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
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] |
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
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] |
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
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 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
# 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. |
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
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 |
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
# 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 |
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 A | |
def hello | |
"A#hello" | |
end | |
def method_missing(method, *args) | |
"A#method_missing" | |
end | |
protected :hello |
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
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 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
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 |