Skip to content

Instantly share code, notes, and snippets.

@sekati
sekati / xcode-build-bump.sh
Created July 24, 2012 20:44
Xcode Auto-increment Build & Version Numbers
# 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)
@fadookie
fadookie / gist:4392708
Created December 27, 2012 22:32
Retrieve random object from NSSet
//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;
@dropmeaword
dropmeaword / midifreq.c
Created April 11, 2013 21:51
MIDI to frequency conversions
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)
{
@gleitz
gleitz / MIDI_scales.js
Last active February 11, 2024 06:17
MIDI scale arrays in Javascript
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],
@mischah
mischah / z.md
Last active December 9, 2022 02:11
Installing und initializing z (https://github.com/rupa/z) with help of Homebrew.

#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
@pcperini
pcperini / BlockChaining.swift
Created June 5, 2014 20:12
Chain blocks for asynchronous, callback-based execution. Always ends in main queue.
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)
})
}
}
@Kaelten
Kaelten / synced.swift
Last active August 29, 2015 14:02
Simple Swift @synchronized Helper
// 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)
}
@keremk
keremk / Date.playground
Created June 24, 2014 06:56
Swift Date Helpers
// 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 {
@genedelisa
genedelisa / MIDISampler
Created August 11, 2014 11:53
Swift MIDI sampler
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