Skip to content

Instantly share code, notes, and snippets.

View kevinvanderlugt's full-sized avatar

Kevin VanderLugt kevinvanderlugt

View GitHub Profile
@kevinvanderlugt
kevinvanderlugt / gist:08144bc587788d3f8e95
Created April 14, 2015 11:22
Generating a random A-Z character in swift
let uppercaseLetters = Array(65...90).map {String(UnicodeScalar($0))}
func randomLetter() -> String {
let randomIndex = arc4random_uniform(UInt32(uppercaseLetters.count))
return uppercaseLetters[Int(randomIndex)]
}
@kevinvanderlugt
kevinvanderlugt / gist:701c1a0c4caa73a147c5
Last active August 29, 2015 14:06
Fixing so that GameCenter wont cause a rejection if not using gamecenter
// In MenuViewController.m replace
[[GameCenterManager sharedManager] authenticateLocalPlayer];
// With
if(kImplementGameCenter)
{
[[GameCenterManager sharedManager] authenticateLocalPlayer];
}
self.leaderboardButton.hidden = !kImplementGameCenter;
// Replace this line (at line 169 for me but might be different for you)
if(self.gameScore == 0)
// With this line
if(self.gameScore == 0 && !self.gameTimer)
// Replace
[self.gameTimer invalidate];
self.gameTimer = nil;
// With
dispatch_async(dispatch_get_main_queue(), ^{
[self.gameTimer invalidate];
self.gameTimer = nil;
});
@kevinvanderlugt
kevinvanderlugt / gist:5a42fc3188e4ea22209b
Last active August 29, 2015 14:02
Playing around with Swift to implement a Queue that can take any object type
class Queue {
var items: Array<AnyObject> = []
// Add an object to the tail of the queue
func enqueue(object: AnyObject) {
items += object;
}
// Remove the head of the queue and return the object
func dequeue() -> AnyObject? {
@kevinvanderlugt
kevinvanderlugt / EmailSubscribeViewController.h
Created May 27, 2014 06:58
EmailSubscribeViewController to allow users in iOS applications to signup to a MailChimp Email List. This is a companion to my blog post http://kevinvanderlugt.github.io/ios-mailing-list-mailchimp/
#import <UIKit/UIKit.h>
@interface EmailSubscribeViewController : UIViewController <UITextFieldDelegate>
@end
@kevinvanderlugt
kevinvanderlugt / gist:5548914
Created May 9, 2013 17:08
Creating bootable USB drive from iso.
# sometimes creates it as .img.dmg if so just mv *.img.dmg to *.img
hdiutil convert /path/to/.iso -format UDRW -o /path/to/target.img
# determine the mount *generally for me /dev/disk2*
diskutil list
# unmount the disk where N is the disk number
diskutil unmountDisk /dev/diskN
# write the img to the usb disk
@kevinvanderlugt
kevinvanderlugt / Benchmark.rb
Last active December 17, 2015 02:29
Ruby sort and sort_by benchmarks for reverse sorting an array of random integers. Just for curiosity, run on your machine to verify
require 'benchmark'
array = []
1000.times {
array << rand(100)
}
sort_count = 10_000
default_sort_time = Benchmark.realtime do
@kevinvanderlugt
kevinvanderlugt / gist:4723492
Created February 6, 2013 15:54
Concurrent enumeration over dictionary
[dict enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id key, id object, BOOL *stop) {
NSLog(@"%@ = %@", key, object);
}];
@kevinvanderlugt
kevinvanderlugt / gist:4590732
Last active December 11, 2015 10:59
Set a row to uppercase on select of a tableview row
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize strings;
- (void)viewDidLoad