Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
@juanplopes
juanplopes / convexhull01.html
Last active August 29, 2015 13:56
Revised @ElemarJR's Convex Hull (using Monotone Chain)
<!doctype html>
<html>
<head>
<title>ConvexHull 01</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
@juanplopes
juanplopes / gist:178060e556e68421a8c5
Last active August 29, 2015 14:02
Ford-Fulkerson example for presentation: http://goo.gl/DizfF7
from collections import defaultdict
def add(network, a, b, capacity):
network[a][b] = network[b][a] = capacity
def send(network, a, b, V, minimum=1000000):
V.add(a)
if a == b:
print '-> path', a
return minimum
import logging
import sys
from graph import *
from residual import *
from dijkstras import Dijkstra
first_from_set = lambda s: list(s)[0]
excess_criteria = lambda x: x.supply > 0
deficit_criteria = lambda x: x.supply < 0
@juanplopes
juanplopes / pave.md
Last active August 29, 2015 14:05
Candidato, é pavê ou pra comê? (texto de @kramercarlos)

Texto criado pelo amigo Carlos Krämer (github . twitter . facebook) lá no Facebook, reproduzido aqui com a permissão dele.

Jornalista: Candidato, é pavê ou pra comê?

Dilma: Veja bem, nunca foi tanto pra comê quanto no meu governo. Há um ditado.... eu digo, editaram quando eu era o cachorro atrás de uma criança ... que diz que todo mundo que insere, ou melhor, ingere o que é pavê, tem uma satisfação imensa de... como dizem... dobrar a esquina. Mas nós precisamos continuar mudando, meu governo foi ótimo, eu fui eleita para dar prosseguimento ao governo Lula, Lula, LULA. Mas ninguém está mais insatisfeita com ele, digo, com o governo, não com o Lula, do que eu, mas os pessimistas é que estão tornando tudo ruim.

Marina: Eu não acho que é pavê nem pra comê. Nós precisamos aprender a reunir o que é bom em tudo, as melhores

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Net;
namespace ConsoleApplication8
from unittest import TestCase, main
import math
class TestNumerosTriangulares(TestCase):
def test_numero_28_deve_ter_5_divisores(self):
"""docstring for test_numero_28_deve_ter_5_divisores"""
self.assertEquals(primeiro_numero_triangular_com(divisores=5), 28)
def test_numero_x_deve_ter_500_divisores(self):
"""docstring for test_numero_x_deve_ter_500_divisores"""
@juanplopes
juanplopes / gist:6553969
Created September 13, 2013 17:59
Script em Python para gerar um ~/.m2/settings.xml com token de acesso a repositório no GitHub.
#!/usr/bin/env python
import httplib, getpass, base64, json, datetime, sys, xml.etree.ElementTree as ET, os.path as path, os
KEY = 'your-private-repo'
NS = {'n':'http://maven.apache.org/SETTINGS/1.0.0'}
def make_auth(username, password):
return base64.b64encode('{}:{}'.format(username, password))
def make_token(repokey, username, password):
@juanplopes
juanplopes / Main.java
Created January 22, 2014 13:41
Using Count-Min Sketch to find stream's quantiles with small memory footprint.
QuantileSketch sketch = new QuantileSketch();
for (int i = 0; i < 100000000; i++) {
double x1 = Math.random();
double x2 = Math.random();
//random normal distribution with mean=0 and stdev=1
sketch.offer(abs(sqrt(-2 * log(x1)) * cos(2 * Math.PI * x2)));
}
for (int i = 0; i <= 100; i++) {
@briandealwis
briandealwis / gist:782862
Created January 17, 2011 13:55 — forked from spullara/gist:782523
One-liner to turn jar with Main-Class into executable shell script
# turn a jar with a Main-Class into a stand alone executable
(echo '#!/usr/bin/env java -jar'; cat blahblah.jar) > blah
# turn a jar with a particular main clas into a stand alone executable
(echo '#!/usr/bin/env java -jar package.MainClass'; cat blahblah.jar) > blah
import static java.lang.System.exit;
import static java.lang.System.out;
public class Dafuq {
/**
* This does not do what you think it does.
* <p>
* You think code is documentation? No! Documentation is code!
\u002a\u002f