Skip to content

Instantly share code, notes, and snippets.

View 29satnam's full-sized avatar
🎯
Focusing

Satnam 29satnam

🎯
Focusing
View GitHub Profile
@29satnam
29satnam / LoginViewController.swift
Last active January 20, 2016 09:33
This is Deployd Swift iOS login implementation with NSURLSession.
let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
import UIKit
import Alamofire
class LoginViewController: UIViewController,UITextFieldDelegate {
@IBOutlet var txtUsername : UITextField!
@IBOutlet var txtPassword : UITextField!
@29satnam
29satnam / bearertoken.swift
Last active January 20, 2016 10:33
To get the current user, send a GET request to /me. Include the sid cookie to identify your session - Depoyd. This is iOS Swift way of doing the same.
let token = prefs.valueForKey("SESSIONID") as? String
let session = NSURLSession.sharedSession()
let url = NSURL(string: "http://xxxxxxxxxx.com:2403/users/me")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "GET"
request.setValue( "Bearer \(token!)", forHTTPHeaderField: "Authorization")
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
if (data != nil) {
let res = response as! NSHTTPURLResponse!;
@29satnam
29satnam / config.json
Created February 6, 2016 16:15
deployd dpd-passport user config.json file
{
"type": "UserCollection",
"properties": {
"socialAccount": {
"name": "socialAccount",
"type": "string",
"typeLabel": "string",
"required": false,
"id": "socialAccount",
"order": 0
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@29satnam
29satnam / GET Example Swift
Created July 16, 2016 10:58
Swift HTTP GET Example
let session = NSURLSession.sharedSession()
let url = NSURL(string: "http://someurl.com")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "GET"
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
if (data != nil) {
let res = response as! NSHTTPURLResponse!;
if 200..<300 ~= res.statusCode {
@29satnam
29satnam / SMTP Block Example Swift iOS
Created July 26, 2016 18:36
SMTP Block Example Swift iOS
var smtpSession = MCOSMTPSession()
smtpSession.hostname = "HOSTNAME"
smtpSession.username = "USERNAME"
smtpSession.password = "PASSWORD"
smtpSession.port = PORT
smtpSession.authType = MCOAuthType.SASLPlain
smtpSession.connectionType = MCOConnectionType.TLS
smtpSession.connectionLogger = {(connectionID, type, data) in
if data != nil {
if let string = NSString(data: data, encoding: NSUTF8StringEncoding){
let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults() //make this global
// Mark: This is how you save.
prefs.setObject("\(someVariable)", forKey: "PORT")
prefs.synchronize()
//Mark: This is how you retrieve saved content.
let retrieve = prefs.valueForKey("PORT") as? String
print(retrieve)
//
// UILabelDeviceClass.swift
//
// Created by MyCandy on 01/01/19.
// Copyright © 2019 Silver Seahog. All rights reserved.
//
import Foundation
import UIKit
@29satnam
29satnam / BottomBorderTextField.swift
Created July 19, 2017 09:40
This is how you can set only Bottom Border to UITextField using Swift 3
class BottomBorderTF: UITextField {
var bottomBorder = UIView()
override func awakeFromNib() {
//MARK: Setup Bottom-Border
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = UIColor.orange
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
@29satnam
29satnam / mailcore2-ios.swift
Created July 25, 2017 10:18
Swift 3 mailcore2-ios Implementation.
var smtpSession = MCOSMTPSession()
smtpSession.hostname = ""
smtpSession.username = ""
smtpSession.password = ""
smtpSession.timeout = 5
smtpSession.port = UInt32(port!)!
smtpSession.authType = MCOAuthType.saslPlain
smtpSession.connectionType = MCOConnectionType.startTLS
smtpSession.connectionLogger = {(connectionID, type, data) in
if data != nil {