Skip to content

Instantly share code, notes, and snippets.

View rodrigotassinari's full-sized avatar

Rodrigo Tassinari de Oliveira rodrigotassinari

View GitHub Profile
@PetrKaleta
PetrKaleta / Rakefile
Last active August 29, 2015 14:01
Heroku deploy rake tasks with hooks. Demonstrates how to trigger Sidekiq to quiet or terminate via API before deploy
# List of environments and their heroku git remotes (id: 'remote_name')
HEROKU_ENVIRONMENTS = {
staging: 'staging-remote-name',
production: 'production-remote-name'
}
namespace :deploy do
# Create rake tasks to deploy on Heroku environments
# $ rake -T deploy
# rake deploy:production # Deploy to production
#!/usr/bin/env ruby
command = '/opt/ruby-enterprise-1.8.6-20080810/bin/passenger-memory-stats'
memory_limit = 200 # megabytes
def running?(pid)
begin
return Process.getpgid(pid) != -1
rescue Errno::ESRCH
return false
export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=1000000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_HEAP_FREE_MIN=500000
@cowboyd
cowboyd / allruby.rb
Created January 17, 2011 19:36
Proof of concept for making all ruby available to javascript.
require 'v8'
require 'openssl'
class Module
def [](name)
self.const_get(name)
end
end
@justinfrench
justinfrench / gist:999715
Created May 31, 2011 01:12
Did you know you can pass classes into Rails tag helpers as Arrays?
# Let's say you've programatically built up an array of classes for a HTML element:
my_classes = [:a, :b, 'c']
# Don't do this, join(" ") is for chumps:
<% content_tag(:p, "Foo", :class => my_classes.join(" ")) %>
# Winners do this:
<% content_tag(:p, "Foo", :class => my_classes) %>
# => <p class="a b c">Foo</p>
<% link_to("Foo", foos_path, :class => my_classes) %>
@justinfrench
justinfrench / gist:999731
Created May 31, 2011 01:27
Did you know there's a less painful way to do data attributes in Rails?
# This has very little win:
<%= content_tag(:p, "Foo", "data-bah" => "...", "data-baz" => "...") %>
# Some chumps make it even more noisy:
<%= content_tag(:p, "Foo", :"data-bah" => "...", :"data-baz" => "...") %>
# I was going to patch Rails to convert :data_bah to "data-bah"
<%= content_tag(:p, "Foo", :data_bah => "...", :data_baz => "...") %>
# But they already do this:
@rodrigotassinari
rodrigotassinari / gist:1078666
Created July 12, 2011 18:47 — forked from sagmor/gist:1041943
Patched Ruby 1.9.2 for faster load and GC
# Ruby 1.9 Fast require:
# https://gist.github.com/1008945
curl https://raw.github.com/gist/1008945/7532898172cd9f03b4c0d0db145bc2440dcbb2f6/load.patch > load.patch
# Ruby 1.9.2 GC Patch:
# https://gist.github.com/856296
curl https://raw.github.com/gist/856296/a19ac26fe7412ef398bd9f57e61f06fef1f186fe/patch-1.9.2-gc.patch > gc.patch
rvm install 1.9.2-p180 --patch load.patch,gc.patch -n loadgc
rm gc.patch load.patch
###
# Read in XML as a stream, write out JSON as a stream. As little information
# is kept in memory as possible.
require 'nokogiri'
require 'psych'
class JSONTranslator < Nokogiri::XML::SAX::Document
attr_reader :emitter
def initialize emitter
@freshtonic
freshtonic / gist:1390291
Created November 24, 2011 00:00
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
 Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
# Rspec formatter by RAFAELDX7
# Use: rspec --require "dx7_formatter.rb" --format Dx7Formatter -- ./spec/your_spec.rb
require 'rspec/core/formatters/base_text_formatter'
class Dx7Formatter < RSpec::Core::Formatters::BaseTextFormatter
def index
@index ||= -1
@index += 1