Skip to content

Instantly share code, notes, and snippets.

@mattrubin
mattrubin / WeakClassProtocol.swift
Last active August 12, 2017 21:13
Swift weak var of protocol type (No @objc required)
import UIKit
// A swift protocol can apply to a class, struct, or enum,
// but only a reference type can be stored in a `weak` var,
// so a weak var cannot be of a typical protocol type.
protocol MyProcotol {
}
@mattrubin
mattrubin / gist:dd2b43c0ad3f8acfc09b
Created January 23, 2015 23:10
Get every password in the keychain
+ (NSArray *)allKeychainItems
{
NSDictionary *queryDict = @{(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitAll,
(__bridge id)kSecReturnPersistentRef: (id)kCFBooleanTrue,
(__bridge id)kSecReturnAttributes: (id)kCFBooleanTrue,
(__bridge id)kSecReturnData: (id)kCFBooleanTrue
};
CFTypeRef result = NULL;
@mattrubin
mattrubin / measure_website_response.sh
Created November 17, 2011 18:37
Measures the response time of a web page
#!/bin/bash
CURL="/usr/bin/curl"
GAWK="/usr/bin/awk"
echo -n "Please pass the url you want to measure: "
read url
echo " Time_Connect Time_startTransfer Time_total "
while [ true ]
do
URL="$url"
result=`$CURL -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
@mattrubin
mattrubin / website_response_times
Created November 17, 2011 18:29
Website response times
Time_Connect Time_startTransfer Time_total
0.607 74.332 74.586 ***
0.462 1.051 1.310
0.127 0.878 1.129
0.134 0.902 1.156
0.096 0.173 0.173
0.131 0.695 0.954
0.127 0.528 0.793
0.127 0.570 0.835
0.126 0.689 0.944
@mattrubin
mattrubin / Hide Google Plus Notifications
Created July 22, 2011 13:21
Instructions for using user stylesheets to hide the Google Plus notifications count
Step 1. Download and install a browser extension that allows you to apply user styles to a page.
For Safari:
http://code.grid.in.th/
For Chrome:
https://chrome.google.com/webstore/detail/fjnbnpbmkenffdnngjfgmeleoegfcffe
For Firefox:
https://addons.mozilla.org/en-US/firefox/addon/stylish/