Skip to content

Instantly share code, notes, and snippets.

View rcalsaverini's full-sized avatar

Rafael Calsaverini rcalsaverini

View GitHub Profile
@rcalsaverini
rcalsaverini / python_resources.md
Created April 3, 2014 14:20 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@rcalsaverini
rcalsaverini / strip_accents.py
Created August 30, 2014 15:05
Removing accents from unicode strings in python
import unicodedata
def strip_accents(unicode_string):
"""
Strip accents (all combining unicode characters) from a unicode string.
"""
ndf_string = unicodedata.normalize('NFD', unicode_string)
is_not_accent = lambda char: unicodedata.category(char) != 'Mn'
return ''.join(
char for char in ndf_string if is_not_accent(char)
@rcalsaverini
rcalsaverini / sample.py
Created September 1, 2014 00:28
Note to self
import pandas as pnd
import numpy as np
import numpy.random as rnd
from collections import namedtuple
class Sampler(list):
def __init__(self, items, weights=None):
super(Sampler, self).__init__(items)
@rcalsaverini
rcalsaverini / redis_lua.py
Last active August 29, 2015 14:07
Redis + Lua
import redis
import functools
from collections import namedtuple
# TODO:
# - better to implement lua methods as descriptors?
# - get lua code from *.lua files
class BaseEvaluator(object):
@rcalsaverini
rcalsaverini / sqlalchemy_join.py
Created December 4, 2014 20:27
SQLAlchemy join on composite key, can't make it work... :(
# coding=utf-8
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
# app.config['SQLALCHEMY_BINDS'] = {
# 'users': 'mysqldb://localhost/users',
# 'appmeta': 'sqlite:////path/to/appmeta.db'
# }
@rcalsaverini
rcalsaverini / proxyoff.sh
Created January 7, 2016 17:27
Scripts for turning on and off the proxy configuration.
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root";
exit 1;
fi
gsettings set org.gnome.system.proxy mode 'none' ;
grep PATH /etc/environment > lol.t;
cat lol.t > /etc/environment;
@rcalsaverini
rcalsaverini / caminhos.mkd
Last active March 12, 2016 17:27
Sugestões de caminhos para chegar ao 3º Meetup de Deep Learning na Experian.

Metrô + caminhada

Estação São Judas

Descendo na estação São Judas: https://goo.gl/maps/2CKSH3pDAhy

  • Desça na estação São Judas da linha azul do metrô, e saia da estação para o lado par da Avenida Jabaquara (ao sair pela catraca, saia pela escada rolante à sua direita).
  • Ao sair da estação siga à sua direita, no sentido bairro da Av. Jabaquara.
  • Acompanhe a avenida virando à direita e passe em frente à Paróquia de São Judas Tadeu (uma igreja bem grande).
  • Vire a direita na Av. Indianópolis.
@rcalsaverini
rcalsaverini / Scott.hs
Last active September 17, 2020 15:02
Scott encoding for lists
{-# LANGUAGE RankNTypes #-}
import Prelude hiding ((++), length)
import Control.Applicative
import Data.Foldable
newtype List a = List {
uncons :: forall r . (a -> List a -> r) -> r -> r
}
@rcalsaverini
rcalsaverini / maybe.hs
Last active January 14, 2018 11:05
Boehm-Berarducci encodings.
{-# LANGUAGE RankNTypes #-}
import Prelude hiding (Maybe, Just, Nothing, maybe)
data Maybe a = Maybe {maybe :: forall r . r -> (a -> r) -> r}
nothing = Maybe (\nothing' just' -> nothing')
just x = Maybe (\nothing' just' -> just' x)
instance (Show a) => (Show (Maybe a)) where
@rcalsaverini
rcalsaverini / keybase.md
Created May 16, 2017 01:52
keybase proof

Keybase proof

I hereby claim:

  • I am rcalsaverini on github.
  • I am rcalsaverini (https://keybase.io/rcalsaverini) on keybase.
  • I have a public key ASDKgpHzRwJySS-DBZgNtUG-KvIzPzeo_TrqQWoOduQvPgo

To claim this, I am signing this object: