Skip to content

Instantly share code, notes, and snippets.

@jgrar
jgrar / struct_test.c
Last active August 29, 2015 13:56 — forked from treeherder/a_g.c
#include <stdio.h>
struct ret
{
char *id;
int accel_x;
int accel_y;
int accel_z;
int gyro_x;
int gyro_y;
int byteCmp (byte a[], byte b[], int n) {
for (byte i = 0; i < n; i++) {
if (a[i] != b[i]) {
return 1;
}
}
return 0;
}
// somewhere in loop()...
....
WHERE timestamp
BETWEEN
strftime('%s', ?, 'unixepoch', 'start of day')
AND
strftime('%s', ?, 'unixepoch', 'start of day', '+1 days', '-1 second')
import re
import subprocess
#device_re = "Bus \d{,3} Device \d{,3}: ID ([a-f0-9]+:[a-f0-9]+)"
device_re = "ID ([a-f0-9]+:[a-f0-9]+)"
df = subprocess.check_output("lsusb", shell=True)
for i in df.split('\n'):
if i:
print (re.findall(device_re, i, re.I))
@jgrar
jgrar / reverse.c
Last active August 29, 2015 14:01
#include <stdlib.h>
#include <stdio.h>
struct list {
int v;
struct list *next;
};
void reverse (struct list **head) {
struct list *p, *n;
#!/bin/sh
# f [targets]...
# process targets, reads targets from stdin if no arguments are supplied
f() {
if [ $# = 0 ]
then
while read -r t
do
#!/bin/sh
while getopts "ab-:" opt
do
case "${opt}" in
-)
case "${OPTARG}" in
foo) echo foo;;
bar) echo bar;;
esac
@jgrar
jgrar / copy.sh
Last active August 29, 2015 14:02
#/bin/sh
# the redirections are a bit confusing, but trust me it works
# progress_gpio.sh (change at your discretion) should read integers representing
# percentage progress and manipulate the leds accordingly
dd if="/dev/sda" | pv -EEn 2>&1 > out.img | progress_gpio.sh
# out.img should be a raw dump of the disk, but i'd recommend also
# saving an fdisk -l "/dev/sda". You could also compress the image
@jgrar
jgrar / 10-clone.rules
Last active August 29, 2015 14:03
autoclone - automagical disk backup
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd?", RUN+="/usr/local/bin/autoclone.sh"
package sumsuffix
func SumSuffix (s string) int {
var r int
for i := 0; i < len(s); i++ {
suffix := s[i:]
for j := 0; j < len(suffix); j++ {
if s[j] != suffix[j] {
break
}