Skip to content

Instantly share code, notes, and snippets.

View gist:c72303df32dc4dc7860c
ruby-install -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/01-fix-make-clean.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/02-railsbench-gc.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/03-display-more-detailed-stack-trace.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/04-fork-support-for-gc-logging.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/05-track-live-dataset-size.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/06-webrick_204_304_keep_alive_fix.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/07-export-a-few-more-symbols-for-ruby-prof.patch -p https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p545/railsexpress/08-thread-variables.patch -p https://raw
@bhb
bhb / exception_logging_example.rb
Created May 1, 2014
Examples for logging Ruby exceptions
View exception_logging_example.rb
begin
raise "flunk!"
rescue => e
puts "Error was #{e.message}" # Error was flunk!
puts "Error was #{e}" # Error was flunk!
puts "Error was #{e.inspect}" # Error was #<RuntimeError: flunk!>
end
@bhb
bhb / stream.rb
Created Jan 22, 2015
Streaming data through Ruby
View stream.rb
# based on https://github.com/baweaver/streamable
# Toying around with alternatives to nested method calls
# i.e. foo(bar(baz))
# and method chaining
# i.e. baz.bar.foo
def stream(data, *methods)
methods.reduce(data) do |d, m|
case m
@bhb
bhb / stats.rb
Last active Aug 29, 2015
Compute stats for array of numbers
View stats.rb
def percentile(arr, pcent)
sorted = arr.sort
# http://en.wikipedia.org/wiki/Percentile#Linear_interpolation_between_closest_ranks
percent_ranks = (1..arr.length).map { |i| (100.0 / sorted.length) * ( i - 0.5) }
if pcent < percent_ranks.first
sorted[0]
elsif pcent > percent_ranks.last
sorted.last
@bhb
bhb / c
Created Mar 11, 2015
Copy text into clipboard
View c
#! /usr/bin/env ruby
# file: ~/bin/c
#
# usage: highlight lines and pipe them to stdout in your editor. nothing
# changes except they are copied to your paste buffer. should be modified to
# work with linux using xclip
$VERBOSE=nil
STDOUT.sync = true
View gist:fcdabe97816137cfc611
brew install opam libffi libreadline-dev
git clone git@github.com:technomancy/grenchman.git grenchman
cd grenchman
opam init (choose y to update .bash_profile or similar)
[open new shell]
opam install ocamlfind core async ctypes
ocamlbuild -use-ocamlfind -lflags -cclib,-lreadline grench.native
ln -s $PWD/grench.native ~/bin/grench
grench lein test
@bhb
bhb / translate_midje.clj
Created Mar 30, 2015
Translate Midje specs to clojure.test tests
View translate_midje.clj
;; Converts a midje test file into a clojure.test test file
;; Adapted from https://github.com/circleci/translate-midje/blob/master/translate_midje.clj
;;
;; Usage:
;; 1. Add [bultitude "0.2.6"] to project.clj
;; 2. Load this file into repl
;; 3. (require 'circleci.translate-midje)
;; 3. (circleci.translate-midje/test-rewrite "test/yourproject/test/foo_test.clj")
;;
;; It won't do everything perfectly (namely, it doesn't translate the 'provided' macro)
View secrets.repl
;; gorilla-repl.fileformat = 1
;; **
;;; # "SECRETS"* of Clojure development
;;;
;;; \* one or more tips may not be a secret to you!
;;;
;;; For months after getting started with Clojure, I understood how to write functions, but not how to **develop programs**. I did have a good grasp of the processes, idioms, and ways to structure larger code bases. As a result, I largely developed programs the same way I did with Ruby: using TDD with lots of implicit state strewn throughout my programs.
;;;
;;; I'm still learning, but I want to share a few of the key ideas I wish I had known when I first started out.
View gist:22909
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@bhb
bhb / foo.rb
Created Nov 13, 2008
undefined
View foo.rb
class Foo
def bar
puts "Hello, world!"
end
end