Skip to content

Instantly share code, notes, and snippets.

View simonwhitaker's full-sized avatar

Simon Whitaker simonwhitaker

View GitHub Profile
@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 / migrate-to-sublime-text.sh
Created July 1, 2012 12:46
Flip your TextMate file type associations to use Sublime Text 2 instead
#!/bin/sh
# Quick and dirty script to flip all the file type currently
# associated with TextMate to be associated with Sublime Text 2
# instead.
#
# DISCLAIMER: worked for me, might not work for you. Use at your
# own risk. I accept no responsibility if you trash your system.
# Specify the plist file we need to tweak
@simonwhitaker
simonwhitaker / Local Host Privacy Notice.md
Last active February 5, 2023 22:34
Local Host Privacy Notice

Privacy Notice for Local Host

Local Host doesn't collect any of your data. Nothing.

  • It does not connect to any external services
  • It does not show ads
  • It does not attempt to monetise you in any way.

I hope you enjoy Local Host! If you have any questions about this privacy notice, drop me a line on hi@s1mn.io and I'll be happy

Take-home coding exercise: ShiftAdd

When completing the exercise, please consider the following:

  1. Allow no more than 3 hours to complete the exercise. (Mostly because I find it useful to set a limit, otherwise the temptation to just make one more change can be endless!)
  2. It's fine to use any resources that you could use in your job; Google, Stack Overflow, etc. But the code you submit should be your own.
  3. We use Python a lot at Shift Lab, so solutions in Python are preferred.
  4. Please include documentation explaining how to run your code

Specification

Python: Type Aliases vs New Types

If you're a fan of Python type hinting, you may have noticed that there are two different ways to create your own types: type aliases and using the NewType helper.

Type aliases look like this:

Vector = list[float]
@simonwhitaker
simonwhitaker / convert-ext-to-uti.m
Created March 22, 2012 09:48
Lists the UTIs for a given list of file extensions
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
#import <libgen.h>
/*
convert-ext-to-uti
Shows the Uniform Type Identifier(s) (UTI) for a
file type based on its file extension. Output is
a tab-separated tuple of (extension, UTI) per
@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 / 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

Setting up Pi-hole on Raspbian Stretch

Prepare your Pi

First off, you need a Raspberry Pi running the latest version of Raspbian ("Stretch"). If you don't already have a Pi, I really like this kit for £49 from Amazon. Once you have your Pi, grab the latest copy of Raspbian Stretch Lite and flash it to an SD card using Etcher. (That kit on Amazon comes with an SD card.)

Enable SSH

With the SD card still attached to your computer, create a file in the root of the SD card called ssh. The contents can be blank. On a Mac, you can do this easily in the Terminal app:

#include <stdio.h>
#include <Accelerate/Accelerate.h>
void print_matrix(const double *matrix, int rows, int cols) {
// for debugging
for (int i = 0; i < rows * cols; i++) {
printf("%.2f", matrix[i]);
if (i % cols == cols - 1) {
printf("\n");
} else {