Skip to content

Instantly share code, notes, and snippets.

@nicokruger
nicokruger / argstester.sh
Created March 18, 2012 21:38
argstester.sh
for var in "$@"
do
echo $var
done
@nicokruger
nicokruger / simple-gnuplot.sh
Created March 18, 2012 21:27
Simple 1d gnuplot line graph
TMP_FILE=$(mktemp)
for var in "$@"
do
echo $var >> $TMP_FILE
done
GNUPLOT_FILE=$(mktemp)
gnuplot <<DeadBeef
set style line 1 linetype 2
@nicokruger
nicokruger / count-files.sh
Created March 18, 2012 21:02
count-files.sh
#!/bin/bash
echo $(find . -type f | grep -v .git | wc -l)
@nicokruger
nicokruger / gister.sh
Created March 18, 2012 20:34
Gister (view gists on github)
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Usage: <mode> <github username> <gist filename>" >&2
echo " mode is:" >&2
echo " -o output the file to stdout" >&2
echo " -s store the file in a temporary location, and print the temp filename" >&2
echo " -x execute the script" >&2
echo " (to pass arguments to the downloaeded script, add a \"-\" and add" >&2
echo " add the args for the downloaded script after that)" >&2
@nicokruger
nicokruger / piped-script-arguments.sh
Created March 18, 2012 20:01
bash pass arguments to script read through pipe
λ ~ → echo 'echo $1 $2 $3' | bash -s - 10 11 12
10 11 12
@nicokruger
nicokruger / git-foreach.sh
Created March 18, 2012 16:42
Execute a command for all commits in a git repository.
#!/bin/bash
if ! [ -d ".git" ]; then
echo "Script must be run from within a git repository"
exit 1
fi
if [ $# -ne 1 ]; then
echo "Please specify a script to execute for each commit"
echo "Script will recieve <repo_dir> <commit ref> as arguments"
@nicokruger
nicokruger / inotify-test.js
Created March 13, 2012 18:57
inotify-test.js
var Inotify = require('inotify').Inotify;
var inotify = new Inotify(); //persistent by default, new Inotify(false) //no persistent
var data = {}; //used to correlate two events
var callback = function(event) {
var mask = event.mask;
var type = mask & Inotify.IN_ISDIR ? 'directory ' : 'file ';
event.name ? type += ' ' + event.name + ' ': ' ';
@nicokruger
nicokruger / spd-povray.sh
Created March 13, 2012 11:07
spd-povray
for F in `find . -executable`; do ./$F -r 4 > tmp.pov; povray +O$F.png +A0.5 +AM2 +W1600 +H1200 tmp.pov; done
@nicokruger
nicokruger / js-proto.js
Created March 4, 2012 07:45
js-proto-deprecated
var NotAuthenticated = function () {
this.name = "Not authenticated";
Error.call(this, "Not authenticated");
Error.captureStackTrace(this, arguments.callee);
};
NotAuthenticated.prototype.__proto__ = Error.prototype;
... later on ....
if (error instanceof NotAuthenticated) {
@nicokruger
nicokruger / find-the-bug1.py
Created March 1, 2012 19:49
find the bug part one
import calendar
import sys
def ConvertDays(days):
year = 1980
while days > 365:
if calendar.isleap(year):
if days > 366:
days -= 366
year += 1