Skip to content

Instantly share code, notes, and snippets.

@lpereira
lpereira / gist:8466423
Created January 17, 2014 00:46
Epoch LHC
/*
* 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
*/
/*
* Com o ethernet shield, alguns dos pinos usados aqui nao funcionam pq o shield
@lpereira
lpereira / gist:c0bf3ca3148321395037
Created June 23, 2014 22:26
Integer to string conversion benchmark
#include <chrono>
#include <cstdint>
#include <iostream>
#include <random>
#include <sstream>
using namespace std;
using namespace std::chrono;
const uint64_t P01 = 10;
@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 / adblock.py
Last active November 29, 2017 00:08
Block ads and other annoyances by redirecting their host names to 127.0.0.1
#!/usr/bin/python
import requests
sources = [
'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext',
'http://hosts-file.net/.%5Cad_servers.txt',
'https://adaway.org/hosts.txt',
'http://winhelp2002.mvps.org/hosts.txt',
'http://sysctl.org/cameleon/hosts',
@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 \
@lpereira
lpereira / gist:ccbb99a0ed288a2e9487
Created May 14, 2015 10:57
Lwan template interpreter
New Old
movsx esi,BYTE PTR [r14+0x8] movsx esi,BYTE PTR [r13+0x8]
mov rdi,r12 mov rdi,rbp
add rbx,0x1 add r13,0x18
call 0x412fd0 <strbuf_append_char> call 0x413ed0 <strbuf_append_char>
mov rax,QWORD PTR [r15+rbx*8] mov eax,DWORD PTR [r13+0x0]
jmp QWORD PTR [rax*8+0x416440] mov rax,QWORD PTR [rax*8+0x4166a0]
jmp rax
@lpereira
lpereira / parse-number.c
Created June 7, 2015 22:04
Number parsing using C11 _Generic
/* parse_number() using C11 _Generic */
/* @lafp, 2015-06-07 */
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#define parse_number(Input, Output) \
_Generic((*Output), \
int: parse_number_strtoint, \
#!/usr/bin/python
import mraa
import time
import pyupm_i2clcd
import pyupm_grove
import SimpleXMLRPCServer
import netifaces as ni
import threading
import Queue
/*
package main
import "fmt"
func main() {
fmt.Println("counting");
for i := 0; i < 10; i++ {