Skip to content

Instantly share code, notes, and snippets.

View mauricioszabo's full-sized avatar

Maurício Szabo mauricioszabo

View GitHub Profile
@mauricioszabo
mauricioszabo / Unobtrusive Javascript on Rails3
Created October 20, 2010 16:41
app/views/javascript/index.html.erb
<h1>Javascript#index</h1>
<div data-update='bottom'>
Nada
</div>
<br />
<div data-update='true'>
Zero
@mauricioszabo
mauricioszabo / exemplo.html
Created November 1, 2010 18:47
Exemplo de HTML para o post http://wp.me/pF72N-33
<html>
<body>
<script src="prototype.js"></script>
<style>
.bold {
font-weight: bold;
}
</style>
<div id='pessoas'>
@mauricioszabo
mauricioszabo / parser.rb
Created March 24, 2011 19:34
Parsing de disciplinas da matrícula da UFABC. Requer a gem pdf-parser
require 'rubygems'
require 'pdf/reader'
require "re_parser"
require "yaml"
class PageTextReceiver
attr_accessor :disciplinas
def initialize
@disciplinas = ReParser.new
@mauricioszabo
mauricioszabo / gist:996323
Created May 27, 2011 22:28
Coding Dojo 27-maio-2011
main =
putStrLn (show $ trocoPara 50)
trocoPara quantia =
let todasCombinacoes = todasPossibilidades (quantia `div` (last todasMoedas)) []
in filter (\c -> (sum c) == quantia ) todasCombinacoes
todasPossibilidades num ps =
if num == 0 then ps
else concat [ (possibilidades num), (todasPossibilidades (num - 1) ps) ]
@mauricioszabo
mauricioszabo / connection_fix.rb
Created October 10, 2011 18:38 — forked from defunkt/connection_fix.rb
MySQL server has gone away fix
# 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/
...
# Restart Passenger
deploy.task :restart, :roles => :app do
...
# Restart the resque workers
run "cd #{current_path} && rake queue:restart_workers RAILS_ENV=production"
end
@mauricioszabo
mauricioszabo / privado.cpp
Created December 1, 2011 18:22
Diferenças entre "private" no Ruby e C++
//Versão em C++. Repare que quando é chamado o método "publico" numa instância da
//classe filha, ela usa a implementação tanto do método "publico" como o "privado"
//da classe pai.
//Se eu não tivesse redefinido o método "privado" na classe filha, eu teria um erro
//de compilação ao tentar acessar "privado" da classe pai. Da mesma forma, diferente
//de ruby, se eu estiver no escopo certo eu posso chamar um método privado com a
//notação this->privado()
#include <iostream>
using namespace std;
@mauricioszabo
mauricioszabo / if_true_if_false.rb
Created December 5, 2011 18:56
ifTrue implementation on Ruby
class TrueClass
def if_true
yield
self
end
def if_false
self
end
end
@mauricioszabo
mauricioszabo / gist:2220745
Created March 27, 2012 21:57
Coding Guides

CODING GUIDES

Well, there are a bunch of people making these kind of "guides", so I think it's time to make mine too...

In this guide, must and should are used to define mandatory or recomended, in that order.

Naming:

  • variable's and method's names must be in snake_case.
@mauricioszabo
mauricioszabo / gist:2580923
Created May 2, 2012 22:05 — forked from isa/gist:2571012
Convert in less than 30 lines
val list = List(
('A', 'B', 'C'),
('A', 'C', 'E'),
('E', 'F', 'D'),
('D', 'A', 'J'),
('E', 'D', 'J')
)
val expected = List(
('A', 'B', 1),