Skip to content

Instantly share code, notes, and snippets.

#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
import ctypes
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
@peterfpeterson
peterfpeterson / ctest
Last active December 31, 2015 03:49
ctest bash completionThis is merged from a couple of online sources that I no longer recall the source of.
# bash completion for ctest(1) -*- shell-script -*-
_ctest()
{
local cur prev words cword
_gst_init_completion -n = || return
case "$prev" in
-C|--build-config)
COMPREPLY=( $( compgen -W 'Debug Release RelWithDebInfo
@peterfpeterson
peterfpeterson / today
Last active January 1, 2016 05:19
Convenience thing to help out with my todo.txt and due dates
#!/usr/bin/env python
import datetime
date = datetime.date.today()
import sys
if len(sys.argv) > 1:
delta = datetime.timedelta(int(sys.argv[1]))
date += delta
print "%4d-%02d-%02d" % (date.year, date.month, date.day)
@peterfpeterson
peterfpeterson / homesick_bash_completion
Created March 28, 2014 21:01
homesick bash completion
# bash completion for homesick(1) -*- shell-script -*-
_castlelist()
{
echo $(homesick list | awk '{print $1}')
}
_homesick()
{
local cur prev words cword
@peterfpeterson
peterfpeterson / nanoc_bash_completion
Last active August 29, 2015 13:58
Bash completion for nanoc. This really is just some of the commands that I use.
# bash completion for nanoc -*- shell-script -*-
_nanoc()
{
local cur prev words cword
_gst_init_completion -n = || return
COMPREPLY=( $( compgen -W "compile create view" -- "$cur") )
} &&
complete -F _nanoc nanoc
@peterfpeterson
peterfpeterson / NeutronXrayLocations.json
Last active November 16, 2017 16:57
Locations of Neutron and X-ray user facilities
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Simple calculator - from https://github.com/mathiasbynens/dotfiles/blob/master/.functions
function calc() {
local result=""
result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')"
# └─ default (when `--mathlib` is used) is 20
#
if [[ "$result" == *.* ]]; then
# improve the output for decimal numbers
printf "$result" |
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
@peterfpeterson
peterfpeterson / gist.md
Last active August 29, 2015 13:58
How to pull in other peoples forks of your gist
  1. git clone <yourgisturl> <usefulname>
  2. cd <usefulname>
  3. edit the .git/config to have the origin remote point at git@gist.github.com:1234.git rather than the https url. I'm sure there is a
  4. git remote add <name> <forkurl>
  5. git fetch <name>
  6. git merge <name>/master --no-ff
  7. git push origin master
# This script is based on one from
# https://forums.dropbox.com/topic.php?id=9644
_dropbox()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="status help puburl stop running start filestatus ls autostart exclude lansync"
@peterfpeterson
peterfpeterson / bibtexdoi.md
Last active September 20, 2022 14:18
Bibtex citation from DOI

This was discovered in the comments of a "not constructive" question on Stack Overflow. Further exploration got me to this page.

$ curl -LH "Accept: text/bibliography; style=bibtex" http://dx.doi.org/10.1136/bmj.313.7072.1659

Will return (whitespace liberally added):

@article{Craddock_1996,
  title={Introducing Selfcite 2.0--career enhancing software},
  volume={313},