Skip to content

Instantly share code, notes, and snippets.

@kennyp
kennyp / gist:6237628
Created August 15, 2013 02:09
LGTM button for pull requests.
// ==UserScript==
// @name LGTM Button
// @namespace lgtm.github.com
// @description Add a LGTM button to pull requests.
// @include https://github.com/Skookum/*/pull/*
// @version 1
// ==/UserScript==
var lgtmButton = document.createElement('button'),
buttonCont = document.querySelector('button[name="comment_and_close"]').parentNode,
commentBtn = buttonCont.querySelector('button:last-child');
class TrueClass
def to_i
1
end
end
class FalseClass
def to_i
0
end
@kennyp
kennyp / gist:5902608
Created July 1, 2013 17:00
Auto-complete for hcl.
_hcl () {
local cur prev opts cmds tasks
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version"
cmds="show tasks aliases set unset start stop resume note"
if [[ ${cur} == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
@kennyp
kennyp / gist:5444483
Created April 23, 2013 15:21
Run concurrently with a progress bar.
def run_concurrently(title, jobs, &block)
mutex = Mutex.new
work = Queue.new
jobs.each {|j| work << j}
pbar = ProgressBar.create(title: title, total: jobs.length, format: '%a |%w>%i| %e %t')
threads = 4.times.map do
Thread.new do
loop do
block.call(work.pop(:nonblocking))
mutex.synchronize { pbar.increment }
@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
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 / 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
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
#!/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
#!/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 /: $!";