Skip to content

Instantly share code, notes, and snippets.

View lecram's full-sized avatar

Marcel Rodrigues lecram

View GitHub Profile
@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 / 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 / explode.c
Last active September 20, 2020 11:48
/* Compiling:
* $ gcc -O2 -o explode gifdec.c explode.c
* Comparing gifdec with ImageMagick's GIF decoder:
* $ ./explode foo.gif # generates gd_%03d.ppm files
* $ convert -coalesce foo.gif im_%03d.ppm
* $ # comparing entire animation:
* $ cat gd_*.ppm | md5sum
* $ cat im_*.ppm | md5sum
* $ # comparing each frame:
* $ md5sum gd_*.ppm
@lecram
lecram / rndfmt.c
Last active August 14, 2020 15:27
Automatic random testing for printf() with regard to %-formatting.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
char rand_chr()
{
char c;
do {
@lecram
lecram / brlife.c
Last active December 16, 2016 23:34
Game of Life in terminal using braille.
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>
#include <locale.h>
#include <time.h>
#include <poll.h>
@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].
#! /bin/sh
cmd="$(match "$(realpath "$1")")"
printf "create '%s'\\n" "$cmd" | nc -U /tmp/dvtm-sock
@lecram
lecram / disasm
Last active January 2, 2016 22:49
A wrapper to use objdump for raw i8086 disassembling with intel syntax.
#! /bin/bash
if [ $# -lt 1 ] || [ $# -gt 3 ]
then
printf 'usage:\n %s <file> [offset [limit|(+|-)length]]\n' `basename $0`
exit 1
fi
IN="$1"
START=0
@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))