Skip to content

Instantly share code, notes, and snippets.

View robinhayward's full-sized avatar

Robin Hayward robinhayward

View GitHub Profile
@robinhayward
robinhayward / gist:7372570
Last active December 27, 2015 18:49
NSLayoutContraint
NSArray *myConstraints = [NSLayoutConstraint RCH_constraintsWithCompleteVisualFormat:@"H:|-60-[self]| * V:|[self]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(self, self.superview)];
+ (NSArray *)RCH_constraintsWithCompleteVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views
{
NSMutableArray *constraints = [NSMutableArray arrayWithCapacity:0];
NSArray *markers = @[@"H:", @"V:"];
NSArray *parts = [format componentsSeparatedByString:@"*"];
for (NSString *formatStringPart in parts) {
for (NSString *markerString in markers) {
NSInteger marker = [formatStringPart rangeOfString:markerString].location;
@robinhayward
robinhayward / IconGenerator.sh
Last active September 24, 2015 08:43
iOS App Icon Generation
#!/bin/bash
f=$(pwd)
rm -rf Output
mkdir Output
# iTunes
sips --resampleWidth 1024 "${f}/${1}" --out "${f}/Output/iTunesArtwork.png"
# App
@robinhayward
robinhayward / Generics.swift
Last active October 29, 2015 17:26
Playing around with generics
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let observer = NumberGeneratorObserver()
observer.generatedNumber = { (number) in
print("Observed: \(number)")
}
let generator = NumberGenerator()
generator.addObserver(observer)
@robinhayward
robinhayward / CleanDesktop.bash
Last active January 5, 2016 16:29
Clean Desktop
// Go clean
// Removes all the icons from your desktop and prevents you adding any
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
// Go back to normal
defaults write com.apple.finder CreateDesktop -bool true && killall Finder
@robinhayward
robinhayward / format.sh
Created April 14, 2021 14:16 — forked from PH9/format.sh
SwiftLint - That run only on modified (new, changes, cached, staged) files
#!/bin/bash
#
# Run SwiftLint
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
SWIFT_FORMAT=/usr/local/bin/swiftformat
if [[ -e "${SWIFT_LINT}" ]]; then
[nostalgia retain]