Skip to content

Instantly share code, notes, and snippets.

View etagwerker's full-sized avatar
🏠
Working from home

Ernesto Tagwerker etagwerker

🏠
Working from home
View GitHub Profile
@etagwerker
etagwerker / ruby_count_indexer.rb
Created December 3, 2010 13:58
Ruby script to count words in a file and order them by occurrences
# Script to index words inside a text file.
# Words separated by spaces.
# Usage: ruby indexer.rb /path/to/file.txt
file_path = ARGV[0] || "votacion.txt"
WORDS_COUNT = {}
file = File.open(file_path, "r")
puts "Indexing #{file_path}"
@etagwerker
etagwerker / most-likely-a-rails3-bug
Created December 21, 2010 02:59
this makes no fucking sense! WTF?!
[etagwerker@bazinga current]$ rvm-prompt
ruby-1.9.2-p0
[etagwerker@bazinga current]$ gem list | grep mysql2
mysql2 (0.2.6)
[etagwerker@bazinga current]$ cat Gemfile | grep mysql2
gem 'mysql2'
[etagwerker@bazinga current]$ rails c production
/home/etagwerker/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:22:in `rescue in mysql_connection': !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' (RuntimeError)
from /home/etagwerker/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:19:in `mysql_connection'
@etagwerker
etagwerker / nginx-default
Created December 29, 2010 19:36
default configuration for nginx to work with a rails app
# This is example contains the bare mininum to get nginx going with
# Unicorn or Rainbows! servers. Generally these configuration settings
# are applicable to other HTTP application servers (and not just Ruby
# ones), so if you have one working well for proxying another app
# server, feel free to continue using it.
#
# The only setting we feel strongly about is the fail_timeout=0
# directive in the "upstream" block. max_fails=0 also has the same
# effect as fail_timeout=0 for current versions of nginx and may be
# used in its place.
@etagwerker
etagwerker / unicorn.default.rb
Created December 29, 2010 19:39
default unicorn configuration
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
worker_processes 2
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/home/deployer/myapp.com/current"
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/myapp.com.sock", :backlog => 64
listen 8080, :tcp_nopush => true
@etagwerker
etagwerker / full Ruby grep
Created February 24, 2011 05:06
how should I do a grep to work cross platform?
result = %x[grep -r 'I18n.translate(' public/*] # this won't work in Windows
system("grep -r 'I18n.t(' public/*") # this won't either
@etagwerker
etagwerker / crossplatform-grepping
Created February 25, 2011 12:29
grepping in Ruby (crossplatform)
grep_output = ""
Dir.glob("public/**/**").select {|file| File.file?(file)}.each do |file|
File.open(file, 'r').each_with_index do |line, index|
grep_output += line if line.include?('I18n.t(') || line.include?('I18n.translate(')
end
end
result = []
result += grep_output.scan(/I18n\.t\('([\w+|\.+]+)'\)/) # captures I18n.t('a.key')
result += grep_output.scan(/I18n\.translate\('([\w+|\.+]+)'\)/) # captures I18n.t('a.key')
result += grep_output.scan(/I18n\.t\(\"([\w+|\.+]+)\"\)/) # captures I18n.t("a.key")
<form accept-charset="UTF-8" action="https://checkout.dineromail.com/CheckOut" class="edit_order" id="checkout_form_confirm" method="post"><div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" />
<input name="authenticity_token" type="hidden" value="cU5BTew+4ZG7RqlwY5LDwoULnGbFkF+H/hcXNdzf5no=" /></div>
<fieldset id="order_details">
<div class="clear"></div>
<legend>Confirmar</legend>
<table class="index">
<tbody id='line-items'>
<tr>
@etagwerker
etagwerker / gist:1000770
Created May 31, 2011 16:07
DataMapper.auto_upgrade! Question
# Departamento Version 1.0
class Departamento
include DataMapper::Resource
property :id, Serial
property :nombre, String, :index => true
end
# Then I run rackup with DataMapper.auto_upgrade!, which creates the tables with the structure above.
@etagwerker
etagwerker / gist:1033187
Created June 18, 2011 15:35
Censo2010 Backbone Rewrite
window.Censo2010 = {};
$(function(){
Censo2010.CabecerasCollection = Backbone.Collection.extend({
model: Censo2010.Cabecera,
url: function() {
@etagwerker
etagwerker / seg-fault-god-rb-resque-fedora-14
Created June 27, 2011 02:01
Segmentation Fault for God-rb on Fedora 14
I [2011-06-26 21:56:53] INFO: resque-1.17.1 moved 'up' to 'start'
/usr/local/rvm/gems/ruby-1.9.2-p0/gems/god-0.11.0/lib/god/event_handler.rb:62: [BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
-- control frame ----------
c:0007 p:---- s:0018 b:0018 l:000017 d:000017 CFUNC :handle_events
c:0006 p:0012 s:0015 b:0015 l:001e2c d:000014 BLOCK /usr/local/rvm/gems/ruby-1.9.2-p0/gems/god-0.11.0/lib/god/event_handler.rb:62
c:0005 p:---- s:0011 b:0011 l:000010 d:000010 FINISH
c:0004 p:---- s:0009 b:0009 l:000008 d:000008 CFUNC :loop
c:0003 p:0009 s:0006 b:0006 l:001e2c d:000005 BLOCK /usr/local/rvm/gems/ruby-1.9.2-p0/gems/god-0.11.0/lib/god/event_handler.rb:60