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
def render_index_template(choice='simple'): | |
return render_template( | |
"index.html", | |
script_list = script_list, | |
default=choice) |
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
func dictionaryBytesToInts() -> [String:UInt8] { | |
var D: [String:UInt8] = [:] | |
let chars = "0123456789abcdef".characters.map { String($0) } | |
for k1 in chars { | |
for k2 in chars { | |
let i = chars.indexOf(k1)! | |
let j = chars.indexOf(k2)! | |
D[k1+k2] = UInt8(i*16 + j) | |
} | |
} |
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
import Foundation | |
let n = 256 | |
let a = Array(0..<n).map { UInt8($0) } | |
let data = NSData(bytes: a, length: a.count) | |
print(data) // "<0001...feff>" | |
let stream = NSInputStream(data: data) | |
stream.open() |
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
// we can easily write map, filter or reduce | |
// for a particular data type | |
extension Array { | |
func mmap(transform: Int -> Int) -> [Int] { | |
var ret: [Int] = [] | |
for Element in self { | |
ret.append(transform(Element as! Int)) | |
} | |
return ret |
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
import Foundation | |
public class Speaker { | |
public init() { | |
} | |
public func speak() -> String { | |
return "woof" | |
} | |
public func testSpeaker() { | |
Swift.print("woof") |
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
import Cocoa | |
import SpeakerFramework | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
@IBOutlet weak var window: NSWindow! | |
func applicationDidFinishLaunching(aNotification: NSNotification) { | |
let sp = Speaker() | |
sp.speak() |
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
import Cocoa | |
import SpeakerFramework | |
class MainWindowController: NSWindowController { | |
@IBOutlet weak var labelTextField: NSTextField! | |
override func windowDidLoad() { | |
super.windowDidLoad() | |
let sp = Speaker() |
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
import Cocoa | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
@IBOutlet weak var window: NSWindow! | |
var mainWindowController: MainWindowController? | |
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
int f1(int); | |
int f2(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
import Foundation | |
func doIt() { | |
let s = "The quick brown fox jumps over the lazy dog." | |
let n = Int(CC_MD5_DIGEST_LENGTH) | |
let len = CC_LONG(s.utf8.count) | |
let ctx = UnsafeMutablePointer<CC_MD5_CTX>.alloc(1) | |
var digest = Array<UInt8>(count:n, repeatedValue:0) |
OlderNewer