Skip to content

Instantly share code, notes, and snippets.

View marcpalmer's full-sized avatar
💭
Busy working on Concepts app, and Captionista

Marc Palmer marcpalmer

💭
Busy working on Concepts app, and Captionista
View GitHub Profile
BOOL hasCurrentAnimations = [self.myLabel.layer animationKeys].count;
if (rising) {
[self.currentTimeLabel.layer removeAllAnimations];
[UIView animateWithDuration:5.0f delay:0.0f
options:(hasCurrentAnimations ? UIViewAnimationOptionBeginFromCurrentState : 0) animations:^{
self.myLabel.center = CGPointMake(self.myLabel.center.x, self.otherButton.center.y);
} completion:nil];
} else {
@marcpalmer
marcpalmer / gist:e2decfdcd51623836ec2
Created October 11, 2014 15:13
Example of resolving image sets depending on display size
#import "UIImage+ImageAdditions.h"
@implementation UIImage (ImageAdditions)
+ (NSString *)resolveAdaptiveImageName:(NSString *)nameStem {
CGFloat height = [UIScreen mainScreen].bounds.size.height;
if (height > 568.0f) {
// Oversize @2x will be used for iPhone 6, @3x for iPhone 6+
// iPads... we'll work that out later
if (height > 667.0f) {
@marcpalmer
marcpalmer / gist:b1fc694ce398c82e614f
Last active August 29, 2015 14:08
Obscure bug with > overloading with UIKit under iOS
// This code fails to compile with iOS SDK 8.1 and Xcode 6.1
import UIKit
let names = ["a","c","b"]
// This fails to compile on iOS targets
// It works if:
// a) you add "return" to the closure
// - or -
// b) you remove the UIKit import
@marcpalmer
marcpalmer / gist:add6a43b23ff8a8d0cb1
Last active August 29, 2015 14:08
Simple message output with autoclosure
let debugEnabled = true
func conditionalMessage(message:@autoclosure () -> String) {
if debugEnabled {
println(message())
}
}
func expensiveMessage() -> String {
println("I’m expensive you know")
@marcpalmer
marcpalmer / gist:11423d0d589f13a0e947
Created October 29, 2014 14:59
Conditional variadic argument list evaluation
let debugEnabled = true
// This makes it all a bit easier to read
typealias LazyVarArgClosure = @autoclosure () -> CVarArgType
func conditionallyLogSomething(messageFormat:@autoclosure () -> String, args:LazyVarArgClosure...) {
// If this is false, we do nothing
if debugEnabled {
// Go through the list of closures and invoke them all, to get an array of arguments
// compatibvle with va_list
@marcpalmer
marcpalmer / gist:6e30d394f8c2e92fe0a3
Created November 28, 2014 12:12
Seriously? XSS fun
window.alert('Pwnd!');
@marcpalmer
marcpalmer / gist:283333cd3ce9032e7637
Created January 5, 2015 11:36
Puzzling compiler error with Xcode 6.2 (6C101)
// Works
class Testing {
func something() {
dispatch_async(dispatch_get_main_queue()) {
[weak self] in
if let blockSelf = self {
blockSelf.somethingElse()
}
}
}
@marcpalmer
marcpalmer / gist:e1c1b7166e6cce7c8759
Created July 15, 2015 11:20
Demo of a possible approach to memoization of arbitrary function return values
//: # Memoization demo
import UIKit
/*:
These are infrastructure classes for storing the cached function return values based on object instance, function name and input arguments.
There is still work to do here. It is not thread safe.
*/
typealias MemoKey = String
@marcpalmer
marcpalmer / gist:1183594
Created August 31, 2011 13:59
Navigation API thoughts

Navigation API

Site navigation is a combination of two concerns - declaring what navigation items there are in the site, and what the structure of them is - as presented to the use.

Specifying items and structure separately is not DRY, and applications also need to have the ability to change the structure to suit them - therefore the structure information provided by a plugin is merely a guide, and inherently disposable.

@marcpalmer
marcpalmer / gist:1195658
Created September 5, 2011 18:50
Integration test output with debug console logging in 2.0
marcmacbook:resources marc$ grails test-app :integration
| Environment set to test.....
> You currently already have a version of the plugin installed [tomcat-2.0.0.BUILD-SNAPSHOT]. Do you want to update to [tomcat-1.3.7]? [y,n] n
| Plugin tomcat-1.3.7 install aborted
> You currently already have a version of the plugin installed [hibernate-2.0.0.BUILD-SNAPSHOT]. Do you want to update to [hibernate-1.3.7]? [y,n] n
| Packaging Grails application.....
2011-09-05 19:47:01,898 [main] INFO plugins.DefaultGrailsPluginManager - Attempting to load [0] user defined plugins
2011-09-05 19:47:01,971 [main] INFO plugins.DefaultGrailsPluginManager - Grails plug-in [logging] with version [2.0.0.BUILD-SNAPSHOT] loaded successfully
2011-09-05 19:47:01,971 [main] INFO plugins.DefaultGrailsPluginManager - Grails plug-in [i18n] with version [2.0.0.BUILD-SNAPSHOT] loaded successfully
2011-09-05 19:47:01,971 [main] INFO plugins.DefaultGrailsPluginManager - Grails plug-in [core] with version [2.0.0.BUILD-SNAPSHOT] loaded su