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 - Swift networking examples | |
| import Cocoa | |
| import Foundation | |
| import XCPlayground | |
| XCPSetExecutionShouldContinueIndefinitely() // this allows async requests to finish in the Playground | |
| // Example of NSURLSession. This is the preferred way of creating web/socket conenctions for Apple programs | |
| var request = NSMutableURLRequest(URL: NSURL(string: "http://www.google.com")!) |
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
| let N = 30 | |
| var fib = [Int](count: N, repeatedValue: 1) | |
| for i in 2..<N { | |
| fib[i] = fib[i-1] + fib[i-2] | |
| } | |
| for number in fib { | |
| println(number) | |
| } |
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
| let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT | |
| dispatch_async(dispatch_get_global_queue(priority, 0)) { | |
| // do some task | |
| dispatch_async(dispatch_get_main_queue()) { | |
| // update some UI | |
| } | |
| } | |
| # Create wrapper to execute blocks in bacground | |
| func dispatch_to_main_queue(block: dispatch_block_t?) { |
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
| let nums = [1, 6, 3, 9, 4, 6]; | |
| let numMax = nums.reduce(Int.min) { max($0, $1) } | |
| minElement(numbers) // 1 | |
| maxElement(numbers) // 9 |
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
| defmodule Life do | |
| @docmodule """ | |
| This program simulates John Conway's "Game of Life" | |
| on a small board of size 8x8 cells. The default board executes | |
| a "glider" that runs from the top left to the bottom right of the board. | |
| The board does not wrap around to the top/bottom or sides. | |
| The primary data structure is a list of lists (8x8), which contains | |
| the board representation. Coords are [row, col]: [0,0] ... [0,7] | |
| ... ... |
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
| defmodule SudokuSolver do | |
| def cell(scheduler) do | |
| send scheduler, { :ready, self } | |
| cell_loop(scheduler, [], ["1","2","3","4","5","6","7","8","9"]) | |
| end | |
| defp cell_loop(scheduler, loc, val) do | |
| receive do | |
| { :loc, location } -> |
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
| ;; | |
| ;; Source code originally from "Clojure Programming" (2012) by Chas Emerick, Brian Carper and Christophe Grand | |
| ;; | |
| (ns mandelbrot.core | |
| (:import java.awt.image.BufferedImage | |
| (java.awt Color RenderingHints))) | |
| (defn- escape | |
| "Returns an integer indicating how many iterations were required | |
| before the value of z (using the components `a` and `b`) could |
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
| (ns primes.core) | |
| ;; Taken from clojures.contrib.lazy-seqs | |
| ; primes cannot be written efficiently as a function, because | |
| ; it needs to look back on the whole sequence. Contrast with | |
| ; fibs and power-of-2 which only need a fixed buffer of 1 or 2 | |
| ; previous values. | |
| ;; primes - based on the \"naive\" implemention described in [1] plus a | |
| ; small \"wheel\" which eliminates multiples of 2, 3, 5, and | |
| ; 7 from consideration by incrementing past them. Also inspired |
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
| ;; | |
| ;; Source code originally from "Clojure Programming" (2012) by Chas Emerick, Brian Carper and Christophe Grand | |
| ;; | |
| (ns gol.core | |
| (:gen-class)) | |
| (defn neighbors | |
| "find our cell neighbors" | |
| [[x y]] | |
| (for [dx [-1 0 1] dy [-1 0 1] :when (not= 0 dx dy)] |
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
| // | |
| // ViewController.swift | |
| // SwiftLife | |
| // | |
| // Created by Nick Brandaleone on 6/1/15. | |
| // Copyright (c) 2015 Nick Brandaleone. All rights reserved. | |
| // | |
| import UIKit |
OlderNewer