Skip to content

Instantly share code, notes, and snippets.

import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var rootVC: UINavigationController? = nil
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
@robmathers
robmathers / groupBy.js
Created October 25, 2018 23:18
A more readable and annotated version of the Javascript groupBy from Ceasar Bautista (https://stackoverflow.com/a/34890276/1376063)
var groupBy = function(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce(function(storage, item) {
// get the first instance of the key by which we're grouping
var group = item[key];
// set `storage` for this instance of group to the outer scope (if not empty) or initialize it
storage[group] = storage[group] || [];
@robmathers
robmathers / ImageColourMask.swift
Last active July 13, 2018 22:03 — forked from omz/gist:1102091
Swift UIImage extension to create arbitrarily-colored icons from a black-with-alpha master image
//
// ImageColourMask.swift
//
// Created by Rob Mathers on 2018-07-13.
// Swift version of https://gist.github.com/omz/1102091/e03982f00ecc34be6c40aedcb0932ed374992741
// Original Objective-C version by Marco Arment and Ole Zorn
//
// Usage example:
// let maskedImage = UIImage(named: "test")?.maskedImage(color: UIColor.blue)
@robmathers
robmathers / port_forwarding.sh
Last active August 28, 2018 15:35
Improved version of the Private Internet Access port forwarding script with better cross-platform support
#!/usr/bin/env bash
#
# Enable port forwarding when using Private Internet Access
#
# Usage:
# ./port_forwarding.sh
error( )
{
echo "$@" 1>&2
@robmathers
robmathers / Re-Fireballer
Last active August 29, 2015 14:22
Sample output from a script to test old Daring Fireball links
-----
Daring Fireball: Pepper Author Maarten Hekkelman
http://daringfireball.net/2002/08/pepper_author_maarten_hekkelman
-----
12 links found
3 links OK
3 redirects OK:
"http://www.hekkelman.com/": http://www.hekkelman.com/ -> "Hekkelman Programmatuur" http://www.hekkelman.net
@robmathers
robmathers / linkstats.md
Last active August 29, 2015 14:07
Further statistics on John Siracusa's OS X Yosemite Review

Some further stats on the links (excluding links to sections of the article, and promotional links, i.e. eBooks/Ars subscriptions) in John Siracusa's OS X Yosemite review.

There are 406 total links, of which 362 are unique.

Top three link destinations (71% of total links):

  1. Ars Technica: 146
  2. Wikipedia: 96
  3. Apple: 45
  • developer.apple.com: 32
@robmathers
robmathers / gist:676c26bf605d5b2fbb71
Created July 22, 2014 02:08
accidentalbot: Links Can Get Mixed in With Titles sample html
<html><head>
<title>Showbot — Liss is More</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0">
<link rel="stylesheet" type="text/css" href="/css/site.css">
<link rel="alternate" type="application/rss+xml" title="Liss is More" href="http://www.caseyliss.com/rss">
<link rel="icon" type="image/png" href="http://www.caseyliss.com/images/favicon.png">
<link rel="apple-touch-icon" href="http://www.caseyliss.com/images/favicon.png">
<script async="" src="//www.google-analytics.com/analytics.js"></script><script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@robmathers
robmathers / feed.xml
Last active August 29, 2015 13:58
Gist for verynicewebsite.net feed that hasn't updated in Feedbin since March 27 (as of April 6, 2014). Bug report for Feedbin.
<?xml version="1.0" encoding="UTF-8"?><feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:lang=""
xml:base="http://verynicewebsite.net/wp-atom.php"
>
<title type="text">John Moltz&#039;s Very Nice Web Site</title>
<subtitle type="text"></subtitle>
<updated>2014-04-05T17:01:27Z</updated>
@robmathers
robmathers / handbrakechapters.py
Created September 6, 2013 21:16
Converts a OGG format chapters to csv format for use with Handbrake. Uses stdin/stdout for easy use with other command-line utilities.
#!/usr/bin/env python
from sys import stdin, stdout
import re
pattern = re.compile("CHAPTER0*(\\d+)=[\\d:\\.]+\\nCHAPTER0*\\1NAME=(.*)$", flags = re.MULTILINE)
replacement = "\\1,\\2"
input = stdin.read()
output = pattern.sub(replacement, input)
@robmathers
robmathers / mkvconverter.py
Created July 16, 2013 03:05
Converts mkvs with h.264 video into m4v containers. Needs mp4box, mediainfo, ffmpeg and probably some other command line tools installed (most of which should be installable via homebrew).
#!/usr/bin/env python
import sys
import os
import subprocess
from pymediainfo import MediaInfo
from glob import glob
import shlex
from fractions import Fraction
import ssatosrt