Skip to content

Instantly share code, notes, and snippets.

Avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
@krzysztofzablocki
krzysztofzablocki / template.stencil
Last active Jan 14, 2017
AutoEquatable template
View template.stencil
// swiftlint:disable file_length
fileprivate func compareOptionals<T>(lhs: T?, rhs: T?, compare: (_ lhs: T, _ rhs: T) -> Bool) -> Bool {
switch (lhs, rhs) {
case let (lValue?, rValue?):
return compare(lValue, rValue)
case (nil, nil):
return true
default:
return false
View Capture.swift
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
func perform(initial: Int) {
var value: Int = initial
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue()) { [myConstant = value] in
print("constant in first block \(myConstant)")
print("captured \(value)")
value = initial * 2
View UINavigationItem+KZAdditions.h
@import UIKit;
@interface UINavigationItem (KZAdditions)
@property (nonatomic, copy) NSDictionary *kz_titleTextAttributes;
@end
View gist:f5f597f04b2efcb711c7
require 'mechanize'
require 'moving_average'
mechanize = Mechanize.new
login_page = mechanize.get 'https://www.myfitnesspal.com/account/login'
form = login_page.forms.first
# noinspection RubyResolve
form.field_with(id: 'username').value = "username"
form.field_with(id: 'password').value = "pass"
form.submit
View gist:0ad07583dcfdb9dd8634
IDEBundleInjection.c: Error 3587 loading bundle '/Users/merowing/Library/Developer/Xcode/DerivedData/GeekFitness-gtvztnsddwdauobsjnmkmeurgqks/Build/Products/Debug-iphonesimulator/GeekFitnessTests.xctest': The bundle “GeekFitnessTests” couldn’t be loaded because it is damaged or missing necessary resources.
DevToolsBundleInjection environment:
XCInjectDiagnostics: (null)
XCInjectBundleInto: /Users/merowing/Library/Developer/Xcode/DerivedData/GeekFitness-gtvztnsddwdauobsjnmkmeurgqks/Build/Products/Debug-iphonesimulator/GeekFitness.app/GeekFitness
XCInjectBundle: /Users/merowing/Library/Developer/Xcode/DerivedData/GeekFitness-gtvztnsddwdauobsjnmkmeurgqks/Build/Products/Debug-iphonesimulator/GeekFitnessTests.xctest
TestBundleLocation: /Users/merowing/Library/Developer/Xcode/DerivedData/GeekFitness-gtvztnsddwdauobsjnmkmeurgqks/Build/Products/Debug-iphonesimulator/GeekFitnessTests.xctest
TMPDIR: /Users/merowing/Library/Developer/CoreSimulator/Devices/39DF8175-6F30-4946-9B23-8B27018F1CE4/data/Containers/Data/Applica
View gist:4d35818d176536655193
when_modified((@[self.counterLabel, self.textView]), ^(id weakSelf) {
[weakSelf updateCharacterLimit];
});
View gist:3c6b9cba4dda976b3ce3
@implementation KZPropertyMapper (MyAppBoxing)
+ (NSDate *)boxValueAsDateSince1970:(id)value __used
{
if (value == nil) {
return nil;
}
AssertTrueOrReturnNil([value isKindOfClass:NSNumber.class]);
return [NSDate dateWithTimeIntervalSince1970:[value floatValue]];
}
View gist:c8ba13b7fd4d36eb3ec0
//! 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;
View gist:11252222
- (void)viewWillAppear:(BOOL)animated
{
[UIView animateWithDuration:animated ? 0.25f : 0.0f animations:^
{
// Some manipulation
} completion:^
{
// Some completion action
}]
}
@krzysztofzablocki
krzysztofzablocki / Bind lifetime
Created Apr 22, 2014
Binding lifetime of self to specific object
View Bind lifetime
- (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);
}