Skip to content

Instantly share code, notes, and snippets.

@lpereira
lpereira / bbmonitor
Last active August 29, 2015 14:07 — forked from drott/bbmonitor
#!/usr/bin/python2
#
# Buildbot monitor
# Author: Leandro A. F. Pereira <leandro@profusion.mobi>
#
# Copyright (C) 2010 ProFUSION Embedded Systems
#
import urllib
import BeautifulSoup
@lpereira
lpereira / Non-pipelined
Created March 3, 2015 10:58
Pipelined vs non-pipelined strace output
3340 accept4(15, <unfinished ...>
3341 <... nanosleep resumed> NULL) = 0
3341 nanosleep({3, 0}, NULL) = 0
3341 nanosleep({4, 0}, <unfinished ...>
3340 <... accept4 resumed> 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 16
3340 write(14, "\20\0\0\0", 4) = 4
3345 <... epoll_wait resumed> {{EPOLLIN, {u32=0, u64=0}}}, 1024, -1) = 1
3340 accept4(15, <unfinished ...>
3345 open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 18
3345 fstat(18, {st_mode=S_IFREG|0644, st_size=2015, ...}) = 0
@lpereira
lpereira / pipeline-test.sh
Created March 9, 2015 22:57
Pipeline benchmark
#!/bin/sh
exec wrk -H 'Host: localhost' \
-H 'Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7' \
-H 'Connection: keep-alive' \
-d 10 \
-c 1000 \
--timeout 16384 \
-t 4 \
http://127.0.0.1:8080/hello \
#!/usr/bin/python
import mraa
import time
import pyupm_i2clcd
import pyupm_grove
import SimpleXMLRPCServer
import netifaces as ni
import threading
import Queue
/*
* ----------------------------------------------------------------------------
* "THE MATE-WARE LICENSE" (Revision 42): <leandro@tia.mat.br> wrote this
* file. As long as you retain this notice you can do whatever you want
* with this stuff. If we meet some day, and you think this stuff is worth
* it, you can buy me a Club-Mate in return. Leandro Pereira
* ----------------------------------------------------------------------------
*/
#include <arpa/inet.h>
@lpereira
lpereira / valuepack.py
Created September 9, 2015 01:12
Value packing with prime numbers
#!/usr/bin/python
import math
def pack_bits(*bits):
n = 0
max_n = 1
for value, prime_for_value in bits:
while n % prime_for_value != value:
@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 / 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>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
struct task {
void *(*cb)(void *data);
void *data;
bool runnable;
};