Skip to content

Instantly share code, notes, and snippets.

View lecram's full-sized avatar

Marcel Rodrigues lecram

View GitHub Profile
@lecram
lecram / test_bmp_font.py
Last active December 28, 2015 08:09
Test for PySDL2's BitmapFont.
# To use this script, save the image from the page below as '7sled.png'.
# http://imgur.com/C2OLhYj
# The script should create a file 'test_bmp_font.bmp' that looks like this:
# http://imgur.com/WFJNRTT
import atexit
import sdl2
import sdl2.ext
@lecram
lecram / table.py
Last active December 20, 2015 12:29
CSV read/write/print/join.
import codecs
import collections
def join(t1, t2, pivots=None, keys=None):
keys1 = t1[0]._fields
keys2 = t2[0]._fields
if pivots is None:
pivots = list(set(keys1) & set(keys2))
if keys is None:
keys = list(set(keys1) | set(keys2))
@lecram
lecram / escher.py
Last active August 27, 2021 07:05
This is a toy one-file application to manage persistent key-value string data. The file is *both* the application and its data. When you run any of the commands described in `escher.py --help`, the file will be executed and, after data change, it will rewrite itself with updated data. You can copy the file with whatever name to create multiple d…
#! /usr/bin/env python
"""{escher} -- one-file key-value storage.
What?
This is a toy application to manage persistent key-value string data.
The file {escher} is *both* the application and its data.
When you run any of the commands below, the file will be executed and,
after data change, it will rewrite itself with updated data.
You can copy the file with whatever name to create multiple datasets.
@lecram
lecram / oer.py
Created July 12, 2012 18:41
Currency conversion.
#! /usr/bin/python
import urllib2
import json
import time
import sys
baseurl = "http://openexchangerates.org/api/latest.json"
key = "{{Your Open Exchange Rates App ID here!}}"
url = baseurl + "?app_id=" + key
@lecram
lecram / rgrow.c
Created November 30, 2011 14:55
Region Growing (C)
#include <stdlib.h>
#include <stdio.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
typedef struct {
unsigned char r;
unsigned char g;
unsigned char b;
@lecram
lecram / ccg.py
Created November 7, 2011 18:24
C Call Graph.
import subprocess
call = "ctags -no - *.c"
tags = subprocess.check_output(call, shell=True)
funcs = []
for entry in tags.split('\n'):
tokens = entry.split('\t')
if tokens[-1].strip() == "f":
func, source, line, symboltype = tokens
@lecram
lecram / thresh.c
Created October 20, 2011 01:42
Limiarização com OpenCV.
/* Limiarização de imagens utilizando OpenCV.
*
* Este programa implementa uma função genérica para limiarização de
* imagens em escala de cinza.
*
* Utilização: thresh file threshold below above
* *file - Nome do arquivo da imagem de entrada.
* *threshold - Valor real do limiar, no intervalo [0, 1].
* *below - Valor real que deve substituir valores abaixo do (ou iguais ao)
* limiar, no intervalo [0, 1].