Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bts on github.
  • I am bts (https://keybase.io/bts) on keybase.
  • I have a public key whose fingerprint is C21B 6375 05AC 06EF EEF8 E0F3 7FBA 4DDD 7EC8 97F4

To claim this, I am signing this object:

(defn topo-sort
"Provided a map of values to their dependencies, returns a seq of the values
sorted topologically.
Adapted from code by cgrande at:
https://groups.google.com/forum/#!topic/clojure/-sypb2Djhio"
[deps]
(mapcat #(for [[u vs] %
:when (empty? vs)]
u)
(take-while seq
@bts
bts / backtrace.txt
Created May 31, 2013 18:27
Intermittent IO.popen "Bad file descriptor" failures upon IO#close when using read+write mode on JRuby 1.7.3.
% jruby -J-Djruby.backtrace.style=raw popen.rb
using r...
using r+...
IOError: Bad file descriptor
getStackTrace at java/lang/Thread.java:1567
getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:171
getBacktrace at org/jruby/runtime/backtrace/TraceType.java:39
prepareBacktrace at org/jruby/RubyException.java:215
preRaise at org/jruby/exceptions/RaiseException.java:214
preRaise at org/jruby/exceptions/RaiseException.java:195
@bts
bts / README.md
Created June 3, 2012 02:18 — forked from juno/README.md
Install rbenv and ruby-build to Amazon Linux (cloud-init).
  1. run user-data.sh
  2. run install-ruby.sh.
router.proxyRequest req, res,
host: proxyHost
port: proxyPort
# becomes:
router.proxyRequest req, res,
host: proxyHost
port: proxyPort
responseHeaderTransform: (headers) ->
@bts
bts / gist:2241714
Created March 29, 2012 18:34
Fast XML escaping in Ruby 1.9 using FFI/libxml2
require 'ffi'
module XmlEscaper
extend FFI::Library
ffi_lib 'xml2'
UTF8 = Encoding.find('UTF-8')
def self.escape(string)
char_ptr = self.xmlEncodeSpecialChars(nil, string)
encoded = char_ptr.read_string
@bts
bts / option1.rb
Created September 30, 2011 21:20 — forked from bkeepers/plugin.rb
Theoretical plugin API for Qu
# bts: If I'm writing a plugin, I'd typically like to have a namespace to add
# my own classes, so I would skip this option:
# Qu.plugin(:autoretry) do |*errors|
# options = {:limit => 3}.merge!(errors.extract_options!)
# errors << Exception if errors.empty?
# before :failure do |job, e|
# if errors.any? {|error| error === e }
# job.data[:retries] += 1
@bts
bts / install_homebrew.rb
Created August 4, 2011 21:25 — forked from mxcl/install_homebrew.markdown
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
require 'sass'
configure do
Tilt.register 'scss', Tilt::SassTemplate
set :scss, :syntax => :scss
end
get '/stylesheets/:file.css' do |file|
content_type 'text/css', :charset => 'utf-8'
#!/usr/bin/env ruby
#
# This script generates RESTful scaffolds from your pre-existing models.
# Copyright 2008 Kyle Maxwell, available under the MIT licence.
#
require "rubygems"
require "active_support"
content = File.read(File.dirname(__FILE__) + "/db/schema.rb").split("create_table")