Skip to content

Instantly share code, notes, and snippets.

View arvindhsukumar's full-sized avatar

Arvindh Sukumar arvindhsukumar

View GitHub Profile
snapShotter.startWithCompletionHandler { (snapshot:MKMapSnapshot?, error:NSError?) in
let image = snapshot?.image
}
let mapSnapshotOptions = MKMapSnapshotOptions()
// Set the region of the map that is rendered.
let location = CLLocationCoordinate2DMake(37.332077, -122.02962) // Apple HQ
let region = MKCoordinateRegionMakeWithDistance(location, 1000, 1000)
mapSnapshotOptions.region = region
// Set the scale of the image. We'll just use the scale of the current device, which is 2x scale on Retina screens.
mapSnapshotOptions.scale = UIScreen.mainScreen().scale
let dispatch_group: dispatch_group_t = dispatch_group_create()
func startRequests(){
asyncFunctionA()
asyncFunctionB()
dispatch_group_wait(dispatch_group, DISPATCH_TIME_FOREVER) // Wait forever! or set a reasonable default for timeout
}
func alsoStartRequests(){
asyncFunctionA()
@arvindhsukumar
arvindhsukumar / this_is_bad.swift
Last active April 7, 2016 15:15
Introduction to dispatch_group
func asyncFunctionA(){
let urlRequest: NSURLRequest = ...
let task = self.session?.dataTaskWithRequest(urlRequest, completionHandler: {
(data:NSData?, response:NSURLResponse?, error:NSError?) in
self.taskAComplete = true
self.checkResults()
})
}
#import <Foundation/Foundation.h>
#import "PASConstants.h"
#import "PASViewController.h"
@interface PASHideDetailAnimator : NSObject <UIViewControllerAnimatedTransitioning>
@end
@implementation PASHideDetailAnimator
@arvindhsukumar
arvindhsukumar / gist:1459405
Last active September 28, 2015 15:37
Wikipedia auto-link generator for Rails
#app/helpers/application_helper.rb
def wikify(text)
text.gsub!(/(\<wp\>(.*?)\<\/wp\>)/) do |m|
n = m.gsub!(/(\<wp\>|<\/wp\>)/, '')
link_to(n, "http://en.wikipedia.org/wiki/#{n}")
end
end
@arvindhsukumar
arvindhsukumar / gist:1450798
Created December 9, 2011 08:56
Facebook Feed Dialog Helper for Rails
# app/helpers/application_helper.rb
# In your View, simply call fb_share with options. app_id and redirect_uri are mandatory.
# For more details, please see http://www.behindtechlines.com/2011/12/09/facebook-feed-dialog-rails/
module ApplicationHelper
def fb_share(app_id, redirect_uri, opts={})
o = {:text => 'Share',
:name => '',