Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Charter Chapman charterchap

View GitHub Profile
View .gitconfig
[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
br = branch -a --sort=-committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
permission-reset = !git diff -p -R --no-color | grep -E \"^(diff|(old|new) mode)\" --color=never | git apply
[diff]
tool = sublimerge
View fff_by_reference.cpp
/* Use of lambda functions for fff custom_fake
*
* this file contains an example of how to have "nested functions"
* within a test case for setting an fff custom_fake for pass by reference args
*
* This method for custom fakes allows all your test code to be self contained
* inside a test case instead of having global functions cluttering your test
* code.
*
* note that lambda captures are not supported
View python_nanomsg_logger_consumer.py
#
# python_nanomsg_logger_consumer.py
# run me first
from __future__ import print_function
from nanomsg import Socket, PAIR, PUB, SUB, SUB_SUBSCRIBE
s2 = Socket(SUB)
s2.connect(b"ipc:///tmp/nanologger.ipc")
s2.set_string_option(SUB, SUB_SUBSCRIBE, b'')
@charterchap
charterchap / fnv1_32.rs
Last active Feb 28, 2017
fnv1_32 and fnv1a_32 in rust
View fnv1_32.rs
// see libhashkit/fnv_32.cc from memcached
// Just using this as excuse to test out the Rust lang
// be warned on correctness, completeness, etc
// Should match libhashkit
// should also match https://www.nitrxgen.net/hashgen/
// FNV hash'es lifted from Dustin Sallings work
@charterchap
charterchap / atomic_writes.cpp
Created Sep 16, 2015
atomic writes linux c++, QT, Boost, GNU
View atomic_writes.cpp
// Practical snippets for loosely atomic writes on linux
// Important, even more so on allocate on flush file systems such as xfs and ext4.
// You can learn more here: https://www.flamingspork.com/talks/
// https://www.kernel.org/doc/Documentation/filesystems/ext4.txt
// These snippets are not perfect, if writing cross platform applications - marco guards
// Just trying to convey the gist
// The basic routine is:
// 1. Write data as file.new
@charterchap
charterchap / osm_get_road_lengths.cpp
Last active Sep 16, 2015
Figure out OSM road lengths
View osm_get_road_lengths.cpp
/*
This is an example tool that computes the sums of highway lengths.
by Frederik Ramm <frederik@remote.org>
notes from Charter Chapman:
I picked this up in 2015 and it didn't work :( so hammered it until it worked
You need the latest of the old Osmium
https://github.com/joto/osmium
@charterchap
charterchap / onelineart
Last active Nov 11, 2016
ascii art for my ps1 prompt
View onelineart
# I find it useful to have return codes printed on my terminal prompt
# I went overboard
### On success print fun art!
# |\/| /\ /
# .__.. \_/ \/
# \____/_ __/
# /_/_/ ~/Documents
### on fail
# :( ~/Documents
View wait_for_xvfb_to_init.sh
# I had a problem today where trying to load things into an Xvfb was not working because the xvfb
# was not yet initialized. The problem script is as follows:
# Start the Xvfb on DISPLAY :1,
`dirname $0`/Xvfb :1 -screen 0 1280x1024x24 -ac -br -fbdir /dev/shm & xvfbpid=$!
DISPLAY=:1 xli -onroot -fillscreen `dirname $0`/images/background.png
# The only solution I see on the web is to insert a sleep statement.
# I don't much like that. The solution I came up with is to wait for the display to be ready to use via xdpyinfo.
# The working script:
@charterchap
charterchap / fnv1a_32.js
Last active Sep 19, 2016
fnv1a_32 hash in javascript consistent w/ libhashkit
View fnv1a_32.js
// J. Charter Chapman
// fnv1a_32 in javascript based on libhashkit
// this one actually outputs consistent with hashkit
// there are a couple of interesting implementations out there
// string to byte array [think char *]
function getBytes(s) {
var buf = [];
for (var i = 0; i < s.length; i++) {
buf.push(s.charCodeAt(i));