Skip to content

Instantly share code, notes, and snippets.

@daveslutzkin
daveslutzkin / histogram.sql
Last active August 29, 2015 14:12
Show a histogram in the Postgres console
with
num_buckets as (select 10),
suburbs as (select unnest(array['Fitzroy North','Northcote','Brunswick East','Clifton Hill'])),
rows as (
select
price as field
from
results inner join properties on (property_id=properties.id)
where
@daveslutzkin
daveslutzkin / docker-hard-clean.sh
Last active August 29, 2015 14:08
Clean up docker containers and images
# Frees up a lot of disk space by removing almost everything from the docker cache.
# Get rid of all unnamed containers.
sudo docker ps -a | grep -v ":" | grep -v "ID" | awk '{ print $1 }' | sort | uniq | xargs sudo docker rm
# Get rid of all unnamed images.
sudo docker images | grep "^<none>" | awk '{ print $3 }' | xargs sudo docker rmi
@daveslutzkin
daveslutzkin / git-ff
Last active December 31, 2015 11:39
#!/bin/bash
# Attempts to fast-forward the current local branch to its remote tracked branch.
# Safely refuses if there is no remote tracking, or if a fast-forward is not possible.
# @author Paul Annesley
if [ -n "$(git merge --ff-only 2>&1 | grep 'unknown option')" ]; then
echo "Your git doesn't seem to support --ff-only... try git 1.7+"
exit 1
fi
@daveslutzkin
daveslutzkin / gist:6290115
Created August 21, 2013 03:40
Start a VirtualBox VM from the command line headless
VBoxManage startvm greenstein --type headless
@daveslutzkin
daveslutzkin / gist:4646080
Created January 27, 2013 03:23
Quick backup of music from one server to another.
rsync -avzhr --delete 2012/ daveslutzkin@Shakespeare.local:/Volumes/Moozaic/New-Music/Music/2012
@daveslutzkin
daveslutzkin / median.sql
Created July 27, 2012 08:00
SQL code to calculate the median
select from_unixtime(timecreated,"%Y-%m") as month,(substring_index(substring_index(group_concat(t._price order by t._price), ',', ceiling(count(*)/2)), ',', -1) + substring_index(substring_index(group_concat(t._price order by t._price), ',', -ceiling(count(*)/2)), ',', 1)) / 2 as median from auction t where status='won' group by month;