Skip to content

Instantly share code, notes, and snippets.

@lpereira
lpereira / minifinf.c
Created June 11, 2011 14:30
minifinf
#include <stdio.h>
#include <string.h>
typedef void (*NativeFunction)(int *ip);
typedef struct _Instruction Instruction;
struct _Instruction {
unsigned int opcode;
unsigned long parameter;
};
@lpereira
lpereira / scdq5541.pde
Created June 12, 2011 16:47
Interfacing Osram SCDQ5541 dot-matrix display with an Arduino
class SCDQ5541 {
private:
int m_clock, m_data, m_load;
void bitbang(unsigned char code)
{
digitalWrite(m_load, LOW);
for (int i = 0; i < 8; i++) {
digitalWrite(m_clock, LOW);
digitalWrite(m_data, code & 0x01);
@lpereira
lpereira / gist:1324915
Created October 29, 2011 18:41
Arduino Charlieplexing
static const byte charlie_pins[] = {5, 6, 7};
static const byte charlie_led[][2] = {
{ 0, 1 },
{ 1, 0 },
{ 0, 2 },
{ 2, 0 },
{ 1, 2 },
{ 2, 1 }
};
@lpereira
lpereira / gist:1636774
Created January 19, 2012 00:36
RFID Arduino
// Ebay RFID decoder by Aaron Christiansen
// Original article: http://thetransistor.com/2011/10/hacking-cheap-rfid-readers/
// Optimizations by Leandro Pereira
// NOTE: this uses the NewSoftwareSerial beta 11
// by Mikal Hart, available here:
// http://arduiniana.org/2011/01/newsoftserial-11-beta/
#include <SoftwareSerial.h>
@lpereira
lpereira / coro.c
Created March 22, 2012 01:12
Simple coroutine implementation in C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <ucontext.h>
typedef struct coro_t_ coro_t;
typedef struct thread_t_ thread_t;
typedef int (*coro_function_t)(coro_t *coro);
typedef enum {
CORO_NEW,
@lpereira
lpereira / gist:3267085
Created August 5, 2012 20:47
Pinball Display Driver
/*
* Pinball Display Driver
* Arudino version by Leandro Pereira
*
* Based on code by Daniel Quadros, available at
* http://dqsoft.blogspot.com.br/2011/06/projeto-epoch-parte4-software-cont.html
*/
#define DISP_S0 8
#define DISP_S1 9
@lpereira
lpereira / partial.c
Last active January 29, 2023 20:12
Partial functions in C This program illustrates a hack to create partial functions in C. The way it works is that it generates a template function (partial_template_function) with known pointers, that is later copied to a region of memory obtained with mmap(), patched up with the address and data to be passed to the real function, and then made …
/*
* Partial applied functions in C
* Leandro Pereira <leandro@tia.mat.br>
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
@lpereira
lpereira / Chamada de Participação para a Tosconf[1]
Created March 6, 2013 19:16
Chamada de Participação para a Tosconf[1]
┌───┬───┬───┬───┬───┬───┬───┐
└─┐ │ │ ─┤ │ │ │ ─┤
│ │ │ ├─ │ ─┤ │ │ │ │ ┌─┘
└─┴───┴───┴───┴───┴─┴─┴─┘
2013-06-01 LHC, Campinas - São Paulo
A Tosconf é uma desconferência anual organizada pelo Laboratório
Hacker de Campinas (LHC). Em sua primeira edição, em 2012, atraiu
desenvolvedores, pesquisadores de segurança da informação e
figuras míticas da computação.
@lpereira
lpereira / gist:6694015
Last active January 26, 2016 23:11
How to use sequences with lwan template
#include <assert.h>
#include <sys/types.h>
#include <dirent.h>
#include "lwan-status.h"
#include "lwan-template.h"
#include "strbuf.h"
struct file_list {
const char *path;
@lpereira
lpereira / arduino-7seg.cc
Created October 20, 2013 02:18
Arduino 7-segment display driver
namespace {
const char segment_pin[7] = {
[0] = 0,
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 0,
[6] = 0,