This file contains 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
struct Parser<Input: CollectionType, Output> { | |
typealias Function = (Input, Input.Index) -> (Output, Input.Index)? | |
} | |
func parseString(string: String) -> Parser<String, String>.Function { | |
return { str, index in | |
let end = advance(index, count(string)) | |
if str.substringWithRange(index..<end) == string { |
This file contains 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 lazyCollection<T>(#count: () -> Int, #get: Int -> T) -> LazyRandomAccessCollection<MapCollectionView<Range<Int>, T>> { | |
return lazy(0..<count()).map(get) | |
} | |
// Example | |
import CoreMIDI | |
let devices = lazyCollection(count: MIDIGetNumberOfDevices, get: MIDIGetDevice) | |
devices.array // compute all | |
devices[0] // MIDIDeviceRef |
This file contains 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 CoreMIDI | |
enum ChannelMessage { | |
case NoteOn(key: UInt8, velocity: UInt8) | |
case NoteOff(key: UInt8) | |
case ControlChange(controller: UInt8, value: UInt8) | |
func bytesForChannel(channel: Int) -> [UInt8] { | |
let status = { $0 | (UInt8(channel) & 0x0F) } | |
let removeMSB = { $0 & UInt8(0x7F) } |
This file contains 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 | |
typealias LightState = [String:NSObject] | |
enum LightCommand { | |
enum LightEffect: String { | |
case None = "none" | |
case ColorLoop = "colorloop" | |
} | |
enum LightAlert: String { |
This file contains 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
struct Zip3Generator | |
< | |
A: GeneratorType, | |
B: GeneratorType, | |
C: GeneratorType | |
>: GeneratorType { | |
private var first: A | |
private var second: B |
This file contains 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
request = require 'request' | |
_ = require 'underscore' | |
exec = require('child_process').exec | |
options = | |
url: 'https://api.github.com/users/JRHeaton/repos?type=owner' | |
json: true | |
headers: | |
'User-Agent': 'jgithubdownload' |
This file contains 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
infix operator >>= { } | |
func >>= <A, B> (x: A?, f: A -> B?) -> B? { | |
if let val = x { | |
return f(val) | |
} | |
return nil | |
} | |
protocol MIDIEnumerable { | |
class func count() -> Int |
This file contains 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 CoreMIDI | |
extension MIDIPacket { | |
static func channel(status: UInt8, data1: UInt8, data2: UInt8) -> MIDIPacket { | |
let newPacket = UnsafeMutablePointer<MIDIPacket>.alloc(1) | |
newPacket.memory.length = 3 | |
withUnsafePointer(&newPacket.memory.data, { (ptr) -> () in | |
let dataPtr = UnsafeMutablePointer<UInt8>(ptr) | |
dataPtr[0] = status |
This file contains 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
void setOSXThemeDark(BOOL dark) { | |
CFPreferencesSetAppValue(CFSTR("AppleInterfaceStyle"), !dark ? nil : CFSTR("Dark"), kCFPreferencesAnyApplication); | |
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), CFSTR("AppleInterfaceThemeChangedNotification"), nil, nil, 1); | |
} |
This file contains 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
// | |
// SignalExtensions.swift | |
// Fan Club | |
// | |
// Created by John Heaton on 12/18/14. | |
// Copyright (c) 2014 StageBloc. All rights reserved. | |
// | |
import Foundation |