Skip to content

Instantly share code, notes, and snippets.

View slezica's full-sized avatar

Santiago Lezica slezica

View GitHub Profile
@slezica
slezica / tumblr_test.py
Created May 18, 2012 05:22
tumblr test
def test():
print "testing code highlight"
@slezica
slezica / markov_1.py
Created May 19, 2012 22:52
Markov stream generator
import sys
from xiter import xiter
from collections import defaultdict
from random import random, choice
def grouped(it, group_size = 2):
buffer = [it.next() for i in xrange(group_size - 1)]
for i in it:
buffer.append(i)
@slezica
slezica / order.py
Created May 20, 2012 04:57
Automatic comparison operators in python
class Order(object):
__lt__ = lambda self, other: other > self
__gt__ = lambda self, other: not self <= other
__le__ = lambda self, other: other >= self
__ge__ = lambda self, other: not self < other
__ne__ = lambda self, other: self < other or other < self
__eq__ = lambda self, other: not self != other
@slezica
slezica / order.py
Created May 20, 2012 04:57
Automatic comparison operators in python
class Order(object):
__lt__ = lambda self, other: other > self
__gt__ = lambda self, other: not self <= other
__le__ = lambda self, other: other >= self
__ge__ = lambda self, other: not self < other
__ne__ = lambda self, other: self < other or other < self
__eq__ = lambda self, other: not self != other
@slezica
slezica / tumblr-gist.js
Created May 20, 2012 06:55
tumblr gist embedder
var real_docwrite = document.write,
body = $('body');
(function insertGists(a_tags) {
if (a_tags.length > 0) {
a_tag = a_tags.shift()
document.write = function(stylesheet) {
$('head').append(stylesheet);
@slezica
slezica / assignment_vs_setter.java
Created July 21, 2012 17:46
Java inconsistencies
// Asssignment:
a = b = c;
if (status = result());
// Standard setters:
setA(setB(c)); // No. Setters return void.
if (setStatus(result()); // And again. Impossible.
@slezica
slezica / gist:3966745
Created October 27, 2012 22:50
ejemplo got
# ============================================================================ #
# Bienvenido al país de Python! Acá todos hablan python, idioma del que vos por
# ahí no sabés nada. Pero no te preocupes: con esta guía vas a dominar las
# frases más comunes en un toque.
# Lo primero que tenés que entender es que las frases que empiezan con un '#'
# (numeral) son totalmente ignoradas en python. O sea que esta conversación que
# estamos teniendo es completamente privada: nadie en Python se está enterando.
class OrderFilterForm(Form):
name = CharField(required = False)
email = CharField(required = False)
aec = CharField(required = False)
date_created_from = DateField(required = False)
date_created_to = DateField(required = False)
def process(self):
data = lambda key: self.cleaned_data.get(key, '')
@slezica
slezica / gist:4381039
Last active December 10, 2015 04:28
Transcripts recorded during human - computer interaction.

The following transcripts were recorded during human - computer interaction.

C

Programmer: okay, give me the numbers one by one.

Computer: I don't know how to "by" "one" and "one".

P: what? Just... is there a number at the top left of the page?
@slezica
slezica / gist:6254089
Created August 16, 2013 22:37
Traducción ruby - python
# Dummy
class Redis:
def send(self, method, key, args, f):
print method, key, args, f
class Nest(str):
def __init__(self, key, redis = Redis()):
super(Nest, self).__init__(key)