Skip to content

Instantly share code, notes, and snippets.

View elm4ward's full-sized avatar

Elmar Kretzer elm4ward

View GitHub Profile
@elm4ward
elm4ward / main.m
Created July 5, 2012 15:17
main.m with DEBUG Exception Logging
int main(int argc, char *argv[])
{
#ifdef DEBUG
// will make debugging more easy
@try {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
@catch (NSException *exception) {
@elm4ward
elm4ward / gist:3139043
Created July 18, 2012 21:28
another not so fast removeObject
NSMutableArray* ma = [[NSMutableArray alloc] init];
// about 0.015 seconds
for (int i = 0; i<10000; i++) {
[ma addObject:[NSString stringWithFormat:@"%@ %d", @"ABC", i]];
}
// still slow: takes more than 7 seconds.....
__block NSMutableArray* ma2 = [ma mutableCopy];
[ma enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[ma2 removeObject:obj];
@elm4ward
elm4ward / gist:3838469
Created October 5, 2012 07:00 — forked from matzew/gist:3833597
Usage of AGAuthenticationManager and AGAuthenticationModule for signup/signin/signout
// create an auth manager object
AGAuthenticationManager* authMgr = [AGAuthenticationManager manager];
// add a new auth module and the required 'base url':
NSURL* baseURL = [NSURL URLWithString:@"https://todoauth-aerogear.rhcloud.com/todo-server"];
id<AGAuthenticationModule> myMod = [authMgr add:@"authMod" baseURL:baseURL];
// ====================================
@elm4ward
elm4ward / gist:8425581
Last active October 22, 2021 21:19
handle CSS animation programmatically via promise
// attention: needs when.js, jquery and checks only for webkit
var transformTo = function ($e, css, property) {
var deferred = when.defer();
$e.on('webkitTransitionEnd', function (e) {
if (!!property && property !== e.originalEvent.propertyName) {
return;
}
$e.off('webkitTransitionEnd');
deferred.resolve();
// Current state of curry and partial application in Swift
// go
func adder1(a:Int)(b:Int) -> Int {
return a + b
}
let adder2 = {(a: Int, b: Int) -> Int in
return a + b;
}
Process: SourceKitService [41303]
Path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/XPCServices/SourceKitService.xpc/Contents/MacOS/SourceKitService
Identifier: SourceKitService
Version: 1.0 (700.1.101.6)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [24966]
User ID: 502
Date/Time: 2015-11-19 15:16:41.268 +0100
import Foundation
#if os(iOS)
import UIKit
#endif
#if os(watchOS)
import WatchKit
#endif
extension NSMutableAttributedString {
/// the protocol
protocol ImplicitDefault {
static var implicitDefault: Self { get }
}
/// the implementation for Strings
extension String: ImplicitDefault {
/// i dont care i take the empty string as default
// ----------------------------------------------------------------------------------------------------
// ArrayZipper Comonads in Swift
//
// http://elm4ward.github.io/swift/functional/comonad/2016/03/30/monads-comonads.html
//
// 1. Array extensions
// 2. ArrayZipperError
// 3. ArrayZipper
// 4. ArrayZipper extensions
// 5. custom operators
// ----------------------------------------------------------------------------------------------------
// Protocol Flow in Swift
//
// http://elm4ward.github.io/swift/protocols/2016/04/02/protocollisions.html
//
// 1. The Protocols
// 2. The Flow
// 3. String Example
// 4. Custom Example
// ----------------------------------------------------------------------------------------------------