Skip to content

Instantly share code, notes, and snippets.

View WayneWeiZhang's full-sized avatar

Wayne Zhang WayneWeiZhang

View GitHub Profile
@rnapier
rnapier / gist:067156ac404cc42f17b6
Created September 7, 2014 18:20
Version 2 of Flattenin' Your Mappenin'
//
// Version 2 of pagesFromData from Flattenin' Your Mappenin'
// http://robnapier.net/flatmap
//
import Foundation
infix operator >>== {}
func >>== <T,U>(x: T, f:T -> Result<U>) -> Result<U> {
return x.flatMap(f)
@implementation NSArray (BadThirdPartyImplementation)
- (id)firstObject
{
return self[0];
}
@end
@Lvt
Lvt / WWDC 2015 Movie Downloader
Last active August 29, 2015 14:22
WWDC 2015 Movie Downloader
Execute in Terminal. This Downloads every Movie in HD
curl -s https://developer.apple.com/videos/wwdc/2015/ | grep "?id=" | sed "s/.*id\=/curl\ \-s https:\/\/developer\.apple\.com\/videos\/wwdc\/2015\/\\\?id\=/"\ | sed "s/\".*/\| grep HD \| sed \"s\/.*\<a href\\\\=\\\\\"\/\/\"\| sed \"s\/\\\\\".\*\/\/\" /" | sh | sed "s/http/curl \-C \- \-O \"http/" | sed "s/\?dl\=1/\"/" | grep http | sh
Not working any more
@alexsporn made the script better
static id _commonInit(MyView *self)
{
// common init stuff like so...
self.opaque = YES;
self->_scale = 1.0;
return self;
}
- initWithFrame:(CGRect)frame;
@sserye
sserye / UIImage+Retina4.h
Created September 14, 2012 03:27 — forked from bstahlhood/UIImage+Retina4.h
Swizzled UIImage imageNamed for iPhone 5
//
// UIImage+Retina4.h
// StunOMatic
//
// Created by Benjamin Stahlhood on 9/12/12.
// Copyright (c) 2012 DS Media Labs. All rights reserved.
//
#import <UIKit/UIKit.h>
@natecook1000
natecook1000 / DictionaryObjectsForKeys.swift
Last active December 9, 2015 18:43
Initializers for Dictionary like NSDictionary +dictionaryWithObjects:forKeys:
// (c) 2015 Nate Cook, licensed under the MIT license
//
// Initializers for Dictionary like NSDictionary +dictionaryWithObjects:forKeys:
public extension Dictionary {
/// Creates a new Dictionary from the given `keys` and `values` collections.
///
/// More efficient than the sequence version because it can reserve the correct
/// capacity before filling the dictionary. Returns `nil` if the lengths of the
/// two collections differ.
@steipete
steipete / AppDelegate.m
Last active December 13, 2015 17:29
Hook onto NSNotificationCenter to see all notifications.
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"%@: %@", note.name, note.userInfo);
}];
@irace
irace / gist:5216137
Last active December 15, 2015 06:28
Core Data migrations are hard. If you don't need to migrate, then don't! Here's how:
/*
Core Data is great but automatic migrations can be tricky. Migrations can take a long time, which could
result in [your app being terminated](http://stackoverflow.com/questions/13333289/core-data-timeout-adding-persistent-store-on-application-launch)
if it is happening on the main thread during application launch. Performing migrations on a background
thread is also a [bad idea](http://stackoverflow.com/a/2866725/503916), meaning your application really
needs to be able to fully launch *without a Core Data stack whatsoever* in order to safely migrate.
This can be a huge change to make to an existing app.
If you're really only using Core Data as a cache, you don't actually *need* to perform a migration.
Simply check if the existing store is compatible with your managed object model and if so, delete
@jaybaird
jaybaird / gist:6003951
Last active December 19, 2015 19:09
Binary Tree with NSArray
#import <Foundation/Foundation.h>
@interface Node : NSObject
@property (nonatomic) NSInteger identifier;
@property (nonatomic, copy) NSString *value;
+ (Node *)nodeWithIdentifier:(NSInteger)identifier value:(NSString *)value;
@end
@implementation Node
+ (Node *)nodeWithIdentifier:(NSInteger)identifier value:(NSString *)value {
@kgn
kgn / cleanup_images.py
Created September 8, 2013 22:10
Python script to cleanup unused images from an iOS app
import os
import re
import sys
projectRoot = sys.argv[1]
imageNamedRegex = re.compile('Named:@"([^"]+)"')
resourceRegEx = re.compile('<string key="NSResourceName">([^<]+)</string>')
def rootImageName(imageName):
imageName = re.sub('.png$', '', imageName)