Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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;
### Keybase proof
I hereby claim:
* I am daveslutzkin on github.
* I am daveslutzkin (https://keybase.io/daveslutzkin) on keybase.
* I have a public key whose fingerprint is F57C 68E3 1BBE EE43 581E 799A AA29 AD04 7A4E DCB0
To claim this, I am signing this object:
@daveslutzkin
daveslutzkin / install-postgres.sh
Last active November 3, 2015 22:58
Install Postgres from PPA
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4 libpq-dev postgresql-contrib-9.4
sudo vim /etc/postgresql/*/main/pg_hba.conf
@daveslutzkin
daveslutzkin / install-docker.sh
Created November 3, 2015 23:01
Install docker from PPA
sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install docker-engine
@daveslutzkin
daveslutzkin / iam-groups-and-policies.sh
Last active November 15, 2015 00:31
AWS CLI show IAM groups and policies by user
for full_username in `aws iam list-users | jq '.Users[].UserName'`
do
username=`echo $full_username | tr -d '"'`
echo $username \\t groups `aws iam list-groups-for-user --user-name $username | jq '.Groups[].GroupName' | tr '\n' ',' | tr -d '"'` \\t policies `aws iam list-attached-user-policies --user-name $username | jq '.AttachedPolicies[].PolicyName' | tr '\n' ',' | tr -d '"'`
done
@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 / gist:6290115
Created August 21, 2013 03:40
Start a VirtualBox VM from the command line headless
VBoxManage startvm greenstein --type headless
@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