Skip to content

Instantly share code, notes, and snippets.

View Ben-G's full-sized avatar
💭
💻

Benjamin Encz Ben-G

💭
💻
View GitHub Profile
@Ben-G
Ben-G / PlaySound.m
Last active August 29, 2015 13:55
Play sound in Cocos2d 3.0
OALSimpleAudio *audio = [OALSimpleAudio sharedInstance];
[audio playEffect:@"your_file_name"]
@Ben-G
Ben-G / gist:571d17e39b51e565991e
Last active August 29, 2015 14:04
Fix for Cocos2D + MGWUSDK
-(void) applicationWillResignActive:(UIApplication *)application
{
[[CCDirector sharedDirector] pause];
}
-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[CCDirector sharedDirector] stopAnimation];
}
@Ben-G
Ben-G / RandomNumber.swift
Last active August 29, 2015 14:13
Swift Random Number Helper
/*
Generates a random number with upper bound of provided value.
Truncates upper bound to 32-Bit values.
*/
func randomInteger(var maximum: Int) -> Int {
if maximum > Int(Int32.max) {
maximum = Int(Int32.max)
}
return Int(arc4random_uniform(
@Ben-G
Ben-G / PFObjectSubscriptExtension.swift
Created March 12, 2015 16:43
Workaround for: 'PFObject' does not have a member named 'subscript'
// Workaround for Parse 1.6.4 and Xcode 6.3, see: http://stackoverflow.com/questions/28953306/pfobject-does-not-have-a-member-named-subscript/29015269#29015269
extension PFObject {
subscript(index: String) -> AnyObject? {
get {
return self.valueForKey(index)
}
set(newValue) {
if let newValue: AnyObject = newValue {
self.setValue(newValue, forKey: index)
}
//: Playground - noun: a place where people can play
import Foundation
/*
Basic Monad according to definition in: http://stackoverflow.com/questions/27750046/is-a-collection-with-flatmap-a-monad
The requirements for being a monad
- A monad has to be a type constructor F[_] that takes one type argument. For example, F could be List, Function0, Option, etc.
@Ben-G
Ben-G / OptionalMap.swift
Created June 8, 2015 04:08
"Optional chaining for functions" using map and curried functions
var a: String? = "a"
var b: String? = "b"
func twoParamFunction(a: String)(b:String) {
println("\(a)\(b)")
}
a.map(twoParamFunction).map { b.map($0)}
//: Playground - noun: a place where people can play
/*
Compiler Error:
candidate exactly matches
func doSomething() {
^
*/
struct A:B,C {
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
let greeting: String = "hello, world!"
let capitalizedGreeting = greeting.capitalizedString
let testString = "👴🙅HahaśāGœ"
@Ben-G
Ben-G / MulticastDelegate
Created July 13, 2015 23:31
Multicast Delegate Swift Prototype (WIP - currently storing strong references to delegates)
// Multicast delegate prototype. Better solution in Obj-C here: http://arielelkin.github.io/articles/objective-c-multicast-delegate/
// Implementations
class CarListener: Hashable {
var hashValue = Int(arc4random())
func receivedNoise(noiseEmitter: CarListenable) {
@Ben-G
Ben-G / DefaultValuesIssues.swift
Created July 28, 2015 21:57
Edge cases with default values for methods in Swift
//: Playground - noun: a place where people can play
import UIKit
protocol APIClientProtocol {
init()
init(urlSession: NSURLSession)
init(apiKey: String)
init(urlSession: NSURLSession, apiKey: String)