Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View telliott99's full-sized avatar

Tom Elliott telliott99

View GitHub Profile
def render_index_template(choice='simple'):
return render_template(
"index.html",
script_list = script_list,
default=choice)
@telliott99
telliott99 / dictionaryBytesToInts.swift
Created December 7, 2015 17:48
Dictionary to go from a String like "ff" to a UInt8 like 255
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)
}
}
@telliott99
telliott99 / bytes.swift
Last active October 11, 2023 13:07
convert NSData -> [UInt8]
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()
// 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
import Foundation
public class Speaker {
public init() {
}
public func speak() -> String {
return "woof"
}
public func testSpeaker() {
Swift.print("woof")
import Cocoa
import SpeakerFramework
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
let sp = Speaker()
sp.speak()
import Cocoa
import SpeakerFramework
class MainWindowController: NSWindowController {
@IBOutlet weak var labelTextField: NSTextField!
override func windowDidLoad() {
super.windowDidLoad()
let sp = Speaker()
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var mainWindowController: MainWindowController?
@telliott99
telliott99 / add.h
Last active December 10, 2015 14:16
Swift import C framework
int f1(int);
int f2(int);
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)