Skip to content

Instantly share code, notes, and snippets.

@joakimk
joakimk / gist:1135095
Created Aug 9, 2011
Script to install GCC toolchain on OSX lion
View gist:1135095
curl http://cloud.github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7.pkg > /tmp/GCC-10.7.pkg &&
sudo installer -pkg /tmp/GCC-10.7.pkg -target /
@joakimk
joakimk / Example of output
Created Aug 21, 2011
Rake task for cleaner output when deploying with capistrano
View Example of output
$ rake deploy
> Executing deploy
> Executing deploy:update
> Executing deploy:update_code
> Executing deploy:finalize_update
> Executing bundle:install
> Executing link_config
> Executing link_files
> Executing build_assets
> Executing deploy:symlink
@joakimk
joakimk / gist:1185872
Created Sep 1, 2011 — forked from metaskills/gist:1124322
Patch Ruby 1.9.3.preview1 GC Tuning Noise
View gist:1185872
diff --git a/gc.c b/gc.c
--- a/gc.c
+++ b/gc.c
@@ -416,7 +416,6 @@
malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
if (malloc_limit_ptr != NULL) {
int malloc_limit_i = atoi(malloc_limit_ptr);
- printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit);
if (malloc_limit_i > 0) {
initial_malloc_limit = malloc_limit_i;
@joakimk
joakimk / migrate_with_annotation.rake
Created Sep 7, 2011
Script to automatically annotate models after db:migrate is run.
View migrate_with_annotation.rake
# Used with:
# gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
if Rails.env.development?
def after_task(task_name, &new_task)
old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
desc old_task.full_comment
task task_name do
old_task.invoke
new_task.call
@joakimk
joakimk / gist:1261080
Created Oct 4, 2011
Unit test results
View gist:1261080
......................................
Finished in 0.03768 seconds
38 examples, 0 failures
real 0m0.386s
user 0m0.344s
sys 0m0.038s
Later on...
View gist:1278898
class CPU
def self.current_usage
process_usages = `ps -eo pcpu`
total_usage = process_usages.split("\n").inject(0) { |sum, usage| sum += usage.strip.to_f }
(total_usage / count).to_i
end
def self.count
case RUBY_PLATFORM
@joakimk
joakimk / example_output.txt
Created Jan 11, 2012 — forked from henrik/example_output.txt
Ruby on Rails initializer to log Savon SOAP XML as pretty JSON instead. Also show what line of code called it.
View example_output.txt
--------------------------------------------------
lib/foo.rb:22:in `save'
# foo.book
>> REQUEST:
{
"CashBook_Book": {
"cashBookHandle": {
"Number": "14"
@joakimk
joakimk / gist:1628294
Created Jan 17, 2012
Economic API-client experiment
View gist:1628294
require 'rubygems'
require 'savon'
require 'active_support'
require 'active_support/core_ext'
require 'json'
# Don't mention the adapter!
HTTPI.log = false
# Log pretty JSON instead of XML, and never mind URL and headers.
@joakimk
joakimk / graphite.rb
Created Jan 25, 2012
Graphite client for ruby with specs
View graphite.rb
require 'socket'
class Graphite
def initialize(host)
@host = host
end
def socket
return @socket if @socket && !@socket.closed?
@socket = TCPSocket.new(@host, 2003)
@joakimk
joakimk / spec_helper.rb
Created Jan 26, 2012
Load path optimizations to use gems in sub-second test suites
View spec_helper.rb
def add_load_path(path)
full_path = "#{ENV["HOME"]}/.rvm/gems/ruby-version@project/#{path}"
raise("load path missing: #{full_path}") unless File.exists?(full_path)
$: << full_path
end
rails_version = File.readlines(File.join(File.dirname(__FILE__), "../../Gemfile")).
find { |line| line.include?("'rails'") }.split.last.gsub("'",'')
add_load_path "bundler/gems/draper-version/lib"