Skip to content

Instantly share code, notes, and snippets.

@kennyp
kennyp / keys.js
Created August 10, 2012 20:32
Key Sequences
/*jslint plusplus: true, continue: true */
/*global define: false, alert: false */
function trimString(str) {
'use strict';
str = str.replace(/^\s\s*/, '');
var ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
@kennyp
kennyp / employee.sql
Created August 23, 2012 20:27
Because there is not a decent limit clause in MSSQL.
SELECT
*
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY last_name asc) AS RowNum,
phppos_people.*,
phppos_employees.username,
phppos_employees.deleted
FROM phppos_people
JOIN phppos_employees ON
@kennyp
kennyp / text.svg
Created September 13, 2012 19:03
Playing with SVG text.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kennyp
kennyp / .bashrc
Created January 16, 2013 17:45
Help for early space.
gi () {
local cmd=$1
shift 1
cmd=$(echo $cmd | sed -e 's/^t//')
git $cmd $@
}
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(setsid);
&daemonize;
exec("mplayer -really-quiet -noar /usr/share/sounds/gnome/default/alerts/glass.* &> /dev/null");
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
#!/usr/bin/bash
git remote prune origin
git branch | grep -v master$ | cut -d' ' -f3 | while read b; do echo "$b == $(git branch -r | grep $b)"; done | grep '== $' | cut -d' ' -f1 | xargs -n1 git branch -d
git gc
h = Hash.new do |h,k|
l = h.keys.select {|i| i < k}.max
h[l]
end
h[1] = :foo
h[5] = :bar
h[3] # => :foo
@kennyp
kennyp / watch-the-ding
Created February 21, 2013 20:48
Replace `_` with `/` for paths. .irssi files live on the server `watch-the-ding' is local.
#!/usr/bin/bash
ssh new.jroes.net 'cat /dev/null > ~/.the-ding && tail -f ~/.the-ding' | while read hit
do
mplayer -really-quiet -noar /usr/share/sounds/gnome/default/alerts/glass.* &> /dev/null
done
require_relative './text_effect'
fonts = %w(Courier Helvetica Times-Roman Arial-Regular Consolas-Regular
Inconsolata-Medium Times-New-Roman-Regular Verdana-Regular)
effects = [:arc, :taper, :concave, :pinch, :bulge, :ramp, :wedge, :normal]
fonts.product(effects).each do |font, effect|
File.open("#{font}-#{effect}.svg", "w") do |f|
f.write TextEffect.new('Hello World!', font, effect)
@kennyp
kennyp / git-by-date
Created February 26, 2013 20:30
If you need to sort files by creation date in git. ex. `find . -name '*.rake' | git by-date`
#!/usr/bin/bash
while read f
do
echo "$(git log --format="%at" --reverse "$f" | head -n1) --> $f"
done | sort -n