Skip to content

Instantly share code, notes, and snippets.

View lecram's full-sized avatar

Marcel Rodrigues lecram

View GitHub Profile
@lecram
lecram / alt.lua
Last active August 29, 2015 14:05
AltScript Prototype
local ffi = require "ffi"
ffi.cdef[[
double hypot(double x, double y);
double copysign(double x, double y);
]]
local mathx = ffi.C
function round(x)
local i, f = math.modf(x + mathx.copysign(0.5, x))
return i
@lecram
lecram / profilight.py
Created February 24, 2015 03:35
Minimal Python profiler implemented in pure Python.
import sys
import os
import linecache
class Profiler:
def __init__(self, instrument):
self.instrument = instrument
def run(self, func, *args, **kwargs):
@lecram
lecram / txt2mid.c
Last active November 8, 2015 22:14
txt2mid
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#define write16(fd, n) write((fd), (uint8_t []) {(n) >> 8, (n) & 0xFF}, 2)
#define write32(fd, n) do { \
#! /bin/sh
cmd="$(match "$(realpath "$1")")"
printf "create '%s'\\n" "$cmd" | nc -U /tmp/dvtm-sock
@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 / 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 / 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