Skip to content

Instantly share code, notes, and snippets.

View mgdelacroix's full-sized avatar
🎧
Working from home

Miguel de la Cruz mgdelacroix

🎧
Working from home
View GitHub Profile
@mgdelacroix
mgdelacroix / decorator_with_arguments.py
Last active August 29, 2015 14:07
Basic example of a python decorator with arguments applied to a class method
def log(log_name):
def decorator(func):
def inner(self, nombre):
print("[%s] Logging a call to %s" % (log_name, func.__name__))
return func(self, nombre)
return inner
return decorator
class Persona:
graph = {
("A", "yes"): "B",
("A", "no"): "C",
}
accepted_states = ("B", "C")
transitions = {
@mgdelacroix
mgdelacroix / gogs.conf
Created September 11, 2014 16:34
gogs supervisor file
[program:gogs]
command=/home/<GOGS-USER>/gogs/gogs web
autostart=true
user=<GOGS-USER>
directory=/home/<GOGS-USER>/gogs
environment=HOME="/home/<GOGS-USER>",USER="<GOGS-USER>"
@mgdelacroix
mgdelacroix / fate_roll.py
Created August 16, 2014 11:00
A simple python script to calculate a FATE dice roll http://www.evilhat.com/home/fate-core/
import random
from functools import reduce
def to_fate(result):
if result < 3:
return '-'
elif result < 5:
return ' '
else:
return '+'
@mgdelacroix
mgdelacroix / SqlTest.groovy
Created July 16, 2014 12:18
Groovy simple sql test
@GrabConfig(systemClassLoader=true)
@Grab('com.h2database:h2:1.4.180')
import groovy.sql.Sql
Sql sql = Sql.newInstance("jdbc:h2:/tmp/devDb", 'sa', '')
println "=================== TEST CONTENT"
println '>> You can invoke this script with two args to insert into test table (id, name)'
println '>> You can invoke this script with the argument CREATE or DESTROY to create or destroy the test table'
@mgdelacroix
mgdelacroix / SimpleEitherScript.groovy
Last active August 29, 2015 14:03
Either and fmap simple (and not formal) implementation
enum EitherStatus {
LEFT, RIGHT
}
class Either {
EitherStatus status = EitherStatus.RIGHT
Map data
String toString() {
return "[${this.status}] > ${this.data}"
@mgdelacroix
mgdelacroix / client.groovy
Created May 20, 2014 13:02
Simple Groovy client-server comunication
def socket = new Socket('localhost', 5000)
socket.withStreams { input, output ->
println input.newReader().readLine()
output << 'Imma socket'
}
@mgdelacroix
mgdelacroix / autoloading.rb
Created April 13, 2014 17:57
Autoloading for rails 4 lib folder
# In config/application.rb
config.watchable_dirs['lib'] = [:rb]
# When requiring something, use require_dependency
# To use lib/myclass.rb
require_dependency 'myclass'
@mgdelacroix
mgdelacroix / basic-handler.groovy
Created March 31, 2014 17:15
Basic Ratpack application with a handler
@Grab("io.ratpack:ratpack-groovy:0.9.2")
import static ratpack.groovy.Groovy.*
import ratpack.handling.Handler
import ratpack.handling.Context
ratpack {
handlers {
get new TestHandler()
}
}
@mgdelacroix
mgdelacroix / handler-insert-test.groovy
Created March 31, 2014 13:01
Testing the Ratpack handler chain
@Grab("io.ratpack:ratpack-groovy:0.9.2")
import static ratpack.groovy.Groovy.*
import ratpack.handling.Handler
import ratpack.handling.Context
import static groovy.json.JsonOutput.toJson
import static ratpack.registry.Registries.registry
ratpack {