Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View klaaspieter's full-sized avatar
🏠
Working from home

Klaas Pieter Annema klaaspieter

🏠
Working from home
View GitHub Profile
@klaaspieter
klaaspieter / Pizza.swift
Created February 2, 2015 20:55
An implementation of the Builder pattern in Swift
import Foundation
enum Cheese : String {
case Mozzarella = "Mozzarella"
case Provolone = "Provolone"
case Pecorino = "Pecorino"
}
class PizzaBuilder {
var size: Int = 0
@klaaspieter
klaaspieter / Karma.clr
Last active August 29, 2015 14:09
Karma colors. Place these files in ~/Library/Colors.
class MockURLSession : NSURLSession {
var request: NSURLRequest?
override func dataTaskWithRequest(request: NSURLRequest, completionHandler: ((NSData!, NSURLResponse!, NSError!) -> Void)?) -> NSURLSessionDataTask {
self.request = request
return super.dataTaskWithRequest(request, completionHandler: completionHandler)
}
}
[RKRequestDescriptor requestDescriptorWithMapping:[mappingProvider.orderConfirmationMapping inverseMapping]
objectClass:[WTNOrderConfirmation class]
rootKeyPath:@"confirmation"
method:RKRequestMethodPOST];
// In the mapping provider
- (RKObjectMapping *)orderConfirmationMapping;
{
if (!_orderConfirmationMapping) {
_orderConfirmationMapping = [RKObjectMapping mappingForClass:[WTNOrderConfirmationResponse class]];
@klaaspieter
klaaspieter / gist:ffcfb2f80fcaaabc1c87
Last active August 29, 2015 14:05
Keeping forgetting to remove those pesky `fdescribes` from your Specta files? Add this to .git/hooks/pre-commit
if ! git diff-index --cached --name-only --exit-code -G "fdescribe" $against
then
echo "\nRemove occurences of fdescribe from listed files."
exit 1
fi
let json = [{
name: "Klaas Pieter Annema",
age: 28
}, // Compiler infers Integer type for age
{
name: "Chris Eidhof",
age: "Unknown"
} // Compiler infers String type for age
];
@klaaspieter
klaaspieter / ProgressBar.java
Created June 30, 2014 18:58
Android ProgressBar subclass with a custom foreground color
package com.yourkarma.android.ui.components;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
public class ProgressBar extends android.widget.ProgressBar {
[[NSDateFormatter dateFormatFromTemplate:@"HHa" options:0 locale:[NSLocale currentLocale]] stringByReplacingOccurrencesOfString:@" " withString:@""];
describe(@"when the retry button is tapped", ^{
before(^{
_fetcher = mock([ProductFetcher class]);
_viewController.productFetcher = _fetcher;
[_viewController.errorView.button sendActionsForControlEvents:UIControlEventTouchUpInside];
});
it(@"retries fetching the products", ^{
[verify(_fetcher) fetch];
});
CGRect rect = {{.x = 0.0, .y = 0.0}, {.width = 0.0, .height = 0.0}};
CGRect rect = {0.0, 0.0, 0.0, 0.0}