Skip to content

Instantly share code, notes, and snippets.

Вы ранее привлекались за хранение данных в глобальных переменных?
Вы когда-нибудь делали .Net за деньги?
Сформулируйте зависимость времени исправления критического бага от seniority присутствующего менеджера
В своём резюме вы указали знание php. вам не стыдно?
Перед вами кисть, холст и мольберт. напишите компилятор
@advantis
advantis / NSManagedObject+ADVCopying.h
Created November 25, 2013 14:34
NSManagedObject category for creating deep copy in another context
//
// Copyright © 2013 Yuri Kotov
//
#import <CoreData/CoreData.h>
@interface NSManagedObject (ADVCopying)
- (instancetype) adv_copyInContext:(NSManagedObjectContext *)context;
@advantis
advantis / arg.py
Last active October 18, 2020 21:50
Custom LLDB command for examining function arguments
#!/usr/bin/python
import lldb
import shlex
def mem_location(arch, index):
index = int(index)
return {
'arm' : ("$r%d" % (index)) if (index < 4) else ("$sp+%d" % (index - 4)),
'armv7' : ("$r%d" % (index)) if (index < 4) else ("$sp+%d" % (index - 4)),
@advantis
advantis / Event.swift
Created September 24, 2014 09:04
C#-inspired event handling in Swift
typealias EventHandler = (AnyObject) -> Void
class Event {
var handlers: [EventHandler] = []
func subscribe(handler: EventHandler) {
handlers.append(handler)
}
dynamic func invoke(sender: AnyObject) {
@advantis
advantis / ADVDataSource.h
Last active December 4, 2018 11:05
Generic UITableView/UICollectionView data source for multiple sections
//
// Copyright © 2013 Yuri Kotov
//
#import <Foundation/Foundation.h>
typedef void(^ADVCellConfigurationBlock)(id cell, id object);
@interface ADVDataSource : NSObject <UITableViewDataSource, UICollectionViewDataSource>
@advantis
advantis / XCTExpectation.swift
Created March 1, 2018 10:27 — forked from ole/XCTExpectation.swift
A variant of XCTKVOExpectation that works with native Swift key paths. To try it out, paste the code into an Xcode playground and observe the unit test output in the console.
import XCTest
/// An expectation that is fulfilled when a Key Value Observing (KVO) condition
/// is met. It's variant of `XCTKVOExpectation` with support for native Swift
/// key paths.
final class KVOExpectation: XCTestExpectation {
private var kvoToken: NSKeyValueObservation?
/// Creates an expectation that is fulfilled when a KVO change causes the
/// specified key path of the observed object to have an expected value.
@advantis
advantis / Digest.swift
Created February 28, 2015 21:23
SHA1 digest in Swift
import Foundation
func sha1(data: NSData) -> String {
let length = Int(CC_SHA1_DIGEST_LENGTH)
var digest = [UInt8](count: length, repeatedValue: 0)
CC_SHA1(data.bytes, CC_LONG(data.length), &digest)
return digest.map { String(format: "%02x", $0) }.reduce("", +)
}
func sha1(string: String) -> String? {
@advantis
advantis / NSData+ADVHexadecimalRepresentation.h
Created November 25, 2013 10:22
NSData category for generating hexadecimal string representation
//
// Copyright © 2012 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSData (ADVHexadecimalRepresentation)
- (NSString *) hexadecimalRepresentation;
@advantis
advantis / ADVLocationDetector.h
Last active December 27, 2015 13:19
Simple location detector
//
// Copyright © 2013 Yuri Kotov
//
#import <CoreLocation/CoreLocation.h>
typedef void(^ADVLocationHandler)(CLLocation *location, NSError *error);
@interface ADVLocationDetector : NSObject
@advantis
advantis / ADVColor.h
Last active December 26, 2015 18:19
UIColor from hex without string parsing, e.g. RGB(0x4C2BFF)
//
// Copyright © 2013 Yuri Kotov
//
#import <UIKit/UIKit.h>
__attribute__((always_inline))
extern inline UIColor * RGB(int color);