Skip to content

Instantly share code, notes, and snippets.

@rothomp3
rothomp3 / singleton.swift
Created October 5, 2015 21:40
Example of building an inheritance-friendly singleton class in Swift
#!/usr/bin/xcrun -sdk macosx swift
import Foundation
public protocol SharedInstanceType
{
init()
}
private struct TokenKey
@rothomp3
rothomp3 / swift-buffer-example.swift
Last active January 1, 2020 17:09
Swift example of writing to memory buffer
let bitmapBuffer = UnsafePointer<UInt8>.alloc(Int(height * width * 4))
let pixelNumber = (x * 4) + (y * width * 4)
bitmapBuffer[pixelNumber + 3] = 255 // Alpha
bitmapBuffer[pixelNumber + 2] = redValue
bitmapBuffer[pixelNumber + 1] = greenValue
bitmapBuffer[pixelNumber + 0] = blueValue
@rothomp3
rothomp3 / objc-buffer-example.m
Created June 6, 2014 14:07
Objective-C way of writing to a memory buffer
uint8_t* bitmapBuffer = calloc(width * height * 4, sizeof(uint8_t));
int pixelNumber = (x * 4) + (y * width * 4);
bitmapBuffer[pixelNumber + 3] = 255; // alpha
bitmapBuffer[pixelNumber + 2] = redValue;
bitmapBuffer[pixelNumber + 1] = greenValue;
bitmapBuffer[pixelNumber + 0] = blueValue;
@rothomp3
rothomp3 / gist:8847626
Created February 6, 2014 16:27
Calling super.super method
Method grannyMethod = class_getClassMethod([[self superclass] superclass], _cmd);
IMP grannyImp = method_getImplementation(grannyMethod);
return grannyImp([self class], _cmd);
//
// AFHTTPRequestOperation+MTSynchronousRequest.h
// MTSyncAFNetworking
//
// Created by Robert Thompson on 10/10/13.
// Copyright (c) 2013 WillowTree Apps. All rights reserved.
//
#import "AFHTTPRequestOperation.h"
@rothomp3
rothomp3 / AFHTTPRequestOperation+MTSynchronousRequest.m
Created October 31, 2013 17:23
Synchronous category on AFNetworking
//
// AFHTTPRequestOperation+MTSynchronousRequest.m
// MTSyncAFNetworking
//
// Created by Robert Thompson on 10/10/13.
// Copyright (c) 2013 WillowTree Apps. All rights reserved.
//
#import "AFHTTPRequestOperation+MTSynchronousRequest.h"
@implementation AFHTTPRequestOperation (MTSynchronousRequest)