Skip to content

Instantly share code, notes, and snippets.

View shepting's full-sized avatar

Steven Hepting shepting

View GitHub Profile
@shepting
shepting / DataModel.m
Created February 15, 2012 14:57
Data Model
+ (NSString *)appName {
return [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];
}
@shepting
shepting / AFTestSpec.m
Last active August 1, 2017 10:30
Use this Gist to test AFNetworking based network calls. Use the respective client to test the succes: for failure: blocks. Stub and expect to your hearts content.
//
// AFTestSpec.m
@interface AlwaysSucceedClient : AFHTTPClient
@end
@implementation AlwaysSucceedClient
- (void)postPath:(NSString *)path parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure
{
NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:parameters];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
@shepting
shepting / cancellable_block.m
Created January 12, 2013 22:18
Use a captured variable to allow a block to be cancelled in the midst of a long-running process. This is essentially the same as the NSOperation isCancelled flag.
__block BOOL isCancelled = NO;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
for (int i = 0; i < 10; i++) {
NSLog(@"Loop %i", i);
if (isCancelled) {
break;
} else {
sleep(1);
}
}
@shepting
shepting / compile.sh
Created March 29, 2013 18:38
Basic app to exemplify a command-line Objective C app.
#!/usr/bin/env bash
# Compile
clang objc_program.m -o program -ObjC -std=c99 -framework Foundation
# Run
./program
@shepting
shepting / YMKeyboardLayoutHelperView.m
Last active March 22, 2016 02:50
A great little helper for handling keyboard animations nicely. Just put this view at the bottom vertically of your views and it will move everything else up and down for you.
//
// YMKeyboardLayoutHelperView.m
// ios-chat
//
// Created by Steven Hepting on 7/17/13.
// Copyright (c) 2013 Yammer. All rights reserved.
//
#import "YMKeyboardLayoutHelperView.h"
#import "UIView+LayoutAdditions.h"
@shepting
shepting / button_switch.js
Created March 13, 2014 22:24
BeagleBone Black sample button/transistor switch code
var b = require('bonescript');
var switchIn = "P9_21";
var transistorOut = "P9_41";
b.pinMode(transistorOut, b.OUTPUT);
b.pinMode(switchIn, b.INPUT);
setInterval(toggle, 100);
console.log("started");
@shepting
shepting / .lldbinit
Created June 13, 2014 01:10
Sample LLDBInit
# Print all the views in the window
command regex rd 's/^[[:space:]]*$/po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]/' 's/^(.+)$/po [%1 recursiveDescription]/'
# Print all the view controllers in the window
command regex rvc 's/^[[:space:]]*$/po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]/' 's/^(.+)$/po [%1 _viewControllerForAncestor]/'
# Print an autolayout trace
command alias at expr -o -- [[UIWindow keyWindow] _autolayoutTrace]
# Load the dynamic code for Reveal
@shepting
shepting / rot13.swift
Last active August 29, 2015 14:05 — forked from jeremy-w/rot13.swift
Simple ROT13 function
// Playground - noun: a place where people can play
let lettersArray = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
func rot13(input: String) -> String {
return reduce(input, "") { result, letter in
if let i = find(lettersArray, letter) {
return result + lettersArray[i + 13]
} else {
return result + letter
@shepting
shepting / last_two_weeks.sh
Last active August 29, 2015 14:06
Last Two Weeks of Git Commits
git log --author=Steven --since=2.weeks --no-merges --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
@shepting
shepting / rot13.swift
Last active August 29, 2015 14:08 — forked from jeremy-w/rot13.swift
// Playground - noun: a place where people can play
import UIKit
let lettersArray = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
func rot13(input: String) -> String {
return reduce(input, "", { result, letter in
if let i = find(lettersArray, letter) {
return result + String(lettersArray[i + 13])