Skip to content

Instantly share code, notes, and snippets.

View PaulTaykalo's full-sized avatar

Paul Taykalo PaulTaykalo

View GitHub Profile
@PaulTaykalo
PaulTaykalo / example.swift
Created September 25, 2017 15:20
How to (not) work with Core Data contexts
/*
func createBackgroundContext() -> NSManagedObjectContext {
let context = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType)
context.parent = self.mainContext
return context
}
*/
do {
let photos = try appData.createBackgroundContext().fetch(request)
@PaulTaykalo
PaulTaykalo / too many function overrides.swift
Created July 10, 2017 15:14
This one wasn't migrated correctly
import Foundation
class A: NSObject, NSCoding {
var value: Double?
init(value: Double?) {
self.value = value
}
@PaulTaykalo
PaulTaykalo / Tracking in swift
Created June 12, 2017 09:03
Time spent by function in Swift
// This is rather simple example of defer usage
// It won't work if your'e about to measure microsecs for obvious reasons
// But it can help if you're gathering small stats and instruments aren't working for you
// For debugging purposes - Try to use instruments first :)
// For analytics purposes - This can be better
// Swift 2.+
// func timeLogger(operation: String = #function) -> () -> () {
// let now = NSDate()
// return {
int +[NSPersistentStoreCoordinator _beginPowerAssertionWithAssert:]() {
r14 = rdx;
rbx = objc_getClass("UIApplication");
rax = 0x0;
rcx = 0x0;
if (rbx != 0x0) {
rcx = [rbx respondsToSelector:@selector(sharedApplication)];
rax = 0x0;
COND = rcx == 0x0;
@PaulTaykalo
PaulTaykalo / pre-commit
Last active May 3, 2017 12:58
Precommit hook that prevents commiting focused examples fdescribe/fit/fcontext
#!/bin/sh
# place me in .git/hooks/pre-commit
exec 1>&2
if test $(git diff-index -p -M --cached HEAD -- | grep '^+' | grep '^+[[:space:]]*\(fdescribe(\|fcontext(\|fit(\)' | wc -c ) != 0
then
searchedStrings=`git diff-index -p -M --cached HEAD -- | grep '^+' | grep '^+[[:space:]]*\(fdescribe(\|fcontext(\|fit(\)'`
echo "Error: You forgot to remove fdescribe:
${searchedStrings}"
exit 1
fi
@PaulTaykalo
PaulTaykalo / associated.swift
Last active March 17, 2017 17:16
Protocols and associated types in swift
protocol Additable {
func add()
}
protocol Substractable {
func sub()
}
protocol SupportsAddition1 {
associatedtype T = Additable
var operand: T {get set}
@PaulTaykalo
PaulTaykalo / timecheck.py
Created March 5, 2017 00:26
Xcode Time tracking
# So there should be run script which will pass
#./timecheck.py start
#./timecheck.py stop
#!/usr/bin/python
import json,httplib,sys,time,os
from os.path import expanduser
seconds = int(round(time.time()))
import UIKit
extension UITableViewCell {
private static var className: String {
return String(self.self)
}
static func reuseIdentifier() -> String {
return className
@PaulTaykalo
PaulTaykalo / main.m
Created January 29, 2017 22:14
When floats stops working
#import <Foundation/Foundation.h>
@implementation NSObject (Private)
- (float)doSomethng {
return 42.0;
}
@end
int main(int argc, char * argv[]) {
@autoreleasepool {
NSObject * object = [NSObject new];
@PaulTaykalo
PaulTaykalo / Example.swift
Last active January 4, 2017 16:10
Some eaxmple
import Foundation
protocol DefaultValueConvertible {
static func defaultValue() -> Self
}
extension Double : DefaultValueConvertible {
static func defaultValue() -> Double { return 0.0 }
}