Skip to content

Instantly share code, notes, and snippets.

View genedelisa's full-sized avatar
💭
Feeding the cats

Gene De Lisa genedelisa

💭
Feeding the cats
View GitHub Profile
@genedelisa
genedelisa / git-bare.sh
Created October 16, 2014 13:15
Bash script to create a bare git repo then add remote to current directory
#!/usr/bin/env bash
# create a bare git repo
# Gene De Lisa
# === the variables
gitdir=~/Dropbox/git
# assumes you're in the project directory, so get the current dir name without the
# full path.
@genedelisa
genedelisa / webapp-arq.sh
Last active August 29, 2015 14:07
Bash script to generate project from maven archetype for Java EE7 webapp with Arquillian
#!/usr/bin/env bash
# maven archetype helper script
# Gene De Lisa
# === the variables
# your generated output
myartifact=sampleproject
mygroup=com.rockhoppertech
@genedelisa
genedelisa / Orientation
Created August 23, 2014 12:55
Receive device orientation notifications in Swift
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "detectOrientation",
name:UIDeviceOrientationDidChangeNotification,
object:nil)
return true
@genedelisa
genedelisa / MIDISamplerSetup
Created August 12, 2014 12:03
Swift MIDI Sampler setup
class MIDISampler : NSObject {
var engine:AVAudioEngine!
var playerNode:AVAudioPlayerNode!
var mixer:AVAudioMixerNode!
var sampler:AVAudioUnitSampler!
override init() {
super.init()
initAudioEngine()
}
@genedelisa
genedelisa / AlertController
Created August 11, 2014 19:07
UIAlertController in Swift
// ios8 and later
var alert = UIAlertController(title: "Hey!",
message: "How 'bout dat?",
preferredStyle: .Alert)
let textConfigClosure: ((UITextField!) -> Void)! = { text in
text.placeholder = "Type something here"
}
alert.addTextFieldWithConfigurationHandler(textConfigClosure)
@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
@genedelisa
genedelisa / Audio Session
Created August 11, 2014 09:31
Swift setup AVAudioSession
func setSessionPlayer() {
let session:AVAudioSession = AVAudioSession.sharedInstance()
var error: NSError?
if !session.setCategory(AVAudioSessionCategoryPlayback, error:&error) {
println("could not set session category")
if let e = error {
println(e.localizedDescription)
}
}
if !session.setActive(true, error: &error) {
@genedelisa
genedelisa / AudioPlayer
Last active January 20, 2017 10:16
Swift AVAudioPlayer
class Sound : NSObject {
/// The player.
var avPlayer:AVAudioPlayer!
/**
Uses AvAudioPlayer to play a sound file.
The player instance needs to be an instance variable. Otherwise it will disappear before playing.
*/
func readFileIntoAVPlayer() {
@genedelisa
genedelisa / MidIPlayer
Last active April 4, 2020 20:43
Swift AVMIDIPlayer
/// soundbanks are either dls or sf2. see http://www.sf2midi.com/
var soundbank:NSURL!
var mp:AVMIDIPlayer!
func playMIDIFile() {
// Load a SoundFont or DLS file.
self.soundbank = NSBundle.mainBundle().URLForResource("GeneralUser GS MuseScore v1.442", withExtension: "sf2")
// a standard MIDI file.
@genedelisa
genedelisa / playSoundWithAVAudioPlayer
Created August 5, 2014 22:00
Play a sound with AVAudioPlayer
func playSoundWithAVAudioPlayer() {
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("alert", ofType: "mp3"))
var error:NSError?
if !AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &error) {
if let err = error {
println("could not set session category: \(err.localizedDescription)")
}
}