Skip to content

Instantly share code, notes, and snippets.

@sundeepgupta
sundeepgupta / gist:52741a916118c0486813
Created August 17, 2014 20:16
Setup shadow on UILabel frame
CALayer *layer = self.nameLabel.layer;
layer.shadowColor = [UIColor blackColor].CGColor;
layer.shadowRadius = 3;
layer.shadowOpacity = 0.9;
layer.shadowOffset = CGSizeMake(0.2, 2);
layer.masksToBounds = NO;
@sundeepgupta
sundeepgupta / gist:ef093bfe253c4529c829
Created September 22, 2014 02:57
Rename files in a folder consecutively starting from zero
folder_path = "/Users/sundeepgupta/drive/tmp/sencha icons"
file_paths = Dir.glob(folder_path + "/*")
file_paths.each.with_index do |file_path, idx|
file_extension = File.extname(file_path)
new_file_path = "#{folder_path}/#{idx}#{file_extension}"
File.rename(file_path, new_file_path)
end
@sundeepgupta
sundeepgupta / gist:f137a2a9ebb377936cdd
Created November 12, 2014 18:18
Mogenerator Build Script
cd ${SOURCE_ROOT}/${PROJECT_NAME}
# Installed via Homebrew
if [ -e /usr/local/bin/mogenerator ]
then
/usr/local/bin/mogenerator --template-var arc=true -m Model.xcdatamodeld/Model.xcdatamodel -M Models/Machine -H Models/Human
exit
fi
# Installed via .dmg
@sundeepgupta
sundeepgupta / Custom Zoom Modal Animator for iOS
Last active August 29, 2015 14:12
Zoom modal custom animator for iOS
#import "CCCardDetailTransitionAnimator.h"
- (void)prepareForCardDetailSequeWithCard:(CCCard *)card navigationController:(UINavigationController *)navigationController {
CCCardDetailViewController *destinationVc = (CCCardDetailViewController *)navigationController.viewControllers.firstObject;
[destinationVc configureWithCard:card delegate:self];
navigationController.modalPresentationStyle = UIModalPresentationCustom;
navigationController.transitioningDelegate = self;
}
@sundeepgupta
sundeepgupta / Resizing UIImage using a CGBitmapContext
Last active August 29, 2015 14:13
Resizing UIImage using a CGBitmapContext
CGImageRef imageRef = image.CGImage;
CGSize size = CGSizeMake(110, 110); //From storyboard.
CGRect frame = CGRectMake(0, 0, size.width, size.height);
CGContextRef context = CGBitmapContextCreate(nil, size.width, size.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef), CGImageGetBitmapInfo(imageRef));
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextDrawImage(context, frame, imageRef);
CGImageRef scaledImageRef = CGBitmapContextCreateImage(context);
UIImage *scaledImage = [UIImage imageWithCGImage:scaledImageRef];

Usage

Requirements

Install the two dependencies, ImageMagick and Ghostscript.

$ brew install imagemagick
$ brew install ghostscript
@sundeepgupta
sundeepgupta / Send email through Mandril API from Swift iOS app
Created April 26, 2015 19:14
Send email through Mandril API from Swift iOS app
import Foundation
public struct EmailMemory {
let memory: Memory
let email: String
let success: (() -> ())
let failure: (NSError -> ())
public init(memory: Memory, success: (() -> ()), failure: (NSError -> ())) {
self.memory = memory
@sundeepgupta
sundeepgupta / BeaconIdGenerator.rb
Last active October 4, 2015 17:49
Algorithm to generate the Major and Minor values for the iBeacon spec.
class BeaconIdGenerator
MAX_MAJOR_MINOR = 65536
MAX_VALUE = MAX_MAJOR_MINOR**2 - 1
def self.perform(value)
raise "Value passed in must be an integer." unless value.is_a? Integer
raise "Value passed in must be at least 0." if value < 0
raise "Value passed in must be at most #{MAX_VALUE}" if value > MAX_VALUE
major = (value/MAX_MAJOR_MINOR).floor
@sundeepgupta
sundeepgupta / bash_loop
Created October 22, 2015 13:48
Loop over bash output list.
git branch -r | grep origin/release $1 | while read b; do t=${b:7}; git tag $t $b; done
@sundeepgupta
sundeepgupta / MapView.m
Last active March 29, 2016 02:20
MapView demo
//
// ViewController.m
// Map Hacks
//
// Created by Ken Woo on 2016-02-02.
// Copyright © 2016 Lighthouse Labs. All rights reserved.
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>