Skip to content

Instantly share code, notes, and snippets.

@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;
@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
@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 / nginx.conf
Last active September 20, 2017 20:04
Nginx conf for solid SSL/TLS
# Thin serving Rails.
upstream app_server {
server 127.0.0.1:3050 fail_timeout=0;
}
# SSL/TLS certificates - the key should be 4096 bit generated with: 'openssl genrsa -des3 -out server.key 4096'
ssl_certificate_key /var/app/deploy/www.thisisatest.com.key;
ssl_certificate /var/app/deploy/www.thisisatest.com.chained.crt;
# Ideally we'd have only TLSv1.2, but that compromises client support significantly
@daveslutzkin
daveslutzkin / phoenix.sh
Last active February 6, 2016 11:31
Elixir + Phoenix setup
# Install node (for brunch)
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
echo 'deb https://deb.nodesource.com/node_4.x trusty main' | sudo tee /etc/apt/sources.list.d/nodesource.list
echo 'deb-src https://deb.nodesource.com/node_4.x trusty main' | sudo tee -a /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install --yes nodejs
# Install erlang and elixir
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb &&\
sudo dpkg -i erlang-solutions_1.0_all.deb &&\
@daveslutzkin
daveslutzkin / install-node.sh
Last active November 11, 2017 23:44
Installs node
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
echo 'deb https://deb.nodesource.com/node_8.x trusty main' | sudo tee /etc/apt/sources.list.d/nodesource.list
echo 'deb-src https://deb.nodesource.com/node_8.x trusty main' | sudo tee -a /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install --yes nodejs
### 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: