Skip to content

Instantly share code, notes, and snippets.

View simonwhitaker's full-sized avatar

Simon Whitaker simonwhitaker

View GitHub Profile
@simonwhitaker
simonwhitaker / show-url.md
Created August 1, 2012 13:00
A Javascript bookmarklet to show the URL for a search results page in Safari 6

Show search results URL in Safari 6

Here's a bookmarklet that'll pop the current search results page's URL open in one of those annoying little JS prompt dialogs.

Show URL

Drag it to your bookmarks bar and click when needed.

The code in a nutshell:

$ grep "\.project" .gitignore
.project
$ git bisect bad
Bisecting: 5 revisions left to test after this (roughly 3 steps)
[85547ec7aa1e9087ed84f09d0f8c603b88377978] Added MIT license text to top of apns.py
$ grep "\.project" .gitignore
$ git bisect good
Bisecting: 11 revisions left to test after this (roughly 4 steps)
[9d17aa48641e3540fbc6a54c26776b45c865887b] unset badge by passing badge=0
$ grep "\.project" .gitignore
@simonwhitaker
simonwhitaker / passwords.md
Created November 15, 2012 16:23
Passwords: Of MD5 and Mistresses

By Simon Whitaker

Errata Security have an interesting post on the hacking of a general's mistress. In it, Robert David Graham looks at how long it would take someone to discover Paula Broadwell's Yahoo! email password based on the hashed copy leaked in an email hack last year. He states:

it'll take 17 hours to crack her password using a GPU accelerator trying 3.5-billion password attempts per second, trying all combinations of upper/lower case and digits.

(My emphasis)

I read that and thought: clearly he's making an assumption here about the (maximum) length of the password. I wonder what the assumption was?

@simonwhitaker
simonwhitaker / ssl_expiry.sh
Created November 30, 2012 22:27
Get the expiry date of a secure website's SSL certificate at the command line
#!/bin/sh
ssl_expiry() {
# Show usage info if not called with a hostname
if [ $# -eq 0 ]; then
echo "Usage: ssl_expiry HOSTNAME"
return 0
fi
domain=$1
@simonwhitaker
simonwhitaker / hashers.py
Last active June 26, 2019 22:07
A Django password hasher that uses SHA512 instead of the default SHA256
import hashlib
from django.contrib.auth.hashers import PBKDF2PasswordHasher
class PBKDF2SHA512PasswordHasher(PBKDF2PasswordHasher):
"""
Alternate PBKDF2 hasher which uses SHA512 instead of SHA256.
Note: As of Django 1.4.3, django.contrib.auth.models.User defines password
with max_length=128
@simonwhitaker
simonwhitaker / GSDismissableViewControllerDelegate.h
Last active December 12, 2015 08:38
A simple protocol for view controllers that want to communicate that they should be dismissed without knowing about how they were presented.
// GSDismissableViewControllerDelegate.h
//
// Created by Simon Whitaker at Goo Software Ltd.
// https://gist.github.com/simonwhitaker/4745057
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol GSDismissableViewControllerDelegate <NSObject>
@simonwhitaker
simonwhitaker / kill-adobe-updater.sh
Created May 15, 2013 11:14
Add this function to your .zshrc or equivalent to get a `kill-adobe-updater` command. Nukes the Adobe Application Manager Updater that creeps onto my menu bar every bloody time I run an Adobe app.
kill-adobe-updater() {
killall "AAM Updates Notifier" 2>/dev/null || echo "AAM Updater not running"
rm ~/Library/LaunchAgents/com.adobe.AAM.Updater-1.0.plist 2>/dev/null || echo "LaunchAgent not found"
}
@simonwhitaker
simonwhitaker / gist:5731617
Last active December 18, 2015 05:18
A sample command-line OSX app for switching the endianness of an input file.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Declare some config values; the input and output file paths and the
// number of bytes per word
NSString *inputFile = @"/Users/simon/Desktop/input.dat";
NSString *outputFile = @"/Users/simon/Desktop/output.dat";
@simonwhitaker
simonwhitaker / postcode-regex.js
Last active December 15, 2023 11:29
An example of using a simplified UK postcode regex in Javascript
var tweet = "Currently chilling out at W1B 2EL, then on to WC2E 8HA or maybe even L1 8JF! :-)";
// Here's a simple regex that tries to recognise postcode-like strings.
// See http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
// for the rules on how UK postcodes are formatted.
var postcode_regex = /[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/g;
var postcodes = tweet.match(postcode_regex);
console.log(postcodes);
import re
tweet = "Currently chilling out at W1B 2EL, then on to WC2E 8HA or maybe even L1 8JF! :-)"
# Here's a simple regex that tries to recognise postcode-like strings.
# See http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
# for the rules on how UK postcodes are formatted.
postcode_regex = '[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}'
postcodes = re.findall(postcode_regex, tweet)