Skip to content

Instantly share code, notes, and snippets.

View mauricioszabo's full-sized avatar

Maurício Szabo mauricioszabo

View GitHub Profile
@mauricioszabo
mauricioszabo / gist:9116205
Created February 20, 2014 15:24
ActiveRecord's query methods
# When you do this:
class Person < ActiveRecord::Base
end
people = Person.where(name: "Foo")
people.each do
# Do something with each row
end
# You're instantiating a relation, which includes this module:
@mauricioszabo
mauricioszabo / ScalaFutures.scala
Created May 17, 2014 13:17
Futures with Scala and Ruby
import concurrent._
import concurrent.duration._
import ExecutionContext.Implicits.global
object ScalaFutures extends App {
val fusers = findFromDB
val finternet = findFromInternet
val result = for(
list_users <- fusers;
@mauricioszabo
mauricioszabo / actor.rb
Created November 6, 2014 20:48
Akka 2.3.2 in JRuby
require 'config-1.2.0.jar'
require 'java'
require 'scala-library.jar'
require 'akka-actor_2.10-2.3.2.jar'
java_import 'akka.actor.UntypedActor'
java_import 'akka.actor.Actor'
java_import 'akka.actor.ActorRef'
java_import 'akka.actor.ActorSystem'
java_import 'akka.actor.UntypedActorFactory'
@mauricioszabo
mauricioszabo / tic_tac_toe.rb
Created November 7, 2014 12:34
Tic-Tac-Toe in TuProlog and JRuby
require_relative 'tu_prolog'
class Lib < TuProlog::RubyLibrary
def getTheory
<<-THEORY
create_board :-
member(Col, ['A', 'B', 'C']),
member(Row, ['1', '2', '3']),
asserta(board(Col, Row, ' ')).
@mauricioszabo
mauricioszabo / db_converter.py
Created April 27, 2015 19:16
Converter from mysql to pg
#!/usr/bin/env python
"""
Fixes a MySQL dump made with the right format so it can be directly
imported to a new PostgreSQL database.
Dump using:
mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root databasename
"""
@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/