Skip to content

Instantly share code, notes, and snippets.

// code for http://gowithconfidence.tumblr.com/post/31797884887/limit-buffers
package main
import (
"bytes"
"errors"
"fmt"
"io"
"sync"
@shanna
shanna / flags.c
Last active December 12, 2015 02:38
Simple C flag parser using uthash. http://troydhanson.github.com/uthash/
#include "flags.h"
#define isopt(text) strncmp(text, "--", 2) == 0
#define isneg(text) strncmp(text, "--no-", 4) == 0
flags_t *flags_parse(int argc, char *argv[]) {
int n;
char *option, *value;
flags_t *flags = NULL, *flag;
@shanna
shanna / bench.sh
Last active December 12, 2015 05:38
Evil or awesome use of tags in golang for debugging?
#!/bin/sh
go test -test.bench . 2> /dev/null
go test -tags debug -test.bench . 2> /dev/null
@shanna
shanna / router.js
Created February 20, 2013 00:59
A javascript router.
/*
Router.
Unlike larger projects (crossroads-min.js ~6.8kb, davis-min.js ~10kb, ...)
this router <1kb is intended to do one thing well; route. No events,
listeners, loggers, history or any other bullshit just a way to execute
callbacks by path.
@example
// document.location.pathname #=> /posts/media/2
@shanna
shanna / example.protocol
Last active December 22, 2015 09:38
DSL to generate a protocol definition tree.
package :foo do
enum :test, {foo: 1, bar: 2, end: 99}
struct :hsv do
float :h
float :s
float :v
end
struct :example do
@shanna
shanna / gist:6d2a6c91222ba4fa81a4
Created December 17, 2014 03:02
printf uint64_t binary.
// Has the advantage of not needing a temp buffer.
#define BINARY_8_FORMAT \
"%d%d%d%d%d%d%d%d"
#define BINARY_8_PARAMS(byte) \
(byte & 0x80 ? 1 : 0), \
(byte & 0x40 ? 1 : 0), \
(byte & 0x20 ? 1 : 0), \
(byte & 0x10 ? 1 : 0), \
(byte & 0x08 ? 1 : 0), \
@shanna
shanna / README.md
Last active August 29, 2015 14:19
BuildKite Systemd Target

BuildKite Systemd Target

Debian Jessie buildkite agent when networking is up.

/etc/systemd/system/buildkite-agent.service

@shanna
shanna / jlink
Created October 25, 2015 10:58
jlink wrapper script for debugging and flashing.
@shanna
shanna / go-env
Last active May 3, 2016 15:11
Symlink Go packages into local project directory.
#!/usr/bin/env sh
# Setup Go environment.
#
# source ~/local/bin/go-env
# http://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there
__util_env_path_prepend() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1:$PATH"
@shanna
shanna / short-prompt.sh
Last active May 4, 2016 07:25
A short, smart, prompt.
# [ -e ~/.config/short-prompt.sh ] && source ~/.config/short-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
__git_ps1() { PS1="$1$2"; }
[ -e ~/.config/git-prompt.sh ] && source ~/.config/git-prompt.sh
__short_ps1() {
local exit=$?
local __short_ps1_host=""
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then