Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / eplot.rb
Created April 30, 2015 21:37
featureful command line plotting of data in a Linux shell, made easy with eplot, a gnuplot wrapper. This version is modified slightly, per the instructions found here: http://stackoverflow.com/questions/123378/command-line-unix-ascii-based-charting-plotting-tool#answer-12868778. eplot in its original form can be found here: http://liris.cnrs.fr/…
#!/usr/bin/ruby
# **************************************************************************
# ### modified based on:
# http://stackoverflow.com/questions/123378/command-line-unix-ascii-based-charting-plotting-tool
# ###
# eplot
# Written by Christian Wolf
#
# eplot ("easy gnuplot") is a shell script which allows to pipe data easily
# through gnuplot and create plots quickly, which can be saved in postscript,
@stantonk
stantonk / run-tests-hook.sh
Last active August 29, 2015 14:23
In a mercurial or git pre-commit or pre-push hook: detect the type of project and invoke the appropriate test runner for various projects. So far Maven and Django projects are supported. Trivial to add others. No-ops on unknown project types.
#!/usr/bin/env bash
################################################################################
# Use as a global mercurial/git pre commit or pre push hook to detect the type
# of project and run unittests before allowing a commit or push to a remote
# repository.
#
# Handy so that you don't have to remember to add test running hooks to every
# repo clone/fork you have.
#
# ********** MERCURIAL SETUP *************
@stantonk
stantonk / loop.py
Last active August 29, 2015 14:24
Indefinitely cycle through some sequence in Python, e.g. for object pools.
# loop foreva-eva
def loop(sequence):
while True:
for elem in sequence:
yield elem
# example usage, imagine you have a set of things you want
# to cycle through, removing bad ones as they appear
class ObjectPoolEmptyError(Exception):
@stantonk
stantonk / date_xrange.py
Created August 19, 2015 18:24
python datetime xrange generator
def date_xrange(s_dt, e_dt, inclusive=False):
ONE_DAY = timedelta(days=1)
days = (e_dt - s_dt).days
days = days + 1 if inclusive else days
return (s_dt + i*ONE_DAY for i in range(0, days))
@stantonk
stantonk / hgbatch.sh
Created March 8, 2012 17:06
Batch execute any single mercurial command on all repositories within a directory.
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg $@" to batch execute a mercurial command in all the repositories.
#
# Make sure you know what you're doing before running this ;-)
#
# Examples:
#
# Perform pull -u on all repositories to get the latest changes and update:
@stantonk
stantonk / .gvimrc.after
Created March 27, 2012 22:25
My current .gvimrc.after
"colo dawn
"colo ir_black
"colo maroloccio
colo darkbone
"set guifont=Monaco:h14
set guifont=DejaVu\ Sans\ Mono\ Bold:h14
"set guifont=Inconsolata\ Bold:h16
set hls is ic scs
set gcr=n:blinkon0
@stantonk
stantonk / date2epoch.py
Last active October 5, 2015 15:47
date2epoch
#!/usr/bin/env python
# Notes
# One can easily get the current epoch using the date command, like so:
#
# in your timezone:
#
# $ date -j +"%s"
# 1363104249
#
@stantonk
stantonk / csv
Last active October 5, 2015 22:07
Read a list of values separated by newlines from stdin and output the values on a single line separated by commas to stdout
#!/usr/bin/env bash
######
# Why is this useful?
#
# Say you have a list of ids in a database tool like SequelPro in
# the result of a query. It is possible to copy an entire column
# to the clipboard. But then you may want to pass that list of
# ids as a comma-separated list into an HTTP(S) API endpoint for
# testing. This solves that problem!
@stantonk
stantonk / prove_signed_post_request_fail.py
Created November 9, 2015 19:10
Demonstrate bug in signing of POST requests in instagram/python-instagram
# -*- coding: utf-8 -*-
from instagram.client import InstagramAPI
import time
access_token = "REDACTED"
api = InstagramAPI(access_token=access_token, client_id='REDACTED', client_secret='REDACTED')
media_id = 'REDACTED'
response = api.media(media_id=media_id)
@stantonk
stantonk / 0_reuse_code.js
Created November 15, 2015 21:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console