Skip to content

Instantly share code, notes, and snippets.

View raphaelcosta's full-sized avatar

Raphael Costa raphaelcosta

View GitHub Profile
@akitaonrails
akitaonrails / human_gc_stats.rb
Created April 9, 2014 00:17
Just a hack to make it easier to understand GC.stat in Ruby 2.0 and 2.1 (made for a tech talk)
# This is an attempt to translate GC.stat to a more understandable format for humans
# from @samsaffron
# http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc?utm_source=rubyweekly&utm_medium=email
# http://samsaffron.com/archive/2014/04/08/ruby-2-1-garbage-collection-ready-for-production
def gc_stats
stats = GC.stat
space_count = ObjectSpace.count_objects
objects_per_heap = space_count[:TOTAL] / stats[:heap_used]
report = {
@kelvinst
kelvinst / i18n-debug.md
Last active August 29, 2015 14:10
Descobrindo as keys de i18n no rails

Descobrindo as keys de i18n no rails

Você já deve ter se pego tentando adivinhar qual key dos arquivos de tradução o rails está buscando né? Chutando as keys uma a uma pra ver se acerta? Não? Bom eu sim 😁, até que eu cansei e procurei algo pra resolver esse problema.

E adivinha só: já existe uma gem pra isso! 🎉 A gem i18n-debug resolve esse problema de uma forma bem fácil. Basta adicionar ela no Gemfile do seu projeto e ele vai começar a colocar as seguintes linhas no log do rails:

[i18n-debug] en.helpers.label.user.username => nil
[i18n-debug] en.helpers.label.user.username => nil
[i18n-debug] en.activerecord.attributes.user.username => "Username"
@rwdaigle
rwdaigle / process.ex
Last active August 29, 2015 14:23
Parallelized collection processing w/ sub-process supervision
alias Task.Supervisor
{:ok, supervisor} = Supervisor.start_link
double = fn(n) -> n*2 end
[1, 2, 3]
|> Enum.map(&Supervisor.async(supervisor, fn -> double.(&1) end))
|> Enum.map(&Task.await/1)
#=> [2, 4, 6]
# Hi! I'am rack middleware!
# I was born for show right way to you JavaScript
# My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com
# Nice to MIT you!
require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
class RoutesJs
def initialize app, options = {}
# Hi! I'am rack middleware!
# I was born for show right way to you JavaScript
# My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com
# Nice to MIT you!
require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
class RoutesJs
def initialize app, options = {}
@tomas-stefano
tomas-stefano / ruby_patch.sh
Created July 2, 2011 18:37
Ruby require 1.9.2 patch and installation
## This is how I installed ruby in my Mac ##
## Will install a ruby 1.9.2-p180-patched #
$ curl https://raw.github.com/gist/1008945/7532898172cd9f03b4c0d0db145bc2440dcbb2f6/load.patch > /tmp/load.patch
$ rvm install ruby-1.9.2-p180 --patch /tmp/load.patch -n patched
#### If you have problems with Ruby::
@croaky
croaky / gist:1089598
Created July 18, 2011 14:01
Transfer data from production to staging on Heroku
heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote production
heroku pgbackups:capture --remote production
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging
/* Mixins
================================================== */
@mixin placeholder-color($color: $grayLight) {
:-moz-placeholder { color: $color; }
::-webkit-input-placeholder { color: $color; }
}
// Border Radius
@sethbro
sethbro / test_helper.rb
Created January 13, 2012 18:19
MiniTest::Spec with Rails setup
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
require 'capybara/rails'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
@remi
remi / jekyll
Created May 12, 2012 10:31
I18n dates with Jekyll (dirty hack version)
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'jekyll' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'