Skip to content

Instantly share code, notes, and snippets.

View simonwhitaker's full-sized avatar

Simon Whitaker simonwhitaker

View GitHub Profile
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(uint32_t, SomeOption) {
SomeOptionNone = 0,
SomeOptionFoo = 1 << 0,
SomeOptionBar = 1 << 1,
};
int main(int argc, char *argv[]) {
@autoreleasepool {
@simonwhitaker
simonwhitaker / git-is-ancestor
Last active April 5, 2022 08:01
A script to determine whether one git commit is the ancestor of another
#!/bin/bash
#
# git-is-ancestor, by Simon Whitaker
#
# Suggested usage
#
# Store this file somewhere, make it executable, then alias
# it to git is-ancestor by putting this in your $HOME/.gitconfig:
#
# [alias]
@simonwhitaker
simonwhitaker / enumeration-benchmark.m
Created July 2, 2013 06:30
A simple benchmarking experiment to compare enumeration techniques in Objective-C. My results are in the comments.
#import <Foundation/Foundation.h>
void timeThis(NSString *label, NSUInteger iterations, void(^block)()) {
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
for (NSUInteger i = 0; i < iterations; i++) {
block();
}
CFAbsoluteTime interval = CFAbsoluteTimeGetCurrent() - start;
printf("%s: %lu iterations, %.3fs\n", [label UTF8String], iterations, interval);
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)
@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);
@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 / 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 / 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 / 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 / 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