Skip to content

Instantly share code, notes, and snippets.

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);
}
@canton7
canton7 / initial tracking
Created May 20, 2011 20:20
Tracking in Git
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
canton7 / gist:1193421
Created September 4, 2011 20:06
Different ways of creating new local tracking branches

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
canton7 / gist:1339179
Created November 4, 2011 11:50
Useful git aliases

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
canton7 / gist:2146783
Created March 21, 2012 13:07
Enumerable#with_props

Enumerable#with_props

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?}"
@canton7
canton7 / multi_loader.rb
Created April 20, 2012 17:05
Rack MultiLoader
class MultiLoader
def initialize(input)
@input = input
initial_map
end
def initial_map
@map = {}
@input.each do |host, opts|
if opts.is_a?(String)
config = IniParser.new('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')
config.save
@canton7
canton7 / 0_readme.md
Created April 17, 2012 17:30
Penisnet

Penisnet

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
canton7 / 0main.md
Last active December 15, 2015 01:09
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
canton7 / gist:5780755
Created June 14, 2013 09:58
Finding files deleted by evil merges
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