Skip to content

Instantly share code, notes, and snippets.

View jplazcano87's full-sized avatar
💭
Learning

Juan Pablo Lazcano jplazcano87

💭
Learning
  • Santiago, Chile
View GitHub Profile
@jplazcano87
jplazcano87 / gist:70fe49c9102481c96091
Created November 1, 2015 22:25 — forked from edwardmp/gist:a0ffb3ace02ce4392b26
Working example of accepting self-signed SSL certificate in Swift
import UIKit
import Foundation
class ViewController: UIViewController, NSURLSessionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
httpGet(NSMutableURLRequest(URL: NSURL(string: "https://example.com")!))
}
@jplazcano87
jplazcano87 / publishAmazonSnsMsg.py
Created November 5, 2015 18:55 — forked from kylefritz/publishAmazonSnsMsg.py
publish a message to Amazon SNS using python or ruby
from time import strftime,gmtime,time
import urllib2
import hmac
import hashlib
import base64
import string
def publishAmazonSnsMsg(Subject,TopicArn,Message,AWSAccessKeyId,privatekey):
#http://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/
amzsnshost = 'sns.us-east-1.amazonaws.com'
@jplazcano87
jplazcano87 / sns-publish.py
Created November 6, 2015 16:27
Create, Publish and Subscribe Users to AWS SNS topics
import boto.sns
import logging
logging.basicConfig(filename="sns-publish.log", level=logging.DEBUG)
c = boto.sns.connect_to_region("us-east-1")
topicarn = "$TOPIC_ARN"
message = "hello Mr"
message_subject = "trialBotoTRopic"
@jplazcano87
jplazcano87 / SNSTopic.py
Created November 6, 2015 20:10 — forked from stuartmyles/SNSTopic.py
A complete example of how to use Amazon Web Services Simple Notification Services from Python. This code uses the boto library https://github.com/boto/boto to create a topic, wait for a confirmation and then send a success message. Simply plug in your AWS access and secret keys, plus your email and mobile phone number.
# An example of how to use AWS SNS with Python's boto
# By Stuart Myles @smyles
# http://aws.amazon.com/sns/
# https://github.com/boto/boto
#
# Inspired by parts of the Ruby SWF SNS tutorial http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-sns-tutorial-implementing-activities-poller.html
# And the Python SNS code in http://blog.coredumped.org/2010/04/amazon-announces-simple-notification.html and http://awsadvent.tumblr.com/post/37531769345/simple-notification-service-sns
import boto.sns as sns
import json
@jplazcano87
jplazcano87 / CustomColors+UIColor.swift
Last active November 23, 2015 01:04
How to add UIColor extensions in swift
import Foundation
import UIKit
extension UIColor{
//create a class function with the name of the custom color
class func lazcolor() -> UIColor {
return UIColor(red: 190.0/255.0, green: 190.0/255.0, blue: 190.0/255.0, alpha: 1.0)
}
class func grayScaleColor(grayScale : CGFloat) -> UIColor {
@jplazcano87
jplazcano87 / vc.swift
Created December 11, 2015 19:23
show viewcontroller with navigation bar
let storyboard : UIStoryboard = UIStoryboard(name: AccountStoryboard, bundle: nil)
let vc : WelcomeViewController = storyboard.instantiateViewControllerWithIdentifier("WelcomeID") as WelcomeViewController
vc.teststring = "hello"
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: true, completion: nil)
@jplazcano87
jplazcano87 / iOSCreatePDF.swift
Created December 14, 2015 15:16 — forked from nyg/iOSCreatePDF.swift
iOS, Swift: Create a PDF file from an HTML string
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer
import UIKit
// 1. Create a print formatter
let html = "<b>Hello <i>World!</i></b>"
let fmt = UIMarkupTextPrintFormatter(markupText: html)
// 2. Assign print formatter to UIPrintPageRenderer
@jplazcano87
jplazcano87 / createDoneButton.swift
Created December 28, 2015 15:13
Add Done Button to Numeric pad iOS (Swift)
@IBOutlet weak var txtNumber: UITextField!
override func viewDidLoad()
{
super.viewDidLoad()
//--- add UIToolBar on keyboard and Done button on UIToolBar ---//
self.addDoneButtonOnKeyboard()
}
@jplazcano87
jplazcano87 / compres+uiimage.swift
Created December 29, 2015 19:22
Compress image data swift
extension UIImage {
var uncompressedPNGData: NSData { return UIImagePNGRepresentation(self)! }
var highestQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 1.0)! }
var highQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.75)! }
var mediumQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.5)! }
var lowQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.25)! }
var lowestQualityJPEGNSData:NSData { return UIImageJPEGRepresentation(self, 0.0)! }
}
//usage
@jplazcano87
jplazcano87 / cell.md
Created January 11, 2016 13:02
Cell with protocols and generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)