Skip to content

Instantly share code, notes, and snippets.

@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 / .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: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
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 <[email protected]>'
tag-review = "!f() { git commit --amend -m \"$(git log -1 --pretty=\"format:%s%n%n%b%n%nReviewed-by: $1\")\"; }; f"
@robmiller
robmiller / .gitconfig
Last active May 20, 2020 13:45
Want to find out what changes were introduced by a particular merge commit? Hey, so do I! ALL THE TIME. These aliases will do that.
# `git merge-log` shows the commits that were introduced in a given merge
# `git merge-diff` shows the actual changes that were introduced by a given merge
# Both commands accept an optional commitish; if ommitted, the last merge commit is used
merge-span = "!f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
merge-log = "!git log `git merge-span .. $1`"
merge-diff = "!git diff `git merge-span ... $1`"
merge-difftool = "!git difftool `git merge-span ... $1`"
@robmiller
robmiller / .gitconfig
Created April 9, 2013 22:38
A git alias to find out what changes were introduced by the last merge.
# usage, e.g.:
# git difftool `git last-merge`
# or:
# git log `git last-merge`
last-merge = "!echo $(git log -1 --merges --pretty=format:%P | cut -d' ' -f1)..$(git log -1 --merges --pretty=format:%P | cut -d' ' -f2)"
@robmiller
robmiller / plugin.php
Last active December 16, 2015 00:48 — forked from joncave/plugin.php
<?php
/* Plugin Name: Damn Vulnerable WordPress Plugin
* Description: Intentionally vulnerable plugin for plugin author education
* Version: 0.1
* Plugin URI: http://make.wordpress.org/plugins/2013/04/09/intentionally-vulnerable-plugin/
* Author: Jon Cave
* Author URI: http://joncave.co.uk
* License: GPLv2+
*
* DO NOT RUN THIS PLUGIN ON AN INTERNET ACCESSIBLE SITE
@robmiller
robmiller / poll.sh
Last active December 15, 2015 06:28
ZSH one-liner to poll every five seconds to see whether a site is updated. Replace "example.com" with your domain, obviously. Relies on your site sending sensible "Age" headers.
while true; do [[ `curl -ILs http://example.com/ | grep 'Age:' | sed 's/Age: //'` < 10 ]] && say "It updated"; sleep 5; done
@robmiller
robmiller / .vimrc
Last active February 18, 2022 11:53
Autoload sessions created by tpope's vim-obsession when starting Vim.
augroup sourcesession
autocmd!
autocmd VimEnter * nested
\ if !argc() && empty(v:this_session) && filereadable('Session.vim') |
\ source Session.vim |
\ endif
augroup END
@robmiller
robmiller / git-cleanup-repo
Last active November 24, 2024 19:55
A script for cleaning up Git repositories; it deletes branches that are fully merged into `origin/master`, prunes obsolete remote tracking branches, and as an added bonus will replicate these changes on the remote.
#!/bin/bash
# git-cleanup-repo
#
# Author: Rob Miller <[email protected]>
# Adapted from the original by Yorick Sijsling
git checkout master &> /dev/null
# Make sure we're working with the most up-to-date version of master.
git fetch