Skip to content

Instantly share code, notes, and snippets.

View alvesjnr's full-sized avatar

Antonio Ribeiro Alves alvesjnr

View GitHub Profile
class Obj:
def _validate(self):
raise NotImplemented("The object %s has not an implemented validation function." % self)
def dump(self):
return {} #some valid dictionary
@classmethod
def load1(cls, dct):
@alvesjnr
alvesjnr / tosm.py
Created May 16, 2012 08:35
Tinny object to structure modeller example of use
"""
tOSM - tinny object to structure modeller
example of use
"""
import tosm as t
class Contacts(t.Obj):
persons = t.ObjListProperty(obj=Person)
@alvesjnr
alvesjnr / gist:2507743
Created April 27, 2012 09:20
My languages ranking

My personal programming Languages ranking

This is my programming languages rankings. I created three different categories:

  • Mastery: How much I know about the language
  • Tasty: How much I like to use the language
  • Respect: How much I respect the language
@alvesjnr
alvesjnr / sena.py
Created April 26, 2012 11:59
Quantos sorteios para você ganhar na mega sena?
import random
my_numbers = set(random.sample(xrange(1,61),6))
if __name__ == '__main__':
count = 1
while my_numbers != set(random.sample(xrange(1,61),6)):
count += 1
print count
@alvesjnr
alvesjnr / crap.c
Created April 5, 2012 14:51
Gosh, NEVER do codes like that!
/*
NOTE: Partially translated from portuguese to english
Menu:
Sandwich Code Price
Hot Dog 100 1,20
Bauru 101 1,30
Bauru with egg 102 1,50
Hamburger 103 1,20
Cheeseburguer 104 1,30

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@alvesjnr
alvesjnr / Espirografo.md
Created March 1, 2012 10:17
How does an spirograph work?

How does an spirograph work?

Some of you shall ask yourselves: "How does a spirograph work?". But I'm sure that most of you would ask me: "What the wacko is an spirograph?"

An spirograph is a toy used to draw "weird spirals" using two circles (one inside other). For whom doesn't remember, the toy is these one:

Espirografo

The way that this toy works is simples: One gear spins inside a big circle (also with gears!). The pen is placed in a hole of the gear. When you spin the gear through the major circle, the pen follows tho different movements: An circle movement made by the gear around the center of the great circle (let's call this point as O) and a movement made by the pen around the center of the gear (let's call the center of the gear as C and the point where the pen is placed as P). As the center of the gear is moving, the result position of the point P is the sum of these two movements: P over C

Como os Espirógrafos Funcionam?

Alguns de vocês devem se perguntar: "Como os espirógrafos funcionam?". Mas a maioria de vocês perguntaria antes "espiro-o-que??".

Bem, espirógrafo é aquele brinquedo que muitos de nós usamos quando pequenos para fazer umas "espirais malucas" desenhadas no papel. O brinquedo é esse aí:

Espirografo

@alvesjnr
alvesjnr / Espirógrafo.md
Created February 29, 2012 15:11
How does a spirograph works?

Como os Espirógrafos Funcionam?

Alguns de vocês devem se perguntar: "Como os espirógrafos funcionam?". Mas a maioria de vocês perguntaria antes "espiro-o-que??".

Bem, espirógrafo é aquele brinquedo que muitos de nós usamos quando pequenos para fazer umas "espirais malucas" desenhadas no papel. O brinquedo é esse aí:

Espirografo

A mecânica do brinquedo é bem simples: uma roda dentada gira dentro de um círculo (também dentado). Sua caneta, que está presa em um orifíco da roda dentada acompanha dois movimentos distintos que são somados: o movimento circular em torno do ponto central do grande cículo (vamos chamar este ponto de O) e um movimento circular em torno do centro da roda dentada (vamos chamar o centro da roda dentada de C). Este centro, por sua vez, está em movimento. É a soma destes dois movimentos que faz surgir aqueles "desenhos muito doidos de São Tomé".

#I'm using python 2.7.2
>>> def a(b=[]):
... b.append('end')
... return b
...
>>> a()
['end']
>>> a()
['end', 'end']