Skip to content

Instantly share code, notes, and snippets.

View alvesjnr's full-sized avatar

Antonio Ribeiro Alves alvesjnr

View GitHub Profile
@alvesjnr
alvesjnr / clock.py
Created September 20, 2012 12:46
A simple clock using Tkinter
from time import strftime
import Tkinter
numbers = {0:'midnight',
1:'one',
2:'two',
3:'three',
4:'four',
# 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"]
@alvesjnr
alvesjnr / hello.cpp
Created June 14, 2012 09:41
Minimum boost+python working example
#include <Python.h>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
char const* greet()
{
return "hello, world";
}
@alvesjnr
alvesjnr / getsubclasspath.py
Created June 7, 2012 08:14
How to get the subclass path
import inspect
import os
class F(object):
@classmethod
def _get_path(cls):
"""
If called by subclass of F will return the path
@alvesjnr
alvesjnr / gist:2852116
Created June 1, 2012 13:22
Por que usei __getattribute__

Seja o pequeno código, assim como listado no example.py do projeto tOSM:

from tosm.objects import *
from tosm.properties import *

class Address(Tobj):
    street = StringProperty()
    number = PositiveIntegerProperty()

class Person(Tobj):

@alvesjnr
alvesjnr / sttr.py
Created May 25, 2012 10:15
I didn't get it yet!
class A(object):
__a = 10
a = A()
print dir(a)
"""
should return something like:
@alvesjnr
alvesjnr / meta_2.py
Created May 22, 2012 14:59
Simple example of metaclass usage in Python
" Python 2 version "
class MyMetaclass(type):
def __new__(cls, name, bases, dct):
attrs = ((name, value) for name, value in dct.items() if not name.startswith('__'))
attrs = dict(("__" + name.upper(), value) for name, value in attrs)
return super(MyMetaclass, cls).__new__(cls, name, bases, attrs)