This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Table based object with method | |
| function newPerson(name) | |
| local M = { | |
| name = name, | |
| age = 0, | |
| } | |
| M.greet = function (self) | |
| print ("This is " .. self.name .. ", I am " .. self.age) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local composer = require( "composer" ) | |
| local scene = composer.newScene() | |
| -- include Corona's "physics" library | |
| local physics = require "physics" | |
| function scene:create( event ) | |
| -- Called when the scene's view does not exist. | |
| -- | |
| -- INSERT code here to initialize the scene |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // An extension to Optional type: | |
| // getOrElse() will return optional's value if exists, otherwise the default value provided as argument will be returned. | |
| // | |
| // Note: Since Xcode6 beta 5, you can use '??' operator. | |
| // | |
| // (c) Tomek Cejner 2014 | |
| // @tomekcejner | |
| extension Optional { | |
| func getOrElse(val:T) -> T { | |
| if self != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang=""> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title></title> | |
| <link rel="stylesheet" href=""> | |
| <style type="text/css"> | |
| * { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution to ultimate Swift Nija challenge | |
| // http://www.raywenderlich.com/77845/swift-ninja-part-2 | |
| enum Suit { | |
| case Clubs, Diamonds, Hearts, Spades | |
| } | |
| enum Rank { | |
| case Jack, Queen, King, Ace | |
| case Num(Int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - Core Data stack | |
| lazy var applicationDocumentsDirectory: NSURL = { | |
| // The directory the application uses to store the Core Data store file. This code uses a directory named "net.japko.EmptyCoreDataSwiftProject" in the application's documents Application Support directory. | |
| let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) | |
| return urls[urls.count-1] as NSURL | |
| }() | |
| lazy var managedObjectModel: NSManagedObjectModel = { | |
| // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //: Playground - noun: a place where people can play | |
| // 1. Create new iOS playground | |
| // 2. Paste this code | |
| // 3. Enable timeline slider (on Utilities panel, alt+cmd+0 to show) | |
| // 4. After letting the animation play, move the slider :) | |
| import UIKit | |
| import XCPlayground |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Disable pixel smoothing | |
| display.setDefault( "magTextureFilter", "nearest" ) | |
| -- Physics debugging: place in scene file in global scope | |
| physics.setDrawMode( "hybrid" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local M = {} | |
| function M.create() | |
| -- initialize members: M.foo = "bar" | |
| end | |
| function M.foo() | |
| end | |
| return M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // npm install bluebird | |
| // npm install superagent | |
| // | |
| var Promise = require('bluebird'); | |
| var request = require('superagent'); | |
| console.log('Promises with Bluebird'); | |
| function get(url) { |