Skip to content

Instantly share code, notes, and snippets.

View jbochi's full-sized avatar

Juarez Bochi jbochi

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / pascal.py
Created November 21, 2012 23:01 — forked from hltbra/pascal.py
Pascal triangule using recursion
def print_pascal_triangle(n_lines):
for row in xrange(n_lines):
for col in xrange(row + 1):
print pascal(row, col),
print
def pascal(row, col):
if col == 0 or row == col:
return 1
@jbochi
jbochi / merge.scala
Created October 17, 2012 16:42
merge sort in scala
def msort(xs: List[Int]): List[Int] = {
val n = xs.length / 2
if (n == 0) xs
else {
def merge(xs: List[Int], ys: List[Int]): List[Int] = (xs, ys) match {
case (Nil, ys) => ys
case (xs, Nil) => xs
case (x :: xs1, y :: ys1) =>
if (x < y) x :: merge(xs1, ys)
else y :: merge(xs, ys1)
@jbochi
jbochi / compose.py
Created September 29, 2012 11:29
function composition in python
class O():
def __repr__(self):
return "<" + ' *o* '.join(map(repr, self.funs)) + ">" if self.funs else "<composer>"
def __init__(self, funs=None):
self.funs = funs if funs else []
def __rmul__(self, other):
other_funs = other.funs if isinstance(other, O) else [other]
return O(other_funs + self.funs)