Skip to content

Instantly share code, notes, and snippets.

View maraca's full-sized avatar

Martin Cozzi maraca

View GitHub Profile
#!/usr/bin/python2.6
import random
values = range(0, 1000000)
customers = []
unpaid_customers = []
# generate a bunch of random values between 0 - 1000
for value in values:
#!/usr/bin/python2.6
import random
values = range(0, 1000000)
customers = []
unpaid_customers = []
# generate a bunch of random values between 0 - 1000
for value in values:
@maraca
maraca / generator.py
Created April 13, 2011 22:35
Generators in python
#!/usr/bin/python2.6
import random
# yields a random customer id
def random_generator(percentage):
for customer in xrange(1000000):
if random.randrange(0, 100, 1) < percentage:
yield customer
@maraca
maraca / gist:1083737
Created July 14, 2011 23:43
Dijkstra in Q
/* dijkstra.q: Dijkstra's shortest path algorithm 10-21-01 AG */
import bag, dict, graph;
public dijkstra G S T;
private search G S T ST, search2 G S T ND ST;
private queue DIST, head Q, rmhead Q, change Q N D1 D2;
@maraca
maraca / gist:1094164
Created July 20, 2011 01:40
Algo to parse periods of time.
#!/usr/bin/python2.6
import datetime
dates = [
datetime.date(2011, 01, 01),
datetime.date(2011, 01, 11),
datetime.date(2011, 01, 15),
datetime.date(2011, 01, 25),
datetime.date(2011, 01, 30),
@maraca
maraca / gist:1096231
Created July 21, 2011 00:12
Coding in French
#!/utilisateur/bin/frython
@privé
le debut class (ma variable)
le debut init(moi)
imprime 'Bonjour Monde'
le fin
le fin
@maraca
maraca / gist:1127145
Created August 5, 2011 08:48
Fun with Cassandra
time ./scripts/cassamine.py > record.txt
Traceback (most recent call last):
File "./scripts/cassamine.py", line 32, in <module>
main()
File "./scripts/cassamine.py", line 24, in main
'sha1': gen_hash(word, 'sha1'), })
File "/usr/local/lib/python2.6/dist-packages/pycassa/columnfamily.py", line 755, in insert
write_consistency_level=write_consistency_level)
File "/usr/local/lib/python2.6/dist-packages/pycassa/columnfamily.py", line 773, in batch_insert
batch.send()
def arr_leader(values):
storage = {}
max_sum_key = values[0]
max_sum_val = 1
for i in values:
if storage.get(i) is None:
storage[i] = 0
storage[i] += 1
# stores the current highest sum
@maraca
maraca / main.py
Created October 22, 2011 12:07
Unique QR codes w/ hash of current timestamp
#!/usr/bin/python2.7
__author__ = "[email protected]"
import hashlib
import os
import qrcode
import time
A woman in a hot air balloon realized she was lost. She reduced
altitude and spotted a man below. Shee decended a bit more and
shouted: 'Excuse me, can you help me? I promised a friend I would meet
him an hour ago but I dont know where I am.'
The man below replied, 'You are in a hot air ballon hovering
approximately 30 feet above the ground. You are between 40 and 41
degrees North latitude and between 59 and 60 degrees west longtitude.'
'You must be an Engineer,' said the balloonist.
'I am' replied the man, 'How did you know.'
'Well'; answered the balloonist, 'everything you have told me is