Skip to content

Instantly share code, notes, and snippets.

View PasswordHelpers.cs
public static class PasswordHelpers
private static bool GetPasswordInitialized(DependencyObject obj)
return (bool)obj.GetValue(PasswordInitializedProperty);
private static void SetPasswordInitialized(DependencyObject obj, bool value)
obj.SetValue(PasswordInitializedProperty, value);
View initial tracking
Scenario | Tracking set up
Clone a (non-emtpy) repo, use the branch which is checked out automatically | Y
Push a branch to a remote, that doesn't exist on the remote | N
Push a branch to a remote, that doesn't exist on the remote, with push -u | Y
Checkout a branch from a remote, without -t (specified or implied) | N
Checkout a branch from a remote, with -t (specified or implied) | Y
canton7 / gist:1193421
Created Sep 4, 2011
Different ways of creating new local tracking branches
View gist:1193421

Ways to create a new local branch, tracking a remote branch

Create a new local branch with the same name as the remote one

git checkout <remote_branch_name>
git checkout -t <remote>/<remote_branch_name>

Create a new local branch with a different name to the remote one

canton7 / gist:1339179
Created Nov 4, 2011
Useful git aliases
View gist:1339179

Useful git aliases

Command-line graphical log viewer

This is invaluable if you've managed to get yourself in a muddle.

git config --global alias.graph git log --graph --oneline --decorate --all
canton7 / gist:2146783
Created Mar 21, 2012
View gist:2146783


This is a little monkey-patch to add a new method to Enumerable, #with_props.

You use it something like this:

[1, 2, 3, 4].each.with_props do |element, props|
   puts "First? #{props.first?}"
View multi_loader.rb
class MultiLoader
def initialize(input)
@input = input
def initial_map
@map = {}
@input.each do |host, opts|
if opts.is_a?(String)
View demo.rb
config ='config.ini').load
p config['section.key']
p config.get('section.not_a_key', 'my_default')
p config['section.two.key3']
config['section.key'] = 'hi'
config.set('section.two.key4', 'the_value', 'This is the comment')


So. One of my housemates pranked me, and I decided to get my revenge. My revenge was 100% inspired by upside-down-ternet, and goes as follows:

  1. Linux box running the ruby script below, which acts as a transparent proxy
  2. iptables rules on the linux box route all port 80 requests through the proxy
  3. arp poisoning routes all of the victim's traffic through the linux box
  4. Proxy isn't actually transparent. It intercepts requests for images, and does some processing on them, blurring them and writing a rude word in the middle.
canton7 /
Last active Dec 15, 2015
Golf'd ruby sudoku solver

Assuming a board in the style

b = [
  nil, nil, nil, 3, 9, nil, nil, 1, nil,
  5, nil, 1, nil, nil, nil, nil, 4, nil,
  9, nil, nil, 7, nil, nil, 5, nil, nil,
  6, nil, 2, 5, 3, nil, nil, 7, nil,
  nil, nil, nil, nil, 7, nil, nil, nil, 8,
  7, nil, nil, 8, nil, nil, 9, nil, 3,
canton7 / gist:5780755
Created Jun 14, 2013
Finding files deleted by evil merges
View gist:5780755
The following snippet might help detect evil merges which deleted a file.
$ for rev in `git rev-list --merges HEAD`; do del=`( git diff --name-only --diff-filter=D $rev^ $rev; git diff --name-only --diff-filter=D $rev^2 $rev ) | sort | uniq -u | tr '\n' ' '`; [ -n "$del" ] && echo "$rev $del"; done