Skip to content

Instantly share code, notes, and snippets.

View mauricioszabo's full-sized avatar

Maurício Szabo mauricioszabo

View GitHub Profile
@mauricioszabo
mauricioszabo / monads.clj
Last active June 15, 2023 14:46
Monads with Clojure
(ns monads)
(defn- ensure-instance [class val constructor]
(if (instance? class val)
val
(constructor val)))
(defprotocol IMonad
(bind [this f]))
@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 / 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 / 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 / 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 / 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 / gist:2580938
Created May 2, 2012 22:09 — forked from isa/gist:2571012
Convert in less than 30 lines
val before = List(
List('A', 'B', 'C'),
List('A', 'C', 'E'),
List('E', 'F', 'D'),
List('D', 'A', 'J'),
List('E', 'D', 'J')
)
val expected = List(
List('A', 'B', 1),
@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),
@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 / 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