Skip to content

Instantly share code, notes, and snippets.

View mitchellporter's full-sized avatar

Mitchell Porter mitchellporter

  • Seattle, WA
View GitHub Profile
@mitchellporter
mitchellporter / ResponseParser.swift
Created July 25, 2016 22:30 — forked from NSExceptional/ResponseParser.swift
A simple class to automate the parsing of an NSURLSessionTask response.
import Foundation
typealias ResponseParserBlock = (ResponseParser) -> Void
class ResponseParser {
// MARK: Response information
private(set) var response: NSHTTPURLResponse?
private(set) var data: NSData?
/**
`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 {
@mitchellporter
mitchellporter / jason.m
Created July 7, 2016 21:57
audio snippet
- (void) audioPCMFrameWasCaptured:(nonnull const AudioStreamBasicDescription *)pcmASBD bufferList:(nonnull const AudioBufferList *)bufferList time:(CMTime)time sampleRate:(Float64)sampleRate {
int16_t *fdata = bufferList->mBuffers[0].mData;
for (int i = 0; i < bufferList->mBuffers[0].mDataByteSize/sizeof(*fdata); i++) {
*fdata = (int16_t)(*fdata * 0.1);
@mitchellporter
mitchellporter / struct_vs_inheritance.swift
Created July 4, 2016 19:05 — forked from AliSoftware/struct_vs_inheritance.swift
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
@mitchellporter
mitchellporter / README.md
Created June 23, 2016 06:03 — forked from joyrexus/README.md
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@mitchellporter
mitchellporter / restAPI.markdown
Created June 3, 2016 05:52 — forked from iksose/restAPI.markdown
Creating a REST API using Node.js, Express, and MongoDB

###Creating a REST API using Node.js, Express, and MongoDB

####Installing Node.js

Go to http://nodejs.org, and click the Install button. Run the installer that you just downloaded. When the installer completes, a message indicates that Node was installed at /usr/local/bin/node and npm was installed at /usr/local/bin/npm. At this point node.js is ready to use. Let’s implement the webserver application from the nodejs.org home page. We will use it as a starting point for our project: a RESTful API to access data (retrieve, create, update, delete) in a wine cellar database.

Create a folder named nodecellar anywhere on your file system. In the wincellar folder, create a file named server.js.

@mitchellporter
mitchellporter / CustomLayerPropertyAnimationPropagation.swift
Created May 31, 2016 18:59
Propagating Custom Property Animation Addition and Removal to Sublayers
//
// In this custom layer, changes to a "highlightedPercentage" key will switch between showing normal and highlighted image views.
// In addition, the size of the layer itself changes depending on these image views as well. This layer needs to fully support atomic,
// model changes to this property as well as animated changes to this key without forcing main thread-bound view layout calls on
// every frame of animated changes.
//
//
// CATransaction.begin()
// CATransaction.setDisableActions(true)
@mitchellporter
mitchellporter / shannon
Created May 25, 2016 19:27
layer anim
UIView.animateWithDuration(1.0) {
// Option 1: Animate the player layer
playerLayer.frame = toViewController.view.bounds
// Option 2: playerLayer is a sublayer of the container view
containerView.frame = toViewController.view.bounds
}
@mitchellporter
mitchellporter / Podfile
Created May 25, 2016 18:09
Podfile template
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
link_with 'APP_NAME_GOES_HERE'
platform :ios, '8.0'
inhibit_all_warnings! # These are all tweaks that were required once all of the Swift issues starting popping up
target 'APP_NAME_GOES_HERE' do
pod 'Parse'
pod 'KGHitTestingViews'
pod 'Device'
@mitchellporter
mitchellporter / gist:5ff7f8f257e518e80394571816f2d694
Created May 19, 2016 00:02 — forked from rsaunders100/gist:6094708
Core image rendering on a EAGLContext
// View controller is a subclass of GLKViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.ciContext = [CIContext
contextWithEAGLContext:self.eaglContext