Skip to content

Instantly share code, notes, and snippets.

View santoshrajan's full-sized avatar

Santosh Rajan santoshrajan

View GitHub Profile
@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
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.backgroundColor = UIColor.lightGrayColor()
var hLayout = HorizontalLayout(height: 200)
hLayout.backgroundColor = UIColor.cyanColor()
view.addSubview(hLayout)
class HorizontalLayout: UIView {
var xOffsets: [CGFloat] = []
init(height: CGFloat) {
super.init(frame: CGRectMake(0, 0, 0, height))
}
required init(coder aDecoder: NSCoder) {
class VerticalScreenLayout: VerticalLayout {
init() {
super.init(width: UIScreen.mainScreen().bounds.width)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
class VerticalFitLayout: VerticalLayout {
override init(width: CGFloat) {
super.init(width: width)
}
required init(coder aDecoder: NSCoder) {
@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"))
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.backgroundColor = UIColor.lightGrayColor()
var vLayout = VerticalLayout(width: view.frame.width)
vLayout.backgroundColor = UIColor.cyanColor()
view.addSubview(vLayout)
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 / 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)
@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]+)/),