Skip to content

Instantly share code, notes, and snippets.

@rday
rday / gpiomon.c
Created December 14, 2015 15:42
Kernel module to detect button presses and record the duration
/*
* Monitor GPIO for button press
* https://www.kernel.org/doc/Documentation/gpio/gpio.txt
* drivers/gpio/gpiolib.c
*
* This is a simple kernel module to detect the duration of a button press on a Raspberry Pi 2.
* The button press durations are stored in a kfifo. A character device can be read, and the
* next available button press will be sent to user space. Only one process can read from
* the character device at a time.
*
@rday
rday / numpy_ma.py
Created June 5, 2013 18:53
Numpy moving average
import numpy as np
def moving_average(data_set, periods=3):
weights = np.ones(periods) / periods
return np.convolve(data_set, weights, mode='valid')
data = [1, 2, 3, 6, 9, 12, 20, 28, 30, 25, 22, 20, 15, 12, 10]
ma = moving_average(np.asarray(data), 3)
assert (np.around(ma, decimals=2)==np.array([2.0, 3.67, 6.0, 9.0, 13.67, 20.0, 26.0, 27.67, 25.67, 22.33, 19.0, 15.67, 12.33])).all() == True
@rday
rday / gist:3504674
Created August 28, 2012 21:52
Abstract wrapper to allow connection pools
type InitFunction func() (interface{}, error)
type ConnectionPoolWrapper struct {
size int
conn chan interface{}
}
/**
Call the init function size times. If the init function fails during any call, then
the creation of the pool is considered a failure.
@rday
rday / notes-slide.py
Last active July 27, 2017 00:53
python pptx notes slide
"""
Example of accessing the notes slides of a presentation.
Requires python-pptx 0.5.6 or later.
ryan@ryanday.net
"""
from pptx.util import lazyproperty, Pt
from pptx.parts.slide import BaseSlide, Slide, _SlideShapeTree, _SlidePlaceholders
from pptx.shapes.shape import BaseShape
@rday
rday / uart.c
Last active August 8, 2016 20:45
UART ISR w/o Driverlib
volatile uint8_t recv_buf[BUF_LEN];
volatile uint8_t recv_buf_idx = 0;
/* ... */
/* EUSCI A0 UART ISR - Echoes data back to PC host */
void euscia0_isr(void)
{
// If this interrupt is an RX interrupt
if (EUSCI_A_CMSIS(EUSCI_A0_MODULE)->rIE.r & EUSCI_A_UART_RECEIVE_INTERRUPT) {
@rday
rday / kern_prot.patch
Last active July 11, 2016 01:16
Don't sort gids that are already sorted
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -2045,12 +2045,22 @@ crsetgroups_locked(struct ucred *cr, int ngrp, gid_t *groups)
int i;
int j;
gid_t g;
+ unsigned int sorted = 0;
KASSERT(cr->cr_agroups >= ngrp, ("cr_ngroups is too small"));
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -130,7 +130,8 @@ static int getmaxfd(struct thread *td);
* resource limit).
*
* Since threads may hold references to individual descriptor table
- * entries, the tables are never freed. Instead, they are placed on a
+ * entries, the tables are only freed if a process has one thread and
+ * the table has not been shared. Otherwise, they are placed on a
* linked list and freed only when the struct filedesc is released.
@rday
rday / test.c
Last active July 8, 2016 02:07
/**
* Verify that single thread, unshared file descriptor tables are freed
*/
#include <stdio.h>
#include <unistd.h>
void dupfds()
{
int i, fd;
int fds[128];
/**
* Make sure that processes with multiple threads don't have old
* file descriptor tables freed.
*/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void *dupfds()
{
@rday
rday / benchmarks.sh
Created May 27, 2016 19:58
Benchmarks for different serialization libraries
➜ encoding git:(master) ✗ go test -bench=.
PASS
BenchmarkThriftSerialize-8 300000 3364 ns/op
BenchmarkJsonSerialize-8 200000 7623 ns/op
BenchmarkPbSerialize-8 200000 5578 ns/op
BenchmarkThriftDeserialize-8 200000 6390 ns/op
BenchmarkJsonDeserialize-8 100000 18291 ns/op
BenchmarkPbDeserialize-8 200000 7358 ns/op
ok code.wirelessregistry.com/util/encoding 8.812s
➜ encoding git:(master) ✗ go test -bench=.