Skip to content

Instantly share code, notes, and snippets.

Avatar

Thiago Ganzarolli tganzarolli

View GitHub Profile
View langton.py
#!/usr/bin/python
class Langton(object):
def __init__(self):
self.ant = ((0,0), 'E')
self.black_squares = set()
self.next = {'E':'S', 'S': 'W', 'W':'N', 'N':'E'}
self.previous = {'E':'N', 'N': 'W', 'W':'S', 'S':'E'}
self.max_y,self.max_x,self.min_y,self.min_x = 0,0,0,0
self.transf = {'E':(1,0), 'S': (0,1), 'W':(-1,0) , 'N':(0,-1)}
@tganzarolli
tganzarolli / CorsPreFlightService
Created Jan 20, 2014
A RestEasy service to return a default OK response for a CORS pre-flight request. Those requests are made when you are using CORS along with authentication headers. Using Jetty, the org.eclipse.jetty.servlets.CrossOriginFilter configured on the web.xml can take care of sending the required headers on the response. However, it does not care of re…
View CorsPreFlightService
import javax.ws.rs.OPTIONS;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.springframework.stereotype.Service;
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
@tganzarolli
tganzarolli / unicorn
Created Oct 5, 2012
/etc/init.d script for unicorn
View unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@tganzarolli
tganzarolli / unicorn
Created Oct 5, 2012
/etc/init.d script for unicorn
View unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@tganzarolli
tganzarolli / unicorn
Created Oct 5, 2012
/etc/init.d script for unicorn
View unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@tganzarolli
tganzarolli / .gitignore
Created Nov 6, 2011 — forked from MaherSaif/.gitignore
rake deploy and rake cache_assets for Heroku (storing JS minimized and gzipped on Amazon S3)
View .gitignore
# Add this
public/javascripts/all.js
@tganzarolli
tganzarolli / bypassable_runner.py
Created Apr 27, 2011
Generates a custom DjangoTestSuiteRunner that can bypassa the creation of a database instance, if the BYPASS_CREATION entry is set to yes, inside DATABASES dict.
View bypassable_runner.py
from django.test.simple import DjangoTestSuiteRunner
class ByPassableDBDjangoTestSuiteRunner(DjangoTestSuiteRunner):
def setup_databases(self, **kwargs):
from django.db import connections
old_names = []
mirrors = []
for alias in connections:
connection = connections[alias]
View auto_follow.rb
require 'rubygems'
require 'twitter'
require 'open-uri'
require 'yajl'
def auto_follow
twitter_config = ConfigStore.new("config/twitter_credentials.yml")
shortening_config = ConfigStore.new("config/url_shortening.yml")
httpauth = Twitter::HTTPAuth.new(twitter_config['email'], twitter_config['password'])
base = Twitter::Base.new(httpauth)