Skip to content

Instantly share code, notes, and snippets.

@jgrar
jgrar / .vimrc
Last active December 5, 2015 12:35
Turn off all jellybeans background colours
" Turn off all jellybeans background colors (.vimrc)
" --------------------------------------------------
" where turning off background colors would leave the text invisible
" on a dark background I've used the background color picked by jellybeans
" for the the foreground.
"
" NOTE:
" Setting the background of StatusLine and StatusLineNC to none
" seems to result in a bug in which the space of the status line
@jgrar
jgrar / compile.sh
Created March 23, 2015 14:10
fml.cpp
g++ -std=c++0x -lboost_unit_test_framework ./parseFilename.cpp -oparseFilename && ./parseFilename
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* returns: non-zero if s points to a sequence
* of characters that is palindromic, 0 if not
*/
int is_palindrome (char *s) {
int N, n;
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
}
@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"
@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
#!/bin/sh
while getopts "ab-:" opt
do
case "${opt}" in
-)
case "${OPTARG}" in
foo) echo foo;;
bar) echo bar;;
esac
#!/bin/sh
# f [targets]...
# process targets, reads targets from stdin if no arguments are supplied
f() {
if [ $# = 0 ]
then
while read -r t
do
@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;
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))