Skip to content

Instantly share code, notes, and snippets.

View mvallebr's full-sized avatar

Marcelo Elias Del Valle mvallebr

View GitHub Profile
@mvallebr
mvallebr / array_test.py
Created September 30, 2014 13:51
array usage
resultado = []
soma = 0
a = 2
for i in range(10):
soma += a
result[i] = soma
print str(result)
import sys
convert = {1:0, 2:1, 3:1, 4:0, 5:1, 6:0, 7:1, 8:0, 9:0, 0:0}
a = [1,2,3,4,5,6,7,8,9,0]
print "Original array", str(a)
print "Converted array",
itera = (convert[key] for key in a)
for v in itera:
sys.stdout.write('%d' % v)
@mvallebr
mvallebr / postfix01.py
Created October 16, 2014 02:14
post fix expression evaluation
'''
Created on 15/10/2014
@author: mvalle
'''
import unittest
from decimal import Decimal
OPS = {
@mvallebr
mvallebr / Dijkstra01.py
Created October 16, 2014 04:07
Dijkstra01 implementation
'''
Created on 15/10/2014
@author: mvalle
'''
import unittest
from decimal import Decimal
OPS = {
@mvallebr
mvallebr / json_example001.py
Created October 18, 2014 17:45
Example showing how to read dict marshalled using str(dict) and print json
'''
Created on 18/10/2014
@author: mvalle
'''
from urllib2 import urlopen
import json
if __name__ == '__main__':
f = urlopen("https://gist.githubusercontent.com/anonymous/acbd70c0616e4225764c/raw/41e9b49faf122d346cce0b5bc12176e33874034a/gistfile1.txt")
@mvallebr
mvallebr / csv_processor.py
Last active July 5, 2018 16:20
Example of processing a CSV using several processes
#!/usr/bin/env python
'''
Created on 21/10/2014
@author: mvalle
'''
import csv
@mvallebr
mvallebr / huffman_times.scala
Last active August 29, 2015 14:08
test of manual map/reduce in scala
/*
def insert_char(char: Char, list: List[(Char, Int)]): List[(Char, Int)] = {
if (list.isEmpty)
return List((char, 1))
if (char == list.head._1)
return (char, list.head._2 + 1) :: list.tail
list.head :: insert_char(char, list.tail)
}
*/
def insert_char(char: Char, list: List[(Char, Int)]): List[(Char, Int)] = list match {
@mvallebr
mvallebr / gist:9af9a59bec3e13f6a2f6
Last active August 29, 2015 14:25
c++ instanciation problem
class Classe1 {
Classe1(int a);
};
class Classe2 {
Classe1 c1;
void do_something(Classe1 &arg) {
c1 = arg;
// do other something
}
RunArgs = namedtuple("RunArgs", ["day", "low", "high", "idx", "num"])
def build_run_args_map():
args_per_day = """
F 11265069 11420695 41 500000
F 11420695 11563706 42 500000
F 11563706 11644847 43 500000
F 11644847 11723533 44 500000
F 11723533 11797201 45 500000
F 11797201 11868330 46 500000
F 11868330 12000000 47 500000
def only_in_x_generator(x, y):
ix = 0
iy = 0
while ix < len(x) and iy < len(y):
if x[ix] < y[iy]:
yield x[ix]
ix += 1
elif x[ix] > y[iy]:
iy += 1
else: