Skip to content

Instantly share code, notes, and snippets.

View nikolaykasyanov's full-sized avatar

Nikolay Kasyanov nikolaykasyanov

  • Careem
  • Berlin, Germany
View GitHub Profile
@nikolaykasyanov
nikolaykasyanov / Example.swift
Last active September 27, 2019 14:53
A property wrapper that creates subject-backed observers (RxSwift)
class ViewModel {
init() {
// accessing underlying subject:
$buttonTapped
.asObservable()
...
}
// look ma, no explicit subject property

Self в Swift и Objective-C

Дисклеймер: речь идёт об однопоточном коде, оставим ужасы параллельного исполнения за скобками. Также не рассматривается возможность overrelease.

Objective-C

Объект точно не ритейнится на время выполнения его метода, пруфы:

#import <Foundation/Foundation.h>
@interface Node: NSObject
@property (nonatomic, weak) Node *parent;
@property (nonatomic) NSArray *children;
@end
@implementation Node {
import Foundation
class Child {
deinit {
print("Child.deinit")
}
var parent: Parent?
func removeFromParent() {
@nikolaykasyanov
nikolaykasyanov / cmake.rb
Created February 4, 2019 20:28
CMake 3.12.4 formula
class Cmake < Formula
desc "Cross-platform make"
homepage "https://www.cmake.org/"
url "https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz"
sha256 "5255584bfd043eb717562cff8942d472f1c0e4679c4941d84baadaa9b28e3194"
head "https://cmake.org/cmake.git"
bottle do
cellar :any_skip_relocation
sha256 "7bcd5ae043d2a6fd5983b026ccdc70b7594e0dbe9de4d367cfcead7edf3c8596" => :mojave
protocol RemoteAPIDelegate: class {
func remoteAPIDidLoadPosts(_ posts: NSArray)
}
class RemoteAPI {
weak var delegate: RemoteAPIDelegate?
func loadPosts() {
protocol ReachabilityDelegate: class {
func reachabilityDidChange(_ reachable: Bool)
}
class Reachability {
weak var delegate: ReachabilityDelegate?
}
class Model: ReachabilityDelegate {
func reachabilityDidChange(_ reachable: Bool) {
@nikolaykasyanov
nikolaykasyanov / C138FB1B-8C83-477C-B33C-05551516167A.codesnippet
Last active November 27, 2016 14:49
__auto_type autocompletion snippet for Xcode 8+. Just put it in ~/Library/Developer/Xcode/UserData/CodeSnippets/ and then start typing aut... in Xcode.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>auto</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>CodeBlock</string>
</array>
require 'json'
require 'net/http'
module Fastlane
module Actions
class MfbLatestHockeyBuildAction < Action
def self.run(config)
host_uri = URI.parse('https://rink.hockeyapp.net')
http = Net::HTTP.new(host_uri.host, host_uri.port)
http.use_ssl = true
public protocol DBWorker2 {
associatedtype S: SequenceType
func fetchObjectsFromStorage(type: S.Generator.Element.Type) -> Observable<S.Generator.Element>
func saveObjectsToStorage(objects: S) -> Observable<Void>
}
public class DBWorker2Impl: DBWorker2 {
public func fetchObjectsFromStorage(type: Item.Type) -> Observable<Item> {
return Observable()