Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python2
# encoding: utf-8
# Decoding: https://twitter.com/diegoboot/status/510846108973953024
bins = [
'01001000', '01100001', '01110000',
'01110000', '01111001', '00100000',
'01010000', '01110010', '01101111',
'01100111', '01110010', '01100001',
@magnunleno
magnunleno / hex-cairo.py
Last active December 25, 2015 03:09
Script that draws Hexagons with Python and Cairo
#!/usr/bin/env python
# encoding: utf-8
import cairo
import rsvg
import math
WIDTH, HEIGHT = (500, 500)
HEX_W, HEX_H = (50, 50)
{{extend 'layout.html'}}
<h1>Clientes</h1>
<div id='contents'>
<table class="table">
<tr>
<th>ID</th>
<th>Cliente</th>
@magnunleno
magnunleno / geraCPF.py
Created July 29, 2013 22:45
Gerador de CPF para ser utilizado em bases de teste :)
#!/usr/bin/env python
# encoding: utf-8
import sys
from random import random
def geraCPF():
cpf = []
for i in range(9):
cpf.append(int(random()*10))
#!/usr/bin/env python
# encoding: utf-8
import cProfile
class singledispatch(object):
__slots__ = (
'resolver',
'default',
'last',
#!/usr/bin/env python2
# encoding: utf-8
class singledispatch(object):
__slots__ = (
'resolver',
'default',
'last',
)
def __init__(self, func):
#!/usr/bin/env python2
# encoding: utf-8
import subprocess
def __get_output(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
output = process.communicate()
retcode = process.poll()
if retcode == 0:
@magnunleno
magnunleno / ProcessaApp.java
Created October 25, 2012 17:10
Processamento XML (Java vs. Python vs. C)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.util.ArrayList;
import java.util.logging.Logger;
@magnunleno
magnunleno / build_static_simple.sh
Created September 27, 2012 21:35
Exemplo de biblioteca estática em C
echo "Cleaning build dir..."
rm build/*
echo
echo "Compiling files"
gcc -c lib/myprint.c -o build/myprint.o
echo
echo "Building lib archive"
ar rcs build/libmyprint.a build/myprint.o
@magnunleno
magnunleno / overlaping-bars.py
Created September 9, 2012 18:34
Overlaping Horizontal Bars Plotting example - built with Python+Cairo
#!/usr/bin/env python
# encoding: utf-8
# Python plotting "module" based in the graph found here:
# http://www.techdrivein.com/2012/09/chrome-overtakes-ie-to-become-worlds.html
#
# License: GPLv3
# Credits: Magnun Leno (@mind_bend)
# Site: http://www.mindbending.org