Skip to content

Instantly share code, notes, and snippets.

@justin-nodeboy
justin-nodeboy / CustomError.js
Last active April 9, 2017 17:37
Custom Error using ES6 Javascript
class CustomError extends Error {
//Extend the super class, in this case the standard Error object
constructor(message){
super(message);
this.name = this.constructor.name;
}
}
module.exports = CustomError;
@justin-nodeboy
justin-nodeboy / SwiftProfileImage.swift
Created February 14, 2016 10:26
A little extension to UIImageView which makes a nice circular profile pic
extension UIImageView {
func resizeForProfilePic(){
self.layer.borderWidth = 1
self.layer.masksToBounds = false
self.layer.borderColor = UIColor.blackColor().CGColor
self.layer.cornerRadius = self.frame.height/2
self.clipsToBounds = true
}
}
@justin-nodeboy
justin-nodeboy / Extensions.swift
Last active February 14, 2016 17:10
A couple of useful extensions that I found online for Downloading a remote image and setting a hex colour code in Swift
extension UIImageView {
func downloadImageFrom(link link:String, contentMode: UIViewContentMode) {
NSURLSession.sharedSession().dataTaskWithURL( NSURL(string:link)!, completionHandler: {
(data, response, error) -> Void in
dispatch_async(dispatch_get_main_queue()) {
self.contentMode = contentMode
if let data = data { self.image = UIImage(data: data) }
}
}).resume()
}
@justin-nodeboy
justin-nodeboy / Helpers.swift
Last active February 13, 2016 18:48
Some little Swift helper functions for dealing with dates.
//Use as follows
//let dateHelper = Helpers()
//let dateString: String = row["dateString"] as! String
//label.text = dateHelper.getFormattedDate(dateString)
import Foundation
class Helpers: NSObject {
func getFormattedDate(date: String) -> String{
@justin-nodeboy
justin-nodeboy / api.js
Last active September 9, 2015 07:13
A simple API function for calling an endpoint in Titanium, see demo.js for usage
/**
Use this function to make calls to a JSON REST API see demo.js for useage
@param options
@param end (Callback)
**/
exports.api = function(options, end) {
//This function makes calls to an Endpoint and then sends the data back via callback to the function that requested it.
//Alloy.CFG.conn_url is set in your config.json file and can be accessed depending on which environment you are using.
var method = options.method,