Skip to content

Instantly share code, notes, and snippets.

@lpereira
lpereira / tpl-array.c
Created November 3, 2016 02:18
Lwan template with arrays
#include <lwan.h>
#include <lwan-template.h>
#include <strbuf.h>
struct thing {
lwan_tpl_list_generator_t generator;
const char *name;
};
import socket
import time
import random
import pygame
import pygame.camera
import pygame.transform
from pygame.locals import *
UDP_IP = "192.168.50.50"
UDP_PORT = 2711
#!/usr/bin/python
import sys
def parse_nm_output(handle):
current_object = None
symbols = {}
symbol_to_object = {}
for line in handle.readlines():
/*
* SPSC Bounded Queue
* Based on public domain C++ version by mstump[1]. Released under
* the same license terms.
*
* [1] https://github.com/mstump/queues/blob/master/include/spsc-bounded-queue.hpp
*/
#if !defined(__ATOMIC_RELAXED)
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
struct task {
void *(*cb)(void *data);
void *data;
bool runnable;
};
@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:
/*
* ----------------------------------------------------------------------------
* "THE MATE-WARE LICENSE" (Revision 42): <[email protected]> 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>
/*
package main
import "fmt"
func main() {
fmt.Println("counting");
for i := 0; i < 10; i++ {
#!/usr/bin/python
import mraa
import time
import pyupm_i2clcd
import pyupm_grove
import SimpleXMLRPCServer
import netifaces as ni
import threading
import Queue
@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, \