Skip to content

Instantly share code, notes, and snippets.

View JayachandraA's full-sized avatar
🎯
Focusing

Jayachandra Agraharam JayachandraA

🎯
Focusing
View GitHub Profile
extension UIImage {
/// Returns a image that fills in newSize
func resizedImage(newSize: CGSize) -> UIImage {
// Guard newSize is different
guard self.size != newSize else { return self }
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0);
self.draw(in: CGRect(x:0, y:0, width:newSize.width, height:newSize.height))
let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
#import <Foundation/Foundation.h>
@interface NSDate (Formatted)
- (NSString*)dateStringByFormatted:(NSString*)formate;
@end
//check twitter services/account availability
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
let composer = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
//set sharing text
composer?.setInitialText(message)
//add image you want to share
composer?.add(image)
//check twitter services/account availability
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
let composer = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
//set sharing text
composer?.setInitialText(message)
//add image you want to share
composer?.add(image)
func showAlert(title: String, message: String){
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let ok = UIAlertAction(title: "Ok", style: .default) { (action) in
}
alert.addAction(ok)
present(alert, animated: true, completion: nil)
}
extension UILabel{
func dynamicHeight() -> CGFloat {
let label = UILabel(frame: self.bounds)
label.numberOfLines = self.numberOfLines
label.lineBreakMode = self.lineBreakMode
label.font = self.font
label.text = self.text
label.sizeToFit()
return label.frame.size.height
}
//create object
let alertController = UIAlertController(title: "Login ✉︎", message: "Please enter your username/email and password.", preferredStyle: .alert)
// create action object
// which can be used to handle the different action when user tapped on any one of them
let okAction = UIAlertAction(title: "Ok", style: .default) { (action) in
//handle ok button action
print("ok button tapped")
}
func performLogin(alertController: UIAlertController) {
guard let textFields = alertController.textFields else { return }
var params = [String:String]()
for textField in textFields{
if textField.placeholder == "Enter username"{
params["username"] = textField.text
}
if textField.placeholder == "Enter password"{
params["password"] = textField.text
}
//create object
let alertController = UIAlertController(title: "Share ♂", message: "Share the your content on social media.", preferredStyle: .actionSheet)
// create action objects
// which can be useed to handle the different action when user tapped on any one of them
let facebookAction = UIAlertAction(title: "Facebook", style: .default) { (action) in
//handle facebook button action
print("facebook button tapped")
self.performLogin(alertController: alertController)
}
@JayachandraA
JayachandraA / US zip (postal) codes.json
Last active June 14, 2017 02:45
->JSON data set of projects funded by the World Bank (436K compressed). JSON data set for US zip (postal) codes (656K compressed).
[
{
"city": "AGAWAM",
"loc": [
-72.622739,
42.070206
],
"pop": 15338,
"state": "MA",
"_id": "01001"