Skip to content

Instantly share code, notes, and snippets.

View larsacus's full-sized avatar

Lars Anderson larsacus

View GitHub Profile

Keybase proof

I hereby claim:

  • I am larsacus on github.
  • I am larsacus (https://keybase.io/larsacus) on keybase.
  • I have a public key whose fingerprint is 4F0E 87B0 42E0 8CDE 01DE C310 AB95 DD3F 493A C413

To claim this, I am signing this object:

@larsacus
larsacus / FetchIOSModelCode.m
Created August 17, 2011 16:21
Fetches exact model code of iOS device for logging
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString *)hardwareDeviceModelCode{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
@larsacus
larsacus / ViewControllerWithAd.m
Created September 13, 2011 20:14
LARSAdController - Create Ad in View with View Controller
- (void)viewWillAppear:(BOOL)animated{
[[LARSAdController sharedManager] addAdContainerToView:[self view] withViewController:self];
[[LARSAdController sharedManager] setGoogleAdPublisherId:myPublisherId]; //change publisher id unless you want me to have your monies
[[LARSAdController sharedManager] layoutBannerViewsForCurrentOrientation:self.interfaceOrientation];
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[[LARSAdController sharedManager] layoutBannerViewsForCurrentOrientation:toInterfaceOrientation];
}
@larsacus
larsacus / NIL_Termination.h
Created October 25, 2011 17:30
Enumerate a list of object specified in a prototype with NS_REQUIRES_NIL_TERMINATION. From http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
- (id)initWithTitle:(NSString *)title
delegate:(id)delegate
animationImages:(UIImage *)firstImage, ...NS_REQUIRES_NIL_TERMINATION;
@larsacus
larsacus / mach_timer.mm
Created November 14, 2011 20:43
High-Resolution Timer Using Mach Time
#include "mach/mach_time.h" //NOT #import
mach_timebase_info_data_t mach_info;
mach_timebase_info(&mach_info);
uint64_t start = mach_absolute_time();
//do stuff to time
uint64_t finish = mach_absolute_time() - start;
@larsacus
larsacus / PDF2UIImage.m
Created November 14, 2011 20:49
Render PDF document to UIImage
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"pdf_name" ofType:@"pdf"];//this is assuming the pdf is in the main bundle
NSInteger pageNumber = 1;//for a one-page PDF
CGSize containerSize = self.imageView.bounds.size;
UIGraphicsBeginImageContext(containerSize);
CGContextRef context = UIGraphicsGetCurrentContext();
const char *pdfFileName = [pdfPath cStringUsingEncoding:NSASCIIStringEncoding];
CGDataProviderRef pdfDataProvider = CGDataProviderCreateWithFilename(pdfFileName);
CGPDFDocumentRef myDocument = CGPDFDocumentCreateWithProvider(pdfDataProvider);
@larsacus
larsacus / EagerPNG.m
Created November 14, 2011 21:52
"Eager" image deserialization - not mine - not sure where I found it - or how useful it may be...
UIGraphicsBeginImageContextWithOptions(size,YES,0.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *deserializedImage = UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
@larsacus
larsacus / PauseCAAnimation.m
Created January 10, 2012 15:46
Pauses and resumes all CA Animations on a CALayer - from http://developer.apple.com/library/ios/#qa/qa1673/_index.html
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
@larsacus
larsacus / ObjectivePotter.mm
Last active December 11, 2015 17:39
Objective-Potter
HWWand *wand = [[HWWand alloc] init];
HWMagic *magic = [HWSpell genericSpell];
[wand setMagic:(__bridge HWSpell *)magic];
Pod::Spec.new do |s|
s.name = 'CSPlaceKitten'
s.version = '0.0.1'
s.summary = 'Automatically place adorable kittens as place holder images on your image views.'
s.description = 'A place kitten category on top of the awesome UIImageView+AFNetworking category that will automatically place adorable kittens as place holder images on your image views.'
s.homepage = 'https://github.com/cnstoll/CSPlaceKitten'
s.license = {:type => 'MIT'}
s.author = {'Conrad Stoll' => 'cnstoll@me.com'}
s.requires_arc = true
s.platform = :ios, '5.0'