Skip to content

Instantly share code, notes, and snippets.

View mitchellporter's full-sized avatar

Mitchell Porter mitchellporter

  • Seattle, WA
View GitHub Profile
@skunkworks
skunkworks / NPClientAPI.h
Last active August 29, 2015 14:05
Using AFNetworking 2.0 and Mantle for some hot RESTful JSON action
@interface NPClientAPI : AFHTTPSessionManager
- (instancetype)initWithBaseURL:(NSString *)baseURL;
/**
Singleton object.
*/
+ (NPClientAPI *)sharedAPI;
/**
@onmyway133
onmyway133 / SimpleCache.m
Last active September 26, 2015 19:47
SimpleCache.m
// CacheItem.h
@interface CacheItem : RLMObject
@property NSString *key;
@property NSData *value;
@end
// CacheItem.m
@implementation CacheItem
@codeswimmer
codeswimmer / ios_coreanimation_eggs.m
Created January 7, 2012 20:44
iOS: Core Animation Example: eggs falling out of a tree
// Core Animation Example: eggs falling out of a tree
// This was glommed from iphonedevsdk: http://www.iphonedevsdk.com/forum/iphone-sdk-development/65632-animation-sample-code-our-newest-app.html
// This is the main animation routine.
- (IBAction) doorEasterEggAction;
{
//treeDoorImageView
CATransform3D theTransform;
UIImageView* anEgg;
@btoews
btoews / twilio_data.json
Created April 15, 2014 12:36
Country codes and Twilio deliverability rates
{
"Afghanistan": {
"country_code": "+93",
"deliverability_rate": 77
},
"Albania": {
"country_code": "+355"
},
"Algeria": {
"country_code": "+213",
#include <stdio.h>
#include <string.h>
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy);
float buffx[3];
float buffy[3];
main()
{
buffx[0] = 1.0; buffy[0] = 1.0;
@chrishulbert
chrishulbert / MyButton.m
Last active December 5, 2015 09:41
UIButton subclass
// How to subclass UIButton, given that it uses a static constructor so you can't override init.
@interface MyButton : UIButton
...
@end
@implementation MyButton
+ (instancetype)buttonWithType:(UIButtonType)buttonType {
MyButton *button = [super buttonWithType:buttonType];
@yoshimin
yoshimin / gist:670e2d551cb9afcd8cd4
Created September 17, 2014 16:48
AVPlayerで動画を再生
// サンプル動画のパスを取得
let bundle = NSBundle.mainBundle()
let url: NSURL = NSBundle.mainBundle().URLForResource("sample", withExtension: "mp4")!
// 動画のパスを指定してplayerItemを生成
self.playerItem = AVPlayerItem(URL: url)
// 上で生成したplayerItemを指定してplayerを生成
self.videoPlayer = AVPlayer(playerItem: self.playerItem)
import UIKit
/*
I'm not sure why `@NSCopying` doesn't seem to be copying the object in the example below.
I'm attempting to write code that follows the "initialization with a configuration object" pattern, like `NSURLSession`.
Ideally the configuration would be a struct, but since I'm still interoperating with Obj-C that's not an option.
*/
class Foo : NSObject, NSCopying {
var bar = "bar"
// the cell creation logic
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UVLVideoCell *videoCell = (UVLVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UVLVideoCell class]) forIndexPath:indexPath];
NSInteger index = 1 + indexPath.item%2;
NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"flak_0%i", index] withExtension:@"mp4" subdirectory:@"videos"];
[videoCell loadVideoURL:sampleURL];
return videoCell;
@nickoneill
nickoneill / ZebraPrinter.swift
Created July 17, 2016 17:53
Too many enums?
/**
`ZebraPrinterStatus` is a list of status responses we handle from the printer or during a connection attempt with the printer.
*/
enum ZebraPrinterStatus {
case Ready
case NotReady([ZebraPrinterError])
case Unknown
func message() -> String {
switch self {