Skip to content

Instantly share code, notes, and snippets.

View jbochi's full-sized avatar

Juarez Bochi jbochi

View GitHub Profile
@jbochi
jbochi / partial.py
Created November 21, 2012 23:30
exemplo de partial
#from functools import partial
def partial(funcao, argumento):
def fn(arg):
return funcao(argumento, arg)
return fn
def to_tag(tag, texto):
return "<{tag}>{texto}</{tag}>".format(tag=tag, texto=texto)
negrito = partial(to_tag, 'b')
@jbochi
jbochi / coins.py
Created November 21, 2012 23:30
Dá troco
def change(n, coins):
if n == 0:
return 1
elif n < 0 or len(coins) == 0:
return 0
else:
return change(n, coins[1:]) + change(n - coins[0], coins)
print change(10, [10, 5, 2, 1])
@jbochi
jbochi / naturais.py
Created November 21, 2012 23:45
Representação de números naturais
class Natural(object):
def __init__(self, anterior):
self.anterior = anterior
def __str__(self):
return str(self.anterior) + " + 1"
def __add__(self, other):
return self.anterior + other.sucessor()
@jbochi
jbochi / lazy.py
Created November 22, 2012 00:11
lazy
def ifilter(funcao, seq):
for x in seq:
if funcao(x):
yield x
def take(seq, n):
i = 0
for x in seq:
if i < n:
@jbochi
jbochi / collisions.html
Created February 25, 2013 01:35
Molecular Dynamics Simulation of Hard Spheres
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='/js/lib/dummy.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
@jbochi
jbochi / queue.r
Last active December 17, 2015 13:19
Queueing system with n parallel servers
PriorityQueue <- function() {
keys <<- values <<- NULL
insert <- function(key, value) {
temp <- c(keys, key)
ord <- order(temp)
keys <<- temp[ord]
values <<- c(values, list(value))[ord]
}
pop <- function() {
key <- keys[[1]]
@jbochi
jbochi / analysis.R
Last active December 18, 2015 23:48
Exponencial Random Graph Model for Facebook friends
# http://badhessian.org/2012/09/lessons-on-exponential-random-graph-modeling-from-greys-anatomy-hook-ups/
library(ergm)
path <- "/Users/juarez.bochi/Dropbox/mestrado/inf2035/Random Graphs/fbergm"
friends_path <- paste(path, "friends_manual.tsv", sep="/")
relationships_path <- paste(path, "relationships.tsv", sep="/")
friends <- read.table(friends_path, sep="\t", header=T, stringsAsFactors=F, strip.white=F, as.is=T)
@jbochi
jbochi / slow.py
Created July 5, 2013 19:52
slow pipe
import sys
import time
delay = float(sys.argv[1])
for line in sys.stdin:
sys.stdout.write(line)
time.sleep(delay)
@jbochi
jbochi / monitor.py
Created July 9, 2013 16:25
Script to monitor an URL for changes
import urllib
from time import sleep
from hashlib import md5
import sys
def bell():
sys.stdout.write('\a')
sys.stdout.flush()
def dig():
Port 8081
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon
<Feed feed.ffm>
file /tmp/feed.ffm
FileMaxSize 20M
</Feed>