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
XCTAssertTrue([BRYEqualsBuilder buildWithBlock:^(BRYEqualsBuilder *builder) {
[builder appendObject:@"foo" otherObject:@"foo"];
[builder appendBool:YES otherBool:YES];
[builder appendFloat:0.5 otherFloat:0.5];
}].isEqual, "Values should be equal");

Every second refresh the hotspot status

For the Karma Android (and iOS app) we need to update the hotspot status every second. We'll consider the exact implementation a detail suffice to say that every second some callback needs to be triggered that performs the necesary update. I'm writing this gist to try and explain what I'm trying to do and to get feedback on my approach from experienced developers.

My first attempt

  1. The main activity has an instance of a HotspotStatusUpdater class (initialize in onCreate)
  2. In onResume I call hotspotStatusUpdater.startUpdatingHotspotStatus(this); (this is a callback that implements the HotspotStatusCallback interface)
  3. In onPause I call hotspotStatusUpdater.stopUpdating();

Activity / fragment layout for the Karma Android app

I'm new to Android development and through trial and error in the past week I've come up with the hereafter described layout for the Karma app. If you're an Android developer I would love to know what you think and how I can improve. For context this is what the app looks like in it's two most important states, connected and disconnected.

You'll notice that both states share a custom background color, the signal strength label, the user's balance and the ssid. This is what I have right now in terms of Activities / Fragments:

  • MainActivity
  • TextualStatusFragment
  • VisualDisconnectedStatusFragment or VisualDisconnectedStatusFragment
@interface ViewController : UIViewController
@property (nonatomatic, readwrite, strong) APIClient *apiClient;
@implementation ViewController
- (APIClient *)apiClient;
if (!_apiClient) {
_apiClient = [[APIClient alloc] initWithBaseURL:someConfig.baseURL];
CGRect rect = {{.x = 0.0, .y = 0.0}, {.width = 0.0, .height = 0.0}};
CGRect rect = {0.0, 0.0, 0.0, 0.0}
describe(@"when the retry button is tapped", ^{
_fetcher = mock([ProductFetcher class]);
_viewController.productFetcher = _fetcher;
[_viewController.errorView.button sendActionsForControlEvents:UIControlEventTouchUpInside];
it(@"retries fetching the products", ^{
[verify(_fetcher) fetch];
[[NSDateFormatter dateFormatFromTemplate:@"HHa" options:0 locale:[NSLocale currentLocale]] stringByReplacingOccurrencesOfString:@" " withString:@""];
klaaspieter /
Created June 30, 2014 18:58
Android ProgressBar subclass with a custom foreground color
import android.content.Context;
import android.util.AttributeSet;
public class ProgressBar extends android.widget.ProgressBar {
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 / 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
echo "\nRemove occurences of fdescribe from listed files."
exit 1