Skip to content

Instantly share code, notes, and snippets.

@mattt
mattt / alfred-wwdc.url
Last active September 25, 2018 10:01
Alfred ASCIIwwdc Web Search
alfred://customsearch/Search%20WWDC%20Sessions/wwdc/utf8/noplus/http://asciiwwdc.com/search?q={query}

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 / UTTypeForImageData.m
Created March 27, 2014 23:19
A quick function for determining an image's file type by its first couple of bytes
@import MobileCoreServices;
static CFStringRef UTTypeForImageData(NSData *data) {
const unsigned char * bytes = [data bytes];
if (data.length >= 8) {
if (bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47 && bytes[4] == 0x0D && bytes[5] == 0x0A && bytes[6] == 0x1A && bytes[7] == 0x0A) {
return kUTTypePNG;
}
}
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('/') + '/'
@kongtomorrow
kongtomorrow / gist:e95bea13162ca0e29d4b
Last active August 31, 2022 16:20
Y combinator in Swift!
/* The Y combinator in Swift!
For a discussion of what the heck this is all about, see http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html
The nifty thing is that it allows us to implement recursion without the ability for a function to refer to itself from within its own definition.
Note how we manage a recursive definition of factorial without any function referring to its own name.
Thanks to @eridius for help with the SelfToUnderlying<T> type.
*/
@mattt
mattt / もじれつ.swift
Last active August 29, 2015 14:05
Terrible misuse of Swift literal convertibles to automatically create Hiragana transliteration of string value.
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
}
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
}

ASCIIwwdc Viewing Statistics

June 1, 2014 – September 15, 2014

Percentage of total visits for sessions among the top 100 pages on ASCIIwwdc.

Initial Takeaways

  • Vast majority of views for 2014 sessions, as might be expected
  • Top 6 most-watched session all involve view controllers & Interface Builder (accounting for 1/4 of total traffic)
  • "What's New in X" sessions are extremely popular
@mattt
mattt / nshipster-new-years-2015.md
Created November 25, 2014 19:38
NSHipster New Year's 2015

Season's Greetings, NSHipsters!

As the year winds down, and we take a moment to reflect on our experiences over the past months, one thing is clear: 2014 has been an incredible year professionally for Apple developers. So much has happened in such a short timespan, and yet it's hard to remember our relationship to Objective-C before Swift, or what APIs could have captivated our imagination as much as iOS 8 or WatchKit.

It's an NSHipster tradition to ask you, dear readers, to send in your favorite tips and tricks from the past year for publication over the New Year's holiday. This year, with the deluge of new developments—both from Cupertino and the community at large—there should be no shortage of interesting tidbits to share.

Submit your favorite piece of Swift or 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!

If you're wondering about what to post, look to