Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
sdpjswl / NSManagedObjectContext+Convenience.h
Created April 18, 2016 03:10
Helper methods for working with Core Data
//
// NSManagedObjectContext+Convenience.h
// ResidentPortal
//
// Created by Prashant Patil on 18/06/14.
// Copyright (c) 2014 Property Solutions. All rights reserved.
//
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
@sdpjswl
sdpjswl / PEM files
Last active November 19, 2016 12:31
PEM files
cert:
openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
key:
openssl pkcs12 -nocerts -nodes -out key.pem -in key.p12
source:
// node.js
http://stackoverflow.com/questions/1762555/creating-pem-file-for-apns
@sdpjswl
sdpjswl / UIImage shadow
Created June 17, 2015 06:22
Add a shadow to a UIImage
- (UIImage *)imageWithShadow {
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGFloat imageWidth = self.size.width;
CGFloat imageHeight = self.size.height;
CGContextRef shadowContext = CGBitmapContextCreate(NULL, imageWidth, imageHeight, CGImageGetBitsPerComponent(self.CGImage), 0, colourSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colourSpace);
CGContextSetShadowWithColor(shadowContext, CGSizeMake(1, -1), 3, [UIColor greenColor].CGColor);
@sdpjswl
sdpjswl / Resized cap image
Created June 11, 2015 08:41
Example of how to use "resizableImageWithCapInsets" method of UIImage
- (void)setResizedImageNamed:(NSString *)imageName {
UIEdgeInsets insets = UIEdgeInsetsMake(0, 50, 0, 5);
UIImage *image = [UIImage imageNamed:imageName];
UIImage *buttonImage = [image resizableImageWithCapInsets:insets];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
}
- (void)centerButtonAndImageWithSpacing:(CGFloat)spacing {
CGFloat insetAmount = spacing / 2.0;
self.imageEdgeInsets = UIEdgeInsetsMake(0, -insetAmount, 0, insetAmount);
self.titleEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, -insetAmount);
self.contentEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, insetAmount);
}
@sdpjswl
sdpjswl / Execution time
Last active August 29, 2015 14:20
Handy macro to log method execution time
declare private function in 'libdispatch':
uint64_t dispatch_benchmark(size_t count, void (^block)(void));
and use it like so:
size_t const objectCount = 1000;
uint64_t n = dispatch_benchmark(10000, ^{
@autoreleasepool {
id obj = @42;
@sdpjswl
sdpjswl / UILabel+PreferredWidth.h
Created April 28, 2015 11:30
Category to get preferred maximum layout width for multiline labels
//
// UILabel+PreferredWidth.h
// GooglePlacesDemo
//
// Created by sudeep on 28/04/15.
// Copyright (c) 2015 Sudeep Jaiswal. All rights reserved.
//
@import UIKit;
@sdpjswl
sdpjswl / Remove .DS_Store
Created April 15, 2015 04:59
Remove .DS_Store files from a directory
find . -name '*.DS_Store' -type f -delete
@sdpjswl
sdpjswl / CALayer+IBColor.h
Created April 11, 2015 10:32
Set border and shadow color with runtime attributes on xib / storyboard
//
// CALayer+IBColor.h
// FunWithRuntimeAttributes
//
// Created by Mike Woelmer on 5/13/14.
// Copyright (c) 2014 atomicobject. All rights reserved.
//
@import UIKit;
@import QuartzCore;
@sdpjswl
sdpjswl / UIImage+Colorize.h
Last active August 29, 2015 14:18
Replace color of a UIImage with another color
//
// UIImage+Colorize.h
// Coderwall
//
// Created by Coderwall on 11/04/15.
// Copyright (c) 2015 Coderwall. All rights reserved.
//
#import <UIKit/UIKit.h>