Categories
swift

Loading image from URL with SWIFT

Found this snippet provided by a stackoverflow user helpful. It loads a remote image async. Helps with performance when loading several images over the network to populate your table cells . This snippet extends the UIImageView Class with an added method imageFromURL(urlString:String) extension UIImageView { public func imageFromUrl(urlString: String) { if let url = NSURL(string: […]

Categories
python

Using Python to Automate SSH Connection and Run Commands

We will be using a  http://fitztrev.github.io/shuttle/ and the pexpect python library. Here is what the shuttle menu looks like. Mine could be named better. #!/usr/bin/python from pexpect import * import pexpect PROMPT = [‘# ‘, ‘>>> ‘, ‘> ‘,’\$ ‘] def send_command(child, cmd): child.sendline(cmd) child.expect(PROMPT) print child.before child.interact() def connect(user, host, password): ssh_newkey = ‘Are you […]

Categories
ios swift

Making an HTTP POST Request in Swift

In this example I will be uploading an image to a node.js server. func makePostRequest(){ // create a instantiate a session let session = NSURLSession.sharedSession() // set url to POST to var url = NSURL(string: “http://yourdomain.com/post”) // create the request object var request = NSMutableURLRequest(URL: url!) request.HTTPMethod = “POST” request.HTTPBody = YOUR_REQUEST_BODY // set up the […]