Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / lab2rgb.fsh
Created December 29, 2014 23:55
lab2rgb.fsh
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
vec3 lab2xyz(vec3 c) {
float fy = (c.x + 16.0) / 116.0;
float fx = c.y / 500.0 + fy;
float fz = fy - c.z / 200.0;
return vec3( 95.047 * ((fx > 0.206897) ? fx * fx * fx : (fx - 16.0 / 116.0) / 7.787),
@jhurliman
jhurliman / rgb2lab.fsh
Created December 29, 2014 23:53
rgb2lab.fsh
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
vec3 rgb2xyz(vec3 c) {
vec3 tmp;
tmp.x = (c.r > 0.04045) ? pow( (c.r + 0.055) / 1.055, 2.4) : c.r / 12.92;
tmp.y = (c.g > 0.04045) ? pow( (c.g + 0.055) / 1.055, 2.4) : c.g / 12.92;
tmp.z = (c.b > 0.04045) ? pow( (c.b + 0.055) / 1.055, 2.4) : c.b / 12.92;
// List all font families and font names in iOS
for (NSString *familyName in UIFont.familyNames) {
NSLog(@"%@", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@" %@", fontName);
}
}
@jhurliman
jhurliman / UIViewController+SegueData.m
Last active August 29, 2015 14:07
UIViewController+SegueData.m
//
// UIViewController+SegueData.h
// SegueDataPassing - Helper method for performing a segue and passing data to
// the destination view controller.
//
// Created by John Hurliman on 10/21/14.
// Copyright (c) 2014 John Hurliman. Released under the MIT license.
// http://opensource.org/licenses/MIT
//
@jhurliman
jhurliman / objc-pre-post-loops.asm
Last active August 29, 2015 14:04
LLVM does not care about your C optimizations
## for (int i = 0; i < 10; i++) { }
LBL1:
cmpl $10, -4(%ebp) ## -4(%ebp) is the stack address of i. Check if it is less than 10
jge LBL3 ## If the previous compare had a greater than or equal to result, exit the loop
jmp LBL2 ## Otherwise, jump to the next address (this instruction will get optimized away)
LBL2:
movl -4(%ebp), %eax ## Load i into the EAX register (where the arithmetic happens!)
addl $1, %eax ## Add 1 to the EAX register
movl %eax, -4(%ebp) ## Copy the EAX register back on to the stack at the address for i.
@jhurliman
jhurliman / const.c
Created June 29, 2014 05:27
Quick explanation of how to read const declarations in C-based languages
const char *s; // read as "s is a pointer to a char that is constant"
char c;
char *const t = &c; // read as "t is a constant pointer to a char"
@jhurliman
jhurliman / compileconcatenation.m
Created June 28, 2014 08:04
Compile-time string concatenation in Objective-C
#ifdef DEBUG
#define kAPIEndpointHost @"http://example.dev"
#else
#define kAPIEndpointHost @"http://www.example.com"
#endif
#define kAPIEndpointLatest (kAPIEndpointHost @"/api/latest_content")
#define kAPIEndpointMostPopular (kAPIEndpointHost @"/api/most_popular")
@jhurliman
jhurliman / init.m
Created June 28, 2014 08:00
init method in Objective-C
- (id)init
{
if (self = [super init]) {
}
return self;
}
@jhurliman
jhurliman / singleton.m
Created June 28, 2014 07:57
Singleton pattern in Objective-C
+ (instancetype)sharedInstance {
static id instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
import UIKit
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
let locationManager: CLLocationManager = CLLocationManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {