Skip to content

Instantly share code, notes, and snippets.

@robmiller
robmiller / .gitconfig
Created April 26, 2013 15:43
A Git alias for tagging the previous commit as having been reviewed. Useful just after a merge
# Usage:
# git tag-review 'Rob Miller <rob@example.com>'
tag-review = "!f() { git commit --amend -m \"$(git log -1 --pretty=\"format:%s%n%n%b%n%nReviewed-by: $1\")\"; }; f"
@robmiller
robmiller / gist:5501879
Created May 2, 2013 12:27
Set `$_SERVER['HTTPS']` in nginx, in the same way as it's done in Apache; this is necessary for example in WordPress, where the `is_ssl` check will otherwise fail (causing a redirect loop if you have `FORCE_SSL_ADMIN` on).
# The best place to put this is your `fastcgi_params` file.
set $_ssl "off";
# We run SSL on ports 443+, not just one port, to get
# around the lack of SNI in clients' browsers; you might
# safely be able to use "$server_port = 443"
if ( $server_port != 80 ) {
set $_ssl "on";
}
@robmiller
robmiller / .gitconfig
Last active December 24, 2016 05:09
A few useful commands for working with branches
# git branch-name: prints the name of the branch in a safe/scriptable/non-porcelain way
# git publish: publishes the current branch on the remote "origin", using the same name as the current branch
# git unpublish: deletes the remote branch with the same name as the current one (potentially destructive)
# git recreate: given a branch name, recreates the branch with that name from the latest master. Deletes both the local and remote copy of the branch first. Very destructive, use with caution
branch-name = "!git rev-parse --abbrev-ref HEAD"
publish = "!git push -u origin $(git branch-name)"
unpublish = "!git push origin :$(git branch-name)"
recreate = "!f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f"
@robmiller
robmiller / gist:5849541
Last active December 13, 2018 16:37
Quickly add Tim Pope's ctags generation scripts to all Git-controlled directories under the current one, so that you don't need to recreate your repositories.
# I love tpope's solution to ctags regeneration[1]; he creates
# a template from which all Git repositories take their default hooks,
# and then uses these hooks to regenerate ctags.
#
# [1]: http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html
#
# It's an elegant solution, but what do you do about repositories that
# already exist? The template will only apply to newly cloned or newly
# initialised repositories.
#
@robmiller
robmiller / gist:6002038
Last active December 19, 2015 18:49
One-liner for finding out what usernames attackers are using when bruteforcing SSH on an OS X box
sudo bzcat /var/log/secure*.bz2 \
| perl -ne '/authentication error for( illegal user)? (\S+) from/ && print "$2\n"' \
| sort | uniq -c | sed 's/^ *//' | sort -n
@robmiller
robmiller / .gitconfig
Created July 17, 2013 07:52
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@robmiller
robmiller / sqlite-distance.rb
Last active February 3, 2021 16:33
Ruby/SQLite code for finding places within a certain distance from another place. In other words, Ruby code that adds a "DISTANCE(lat1, lon1, lat2, lon2)" to SQLite, allowing you to select records based on the distance between two points of latitude and longitude. Magic! Adapted from the ObjectiveC version here: http://daveaddey.com/?p=71
db = SQLite3::Database.new ":memory:"
# A sample SQLite table; all that's necessary is the lat and log fields
db.execute <<-SQL
CREATE TABLE users (
email VARCHAR(255),
lat FLOAT,
lon FLOAT
)
SQL
@robmiller
robmiller / nscp.sh
Created October 7, 2013 13:34
I often want to copy the IP address for a hostname to my clipboard. This shell function will do that; drop it in your `.bashrc` or `.zshrc` and you can then call `nscp example.com` to copy the A record for `example.com` to your clipboard. It also outputs it, so you can verify it by eye (or pipe it into something else).
function nscp() {
nslookup $1 | sed -n 'x;$p' | cut -d' ' -f2 | tee >(pbcopy)
}
@robmiller
robmiller / strtotime.rb
Last active December 24, 2015 21:49
Sometimes I want to do natural language datetime calculations from the commandline, just to work out things like "what date will it be in 60 days" or "when was 30 days ago". This helps.
#!/usr/bin/env ruby
# Requirements: Ruby and the Chronic gem
#
# Install Chronic with: `gem install chronic`
#
# Examples:
#
# $ strtotime 'in 60 days'
# 6 Dec 2013 14:55:44
@robmiller
robmiller / unvalued_projects.rb
Last active December 26, 2015 03:19
Script for showing projects in your LiquidPlanner workspace that haven't had a contract_value added to them.
require "rubygems"
require "liquidplanner"
# Assumes a file called ~/.lprc exists that contains:
# { "email": "foo@example.com", "pass": "pa55w0rd", "space": 1234 }
config = JSON.parse(IO.read(File.expand_path("~/.lprc")))
lp = LiquidPlanner::Base.new(email: config["email"], password: config["pass"])
workspace = lp.workspaces(config["space"])