This file contains 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
# Run the given block +num+ times and then print out the mean, median, min, | |
# max, and stddev of the run. For example: | |
# | |
# irb> stats(10) { sleep(rand / 100) } | |
# mean: 5.99ms | |
# median: 6.76ms | |
# min: 1.49ms | |
# max: 9.28ms | |
# stddev: 2.54ms | |
def stats(num) |
This file contains 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 your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
This file contains 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
~$ ARCHFLAGS='-arch i386 -arch x86_64' | |
~$ rvm install 1.8.7 --debug --reconfigure -C --enable-shared=yes | |
~$ wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download | |
~$ tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0 | |
~/RubyCocoa-1.0.0$ ruby install.rb config --build-universal=yes | |
~/RubyCocoa-1.0.0$ ruby install.rb setup | |
~/RubyCocoa-1.0.0$ sudo ruby install.rb install |
This file contains 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
(function() { | |
var ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3'; | |
if (navigator.userAgent.indexOf(ua) === 0) { | |
document.write('<sc' + 'ript src="/js/ios3_bug.js"></sc' + 'ript>'); | |
} | |
})(); | |
// iPhone OS 3 requires an external script tag to be synchronously | |
// loaded in the HEAD od the HTML document if there's a reference |
This file contains 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
require "stateful" | |
class Folder < ActiveRecord::Base | |
include Stateful | |
# ... | |
stateful do | |
state :active | |
state :inactive |
This file contains 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
bash -c ' | |
<% if knife_config[:bootstrap_proxy] -%> | |
( | |
cat <<'EOP' | |
<%= "proxy = #{knife_config[:bootstrap_proxy]}" %> | |
EOP | |
) > ~/.curlrc | |
<% end -%> | |
if [ ! -f /usr/bin/chef-client ]; then |
This file contains 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
# Public: generates a mixable singleton implementation dependent on a model key. | |
# Once you mix it into a model, your model gains an .instance method that will | |
# generate an object and cache it. Further calls to the .instance methods will | |
# return the same object. | |
# | |
# key - The name of the attribute we use to index instances. Defaults to "id". | |
# | |
# Example | |
# | |
# # Called without arguments uses the "id" as key. |
This file contains 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
require 'minitest/unit' | |
require 'drb' | |
require 'rinda/tuplespace' | |
module MiniTest | |
class ParallelRunner < MiniTest::Unit | |
URI = 'druby://127.0.0.1:12345' | |
def _run_suites suites, type | |
hash = Hash[suites.map { |s| [s.name, s] }] |
This file contains 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
<textarea style="height: 100%; width: 100%; background: #222; padding: 5% 25%; color: #eee;"></textarea> |
This file contains 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
#!/usr/bin/env ruby | |
# | |
# USAGE: | |
# | |
# ruby -rubygems -ropen-uri -e 'eval open("http://gist.github.com/raw/473222/snippet.rb").read' jbarnette dr-nic-magic-awesome | |
# | |
# Or locally: | |
# | |
# $ show_forks jbarnette dr-nic-magic-awesome | |
# jbarnette - 2008/06/05 15:54:29 -0700 |
OlderNewer