Skip to content

Instantly share code, notes, and snippets.

View notahat's full-sized avatar

Pete Yandell notahat

View GitHub Profile
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 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.
@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
@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 / 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 / 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
class Dependency
def self.foo
puts "Foo"
end
def self.bar
puts "Bar"
end
end
@notahat
notahat / valid.rb
Created October 11, 2012 02:50
Testing fail?
# I have a class that delegates functionality to a couple of objects that it
# constructs. I want to test this in isolation. I want to make sure that the
# objects are constructed with the right arguments. I also want to make sure
# that the results from the objects are handled correctly.
#
# I'm finding it hard to structure the code and test in a way that isn't
# cumbersome. What's below works, but it feels like a lot of stubbing and setup
# for something the should be simpler.
#
# Anyone got a better approach for this?
class PagingEnumerator < Enumerator
def initialize(&block)
super do |yielder|
page = 0
loop do
items = block.call(page)
break if items.empty?
items.each {|item| yielder.yield(item) }
page += 1
# On a new ubuntu 14.04 box, as root, with the following variables
# export BUILDBOX_AGENT_NAME="buildbox-agent-N"
# export BUILDBOX_AGENT_ACCESS_TOKEN="<your token here>"
# export BUILDBOX_AGENT_SSH_PRIVATE_KEY="<an ssh private key>"
# export BUILDBOX_AGENT_SSH_PUBLIC_KEY="<an ssh public key>"
# Make tmp totally in memory
echo "none /tmp tmpfs size=4g 0 0" >> /etc/fstab
mount /tmp