Skip to content

Instantly share code, notes, and snippets.

View alvesjnr's full-sized avatar

Antonio Ribeiro Alves alvesjnr

View GitHub Profile
(import [random [shuffle]])
(defn quick [s]
(if (len s)
(+ (quick (list-comp x [x s] (< x (first s)) ))
[(first s)]
(quick (list-comp x [x s] (> x (first s)) ))
)
[]
)
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@alvesjnr
alvesjnr / blah.py
Last active December 26, 2015 04:59
# using python 2.7
class A(object):
value = 10
class B(A):
other_value = 11
def _get_pythonpath(self):
if os.name == 'nt':
p = subprocess.Popen(["set",], shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.split():
if line.startswith("PYTHONPATH"):
return line.split()[1]
else:
p = subprocess.Popen(["echo", "$PYTHONPATH"], shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
try:
#py 2.x
from Tkinter import *
except ImportError:
#py 3.x
from tkinter import *
app = Tk()
@alvesjnr
alvesjnr / trie.py
Created January 31, 2013 16:56
Naive Trie implementation
class Node(dict):
def __init__(self, value=None, *args, **kwargs):
self.value = value
super(Node,self).__init__(*args, **kwargs)
class Trie(object):
# This Python script contains all the machine dependent settings
# needed during the build process under UBUNTU 9.04 32-bit.
# Compilers to be used.
cc = "gcc"
cxx = "g++"
f77 = "g77"
link = cxx

How to NOT write python codes

I found a piece of art in a code today. So I'm sharing it to you.

The guy was trying to check if a variable 'member' is a class from the module 'mod'

He figured that str(member) would return it's class representation, something like that:

>>> str(member)

1 Introdução
1.1 Simulação de eventos discretos
1.2 Sistemas centralizados e distribuídos
2 Simulação Distribuída de Eventos Discretos
2.1 Categorias de protocolos de simulação
2.2 O protocolo Time Warp
2.3 O protocolo Rollback Solidário
2.4 Balanceamento de cargas
@alvesjnr
alvesjnr / setup.py
Created June 14, 2012 10:58
Another boost+python example
#setup.py
from setuptools import setup
from setuptools.extension import Extension
import os.path
import sys
include_dirs = ["/usr/include/boost","."]
libraries=["boost_python-py27"]
library_dirs=['/usr/local/lib', "/usr/lib/python2.7"]