Skip to content

Instantly share code, notes, and snippets.

View alvesjnr's full-sized avatar

Antonio Ribeiro Alves alvesjnr

View GitHub Profile
@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 = {}
@alvesjnr
alvesjnr / mapreduce.py
Created June 21, 2011 20:28
Second mapreduce for counting: separated blocks
#coding: utf-8
from multiprocessing.pool import ThreadPool
def mapping(value):
return [(word,1) for word in value]
def reducing(list_maps):
@alvesjnr
alvesjnr / callback_couters.js
Created June 30, 2011 19:03
Callback Counters
var counter = 2;
fs.readFile(__filename, onRead);
fs.readFile("/etc/passwd", onRead);
function onRead(err, content) {
if (err) throw err;
// Do something with content
counter--;
if (counter === 0) done();
typedef struct {
char key[8];
void *value;
} BIWord;
//HOW TO USE IT IN OTHER SOURCECODE FILE?
BIWord word[10] = { {"_add", &_add},
{"_dup", &_dup}
};
@alvesjnr
alvesjnr / RangedDAtaStructur.py
Created July 11, 2011 20:53
A ranged data structure
class RangedDataStructure(object):
internal_elements = []
class ParseError(BaseException):
"""Parser Error"""
class Element(object):
def __init__(self, initial, finish, open_i, open_f, value):
self.initial = initial
Interval structure
Implement an efficient data structure for storing keys in intervals
mapping to values. The interval is defined as a 2-tuple: {low, high}.
When creating a new map the user can choose if the interval is open or
closed, in both ends.
Eg. given the left-closed, right-open map M=
[1, 10) -> a
[10, 20) -> b
@alvesjnr
alvesjnr / rgb.erl
Created July 19, 2011 13:18
Rgb marshall and unmarshell
-module(rgb).
-export([marshall/3, unmarshall/1]).
marshall(R,G,B) ->
if
R > 31 ->
throw({overlimit, R});
G > 63 ->
throw({overlimit, G});
B > 31 ->
#include <iostream>
class Base
{
public:
int value;
virtual int get_value_plus_one();
};
class Derived: public Base
search_filters = ([k.replace('__exact', ''),humanize_search_values(k, v)] for k, v in filters.items() if v)
class Schema(colander.Schema):
title = colander.SchemaNode(
colander.String(),
title='Book Title',
description='Book title without abbreviations',
)
schema = Schema()
form = deform.Form(schema)
form.render({'title':None}) # It is rendering a text field with the string None as content