Skip to content

Instantly share code, notes, and snippets.

View tganzarolli's full-sized avatar

Thiago Ganzarolli tganzarolli

View GitHub Profile
@tganzarolli
tganzarolli / langton.py
Created March 4, 2019 23:03
Langton's ant
#!/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 January 20, 2014 14:25
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…
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 October 5, 2012 21:30
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by [email protected] 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 October 5, 2012 21:30
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by [email protected] 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 October 5, 2012 21:29
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by [email protected] 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 November 6, 2011 04:46 — forked from MaherSaif/.gitignore
rake deploy and rake cache_assets for Heroku (storing JS minimized and gzipped on Amazon S3)
# Add this
public/javascripts/all.js
@tganzarolli
tganzarolli / bypassable_runner.py
Created April 27, 2011 20:15
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.
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]
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)