Skip to content

Instantly share code, notes, and snippets.

View krzysztofzablocki's full-sized avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
With 10.8 SDK, `#define OBJC_OLD_DISPATCH_PROTOTYPES 0` at the top of your file or PCH to get errors if you use objc_msgSend without a cast.
@krzysztofzablocki
krzysztofzablocki / gist:6711189
Created September 26, 2013 08:03
Multiple weak call
Wrong:
__weak id obj;
dispatch_async(queue, ^() {
[obj doSomething];
[obj doSomethingElse]; <- can turn to nil at any point, should store in strong at beggining of block
[obj doSomethingElse2];
});
Ok:
#import <Foundation/Foundation.h>
@interface A : NSObject
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler;
@end
@implementation A
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler
{
NSLog(@"object: %@", o);
@krzysztofzablocki
krzysztofzablocki / gist:8913213
Last active January 25, 2018 22:06
Diet setup for cutting, paste into calca.io and modify stats.
# For training rest 5 min on compounds, 3-5 minutes on smaller ones
# Training A (first set to failure, second set -10% weight + 1 rep):
# Deadlift - 2x4-5
# Overhead Press - 1x6-8
# Weighted Chinup - 2x4-6
# Chest-Supported Rows - 2x6-8
# Close-grip chinup - 1x6-10
# Training B (first set to failure, second set -10% weight + 1 rep):
#!/usr/bin/env ruby
require 'net/http'
require 'openssl'
# Track public available information of a twitter user like follower, follower
# and tweet count by scraping the user profile page.
# Config
# ------
twitter_username = ENV['TWITTER_USERNAME'] || 'foobugs'
@krzysztofzablocki
krzysztofzablocki / Bind lifetime
Created April 22, 2014 13:43
Binding lifetime of self to specific object
- (void)bindLifetimeToObject:(id)object
{
objc_setAssociatedObject(object, (__bridge void *)self, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)releaseLifetimeFromObject:(id)object
{
objc_setAssociatedObject(object, (__bridge void *)self, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@krzysztofzablocki
krzysztofzablocki / gist:11252222
Created April 24, 2014 12:04
Don't repeat yourself
- (void)viewWillAppear:(BOOL)animated
{
[UIView animateWithDuration:animated ? 0.25f : 0.0f animations:^
{
// Some manipulation
} completion:^
{
// Some completion action
}]
}
//! raw builder
TMTween(self.view).animate(@"frame.origin.x", ^(TMTween *tween) {
tween.from = tween.view.left;
tween.to = 110;
tween.duration = 1.5;
tween.options = PMTweenOptionNone;
tween.easing = easing;
}).animate(@"backgroundColor.blue", ^(TMTween *tween) {
tween.from = 0.3f;
tween.to = 1.0;
@implementation KZPropertyMapper (MyAppBoxing)
+ (NSDate *)boxValueAsDateSince1970:(id)value __used
{
if (value == nil) {
return nil;
}
AssertTrueOrReturnNil([value isKindOfClass:NSNumber.class]);
return [NSDate dateWithTimeIntervalSince1970:[value floatValue]];
}
when_modified((@[self.counterLabel, self.textView]), ^(id weakSelf) {
[weakSelf updateCharacterLimit];
});