Skip to content

Instantly share code, notes, and snippets.

View alvesjnr's full-sized avatar

Antonio Ribeiro Alves alvesjnr

View GitHub Profile
# -*- coding: utf-8 -*-
__author__ = "Antonio Ribeiro Alves Júnior"
__date__ = "Sept/2010"
__license__ = "Creative Commons"
__contact__ = "alvesjunior.antonio [at] gmail [dot] com"
class Serial:
def create_stream(self,frase):
"""Cria o stream serial binário para uma determinada cadeia de caracteres de entrada"""
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = "Antonio Ribeiro Alves Júnior"
__date__ = "Sept/2010"
__license__ = "Creative Commons"
__contact__ = "alvesjunior.antonio [at] gmail [dot] com"
class Serial:
def __init__(self,parity=0,start=1,stop=1):
self.parity = parity
/**
License: Creative Comons
Author: Antonio Ribeiro Alves júnior
**/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int *primo(int v)
from isisdm.mapper import Document
from isisdm.mapper import TextField, NumberField, DateTimeField
class Livro(Document)
titulo = TextField(required=True, repeatable=True)
data = DateTimeField()
total_paginas = NumberField()
@alvesjnr
alvesjnr / couch_attach.py
Created April 27, 2011 16:41
Attaching files in couchdb with couchdbkit
#Example: attaching file using couchdbkit
import couchdbkit
f = open('/tmp/file') #it works if you have a file with this name dude!
doc = {'text':'My Attachment'}
s = couchdbkit.Server()
db = s.get_or_create_db('blah')
@alvesjnr
alvesjnr / blogpost.py
Created May 14, 2011 23:37
My blogpost at assemblando.com
def fibo(n):
if n==0 or n==1:
return n
else:
return fibo(n-1)+fibo(n-2)
def fibo2(n):
if n==0 or n==1:
return n
n -= 1
@alvesjnr
alvesjnr / MyList.py
Created May 18, 2011 13:17
List wich accept & operator
class MyList(list):
def __and__(self, other):
op = str(bin(other)[2:])
op = op.zfill(len(self))[::-1]
acc = []
for count,i in enumerate(op):
if int(i):
acc.append(self[count])
return acc
@alvesjnr
alvesjnr / sqlalchemy_many_to_many.py
Created June 6, 2011 17:30
Second example usign sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker
engine = create_engine('sqlite:///:memory:', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
metadata = MetaData()
Base = declarative_base()
@alvesjnr
alvesjnr / mapreduceconcepts.py
Created June 20, 2011 20:12
Introducing mapreduce concptes
#coding: utf-8
text = """No te amo como si fueras rosa de sal, topacio
o flecha de claveles que propagan el fuego
te amo como se aman ciertas cosas oscuras,
secretamente, entre la sombra y el alma.
Te amo como la planta que no florece y lleva
dentro de sí, escondida, la luz de aquellas flores,
y gracias a tu amor vive oscuro en mi cuerpo
el apretado aroma que ascendió de la tierra.
@alvesjnr
alvesjnr / mapreduce.py
Created June 21, 2011 13:30
Firt try: mapreduce for counting
#coding: utf-8
def map(key, value):
for word in value:
yield (word,1)
def reduce(list_maps):
reduced = {}