#The power of z
Do you spend lots of time doing things like this?
cd this/is/the/path/that/i/want/so/i/type/it/all/out/to/get/whereiwant
With z, you could just do this:
# xcode-build-bump.sh | |
# @desc Auto-increment the build number every time the project is run. | |
# @usage | |
# 1. Select: your Target in Xcode | |
# 2. Select: Build Phases Tab | |
# 3. Select: Add Build Phase -> Add Run Script | |
# 4. Paste code below in to new "Run Script" section | |
# 5. Drag the "Run Script" below "Link Binaries With Libraries" | |
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0) |
//Implemented based on the pseudo-code in http://stackoverflow.com/a/9981965/350761 | |
int randomIndex = arc4random() % [set count]; | |
__block int currentIndex = 0; | |
__block id selectedObj = nil; | |
[set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { | |
if (randomIndex == currentIndex) { selectedObj = obj; *stop = YES; } | |
else currentIndex++; | |
}]; | |
return selectedObj; |
double midi2freq(int midi) | |
{ | |
double f; | |
f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0); | |
return (f); | |
} | |
int freq2midi(double f) | |
{ |
var scales = { | |
'natural major': [0,2,4,5,7,9,11,12], | |
'ionian': [0,2,4,5,7,9,11,12], | |
'major': [0,2,4,5,7,9,11,12], | |
'chromatic': [0,1,2,3,4,5,6,7,8,9,10,11,12], | |
'spanish 8 tone': [0,1,3,4,5,6,8,10,12], | |
'flamenco': [0,1,3,4,5,7,8,10,12], | |
'symmetrical': [0,1,3,4,6,7,9,10,12], | |
'inverted diminished': [0,1,3,4,6,7,9,10,12], | |
'diminished': [0,2,3,5,6,8,9,11,12], |
#The power of z
Do you spend lots of time doing things like this?
cd this/is/the/path/that/i/want/so/i/type/it/all/out/to/get/whereiwant
With z, you could just do this:
int fromPPQ15360TicksToSamples (int ticks, int tempo, int sampleRate) | |
{ | |
// ticks -> samples | |
// 3.9025 = 60000 (milliseconds / min) / 15360 (ticks per quarter note) | |
return (3.9025 * sampleRate * ticks) / (double)tempo; | |
} | |
int fromSamplesToPPQ15360Ticks (int sampleOffset, int tempo, int sampleRate) | |
{ | |
// samples -> ticks |
operator infix ~> { associativity right } | |
@infix func ~>(firstBlock: (() -> Void), secondBlock: (() -> Void)) -> (() -> Void) { | |
return { | |
dispatch_async(dispatch_get_global_queue(-32768, 0), { | |
firstBlock() | |
dispatch_async(dispatch_get_main_queue(), secondBlock) | |
}) | |
} | |
} |
// A simple replacement for Obj-C's @synchronized keyword, currently seems to cause compiler error if lock is an object array. | |
func synced(lock: AnyObject, closure: () -> ()) { | |
objc_sync_enter(lock) | |
closure() | |
objc_sync_exit(lock) | |
} |
// Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
enum TimeIntervalUnit { | |
case Seconds, Minutes, Hours, Days, Months, Years | |
func dateComponents(interval: Int) -> NSDateComponents { |
class MIDISampler : NSObject { | |
var engine:AVAudioEngine! | |
var playerNode:AVAudioPlayerNode! | |
var mixer:AVAudioMixerNode! | |
var sampler:AVAudioUnitSampler! | |
/// soundbanks are either dls or sf2. see http://www.sf2midi.com/ | |
var soundbank:NSURL! | |
let melodicBank:UInt8 = UInt8(kAUSampler_DefaultMelodicBankMSB) | |
/// general midi number for marimba | |
let gmMarimba:UInt8 = 12 |