Skip to content

Instantly share code, notes, and snippets.

Mattt mattt

Block or report user

Report or block mattt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am mattt on github.
  • I am mattt (https://keybase.io/mattt) on keybase.
  • I have a public key whose fingerprint is 58FC 9E3A 40F3 5F72 E402 F6C0 2755 0012 282D EB01

To claim this, I am signing this object:

View multipart-http-basic.m
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"Pa55w0rd"]
NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
[manager POST:@"http://example.com/resources.json" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:filePath name:@"image" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
View asciiwwdc-scraper.rb
require 'open-uri'
require 'nokogiri'
year = 2014
doc = Nokogiri::HTML(open("https://developer.apple.com/videos/wwdc/#{year}/"))
doc.search("p.download").each do |download|
href = download.at("a").attr('href')
uri = URI(href)
uri.path = uri.path.split('/')[0...-1].join('/') + '/'
View interrobang.swift
postfix operator {}
postfix func (value: Bool) -> Bool {
return arc4random_uniform(2) == 0
}
prefix operator {}
prefix func (value: Bool) -> Bool {
return value
}
@mattt
mattt / もじれつ.swift
Last active Aug 29, 2015
Terrible misuse of Swift literal convertibles to automatically create Hiragana transliteration of string value.
View もじれつ.swift
struct もじれつ: Printable {
let description: String
init(string: String) {
var mutableString = NSMutableString(string: string) as CFMutableString
if CFStringTransform(mutableString, nil, kCFStringTransformLatinHiragana, 0) == 1 {
self.description = mutableString as NSString
} else {
self.description = string
}
View phones.rb
module Keats
module Phones
IPA_CONSONANTS = {
"B" => "b", # b - Lower-case B <be> voiced bilabial plosive
"CH" => "t\312\203", # tʃ - T-Esh ligature <cheese> voiceless postalveolar affricate
"D" => "d", # d - Lower-case D <dee> voiced dental or alveolar plosive
"DH" => "\303\260", # ð - Eth <thee> voiced dental fricative
"F" => "f", # f - Lower-case F <fee> voiceless labiodental fricative
"G" => "g", # g - Lower-case G <green> voiced velar plosive
"HH" => "h", # h - Lower-case H <he> voiceless glottal fricative
@mattt
mattt / rocket.md
Created May 27, 2015
Rocket: a hybrid approach to real-time cloud applications
View rocket.md

This document was originally posted on 8/1/2013.

Rocket is a technique for building real-time functionality on top of REST web services that leverages web standards like [Server-Sent Events][SSE] and [JSON Patch][RFC6902]. Most importantly, it fits comfortably with how you're already building applications.

A Tale of Two Paradigms

Just as light can act as both a particle and a wave, so information can be thought as both a document and a stream.

Each approach has its particular strengths and weaknesses:

View NSAssertionHandler.m
/** NSAssertionHandler - Object encapsulation of assertions
Copyright (C) 1995, 1997 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: Apr 1995
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
View NSHipster-New-Years-2014.md

Greetings, NSHipsters!

As we prepare to increment our NSDateComponents -year by 1, it's time once again for NSHipster end-of-the-year Reader Submissions! Last year, we got some mind-blowing tips and tricks. With the release of iOS 7 & Mavericks, and a year's worth of new developments in the Objective-C ecosystem, there should be a ton of new stuff to write up for this year.

Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see:

  • Using NSStringFromSelector(@selector()) as a safer way to do KVC / KVO / NSCoding.
  • Panic's [rather surprising discovery about the internals of the Lightning Digital AV Adapter](http://www.panic.com/blog/the-lightning-di
@mattt
mattt / UIImageForSwatchOfColorWithSize.h
Created Sep 27, 2013
Create a UIImage swatch of a color with a specified size.
View UIImageForSwatchOfColorWithSize.h
static UIImage * UIImageForSwatchOfColorWithSize(UIColor *color, CGSize size) {
UIImage *image = nil;
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
{
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(c, [color CGColor]);
You can’t perform that action at this time.