Skip to content

Instantly share code, notes, and snippets.

Avatar

Lars Anderson larsacus

View GitHub Profile
View keybase.md

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:

View CSPlaceKitten.podspec
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'
@larsacus
larsacus / ObjectivePotter.mm
Last active Dec 11, 2015
Objective-Potter
View ObjectivePotter.mm
HWWand *wand = [[HWWand alloc] init];
HWMagic *magic = [HWSpell genericSpell];
[wand setMagic:(__bridge HWSpell *)magic];
View PauseCAAnimation.m
-(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 / round.m
Created Dec 16, 2011
Round corner without clipsToBounds
View round.m
// Clips the bottom left corner to a radius
CGSize cornerSize = CGSizeMake(10,10);
UIBezierPath *roundRectMaskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:cornerSize];
CAShapeLayer *roundRectMaskLayer = [CAShapeLayer layer];
roundRectMaskLayer.frame = self.view.bounds;
roundRectMaskLayer.path = roundRectMaskPath.CGPath;
@larsacus
larsacus / EagerPNG.m
Created Nov 14, 2011
"Eager" image deserialization - not mine - not sure where I found it - or how useful it may be...
View EagerPNG.m
UIGraphicsBeginImageContextWithOptions(size,YES,0.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *deserializedImage = UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
@larsacus
larsacus / PDF2UIImage.m
Created Nov 14, 2011
Render PDF document to UIImage
View PDF2UIImage.m
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 / mach_timer.mm
Created Nov 14, 2011
High-Resolution Timer Using Mach Time
View mach_timer.mm
#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 / NIL_Termination.h
Created Oct 25, 2011
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
View NIL_Termination.h
- (id)initWithTitle:(NSString *)title
delegate:(id)delegate
animationImages:(UIImage *)firstImage, ...NS_REQUIRES_NIL_TERMINATION;
@larsacus
larsacus / ViewControllerWithAd.m
Created Sep 13, 2011
LARSAdController - Create Ad in View with View Controller
View ViewControllerWithAd.m
- (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];
}