Skip to content

Instantly share code, notes, and snippets.

View santoshrajan's full-sized avatar

Santosh Rajan santoshrajan

View GitHub Profile
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
println(view.frame)
view.backgroundColor = UIColor.lightGrayColor()
let view1 = UIView(frame: CGRectMake(100, 50, 100, 100))
@santoshrajan
santoshrajan / JSONParseDictionary.swift
Last active August 29, 2015 14:07
JSON Parse Dictionary in Swift
// Author - Santosh Rajan
import Foundation
let string = "{\"name\": \"John\", \"age\": 35, \"children\": [\"Jack\", \"Jill\"]}"
func JSONParseDictionary(jsonString: String) -> [String: AnyObject] {
if let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
if let dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: nil) as? [String: AnyObject] {
return dictionary
@santoshrajan
santoshrajan / JSONParseArray.swift
Last active November 30, 2019 18:49
JSON Parse Array in Swift
// Author - Santosh Rajan
import Foundation
let string = "[ {\"name\": \"John\", \"age\": 21}, {\"name\": \"Bob\", \"age\": 35} ]"
func JSONParseArray(jsonString: String) -> [AnyObject] {
if let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
if let array = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: nil) as? [AnyObject] {
return array
@santoshrajan
santoshrajan / JSONStringify.swift
Created October 12, 2014 05:36
JSON Stringify in Swift
// Author - Santosh Rajan
import Foundation
let jsonObject: [AnyObject] = [
["name": "John", "age": 21],
["name": "Bob", "age": 35],
]
func JSONStringify(value: AnyObject, prettyPrinted: Bool = false) -> String {
@santoshrajan
santoshrajan / 1kmarkdown
Last active April 4, 2017 05:54
Markdown Parser in 1k of JavaScript
var fs = require("fs"),
src = fs.readFileSync(process.argv[2], 'utf8')
// createParser and createBodyParser creates parsers. A parser takes a string,
// and if successful returns an array of two elements. The object representation
// of consumed portion and the remainder of of the string. If failure returns null.
var markdownParser = createBodyParser("markdown",
createParser('newline', /^(\n+)/),
createParser('h1', /^# ([^\n]+)/),
@santoshrajan
santoshrajan / sequence.ls
Created September 13, 2012 16:23
A LispyScript example using sequenced callbacks.
;; http://lispyscript.com
;; LispyScript sequenced callback example
;; No need for nested callbacks. Just write your callbacks in a sequence and pass "(next)" as
;; your callback, which will set the next function in the sequence as your callback.
;;
;; This example is a simple node server that will serve static plain text file to the browser.
;;
(var fs (require "fs"))
(var http (require "http"))
@santoshrajan
santoshrajan / server.ls
Created August 11, 2012 05:52
A LispyScript Server example with nodejs, expressjs, twitter bootstrap
;; http://lispyscript.com
;; LispyScript example using nodejs, expressjs and twitter bootstrap
;; LispyScript templates are written in LispyScript!
;; Html5 templates support all html5 tags
;; The express server
(var express (require "express"))
(var app (express))
(app.listen 3000)