Skip to content

Instantly share code, notes, and snippets.

View VadimYakovliev's full-sized avatar
👻
BO0o...

YVV VadimYakovliev

👻
BO0o...
  • Kyiv, Ukraine
  • 09:58 (UTC +03:00)
View GitHub Profile
@maximkrouk
maximkrouk / Weak.swift
Last active February 5, 2021 12:05
A mechanism for safe capturing & weakifying objects
import Foundation
/// Weakly captures an object
///
/// Actually the same as `weak` but initializable
///
/// Usage:
/// ```
/// Weak(object)
/// Weak(self)
@maximkrouk
maximkrouk / Authenticated.swift
Last active July 6, 2020 16:11
Property wrapper for system FaceID/TouchID/Password secured actions
import Foundation
import LocalAuthentication
@propertyWrapper
public class Authenticated {
public typealias Action = () -> Void
private var _action: Action = {}
private var _onStart: Action?
private var _onSuccess: Action?
@dsabanin
dsabanin / enable-xcode-debug-menu.sh
Last active November 7, 2022 16:17
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode
/*
ModelBinding<T>: a simple class for binding a Flutter app to a immutable
model of type T.
This is a complete application. The app shows the state of an instance of
MyModel in a button's label, and replaces its MyModel instance when the
button is pressed.
ModelBinding is an inherited widget that must be created in a context above
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// https://github.com/avito-tech
private class ObserverBox<T>: Hashable {
typealias Observer = T
private(set) weak var disposable: AnyObject?
private let objectIdentifier: ObjectIdentifier
var observers = [Observer]()
let hashValue: Int
// https://github.com/avito-tech
//
// Sampler is like a baby of Debouncer and Throttler.
//
// Unlike Debouncer, sampler executes action immediately (if there are no actions before, for time > delay)
// Unlike Throttler it guarantees that last action in sequence will be executed (see last error in example)
/// CAUTION: This class isn't thread-safe
public final class Sampler {
// MARK: - Public properite
let a: Double? = 1.0
let b: Double? = 2.0
let c: Double? = 3.0
let d: Double? = 4.0
let e: Double? = 5.0
let f: Double? = 6.0
let g: Double? = 7.0
extension Optional {
func `or`(_ value : Wrapped?) -> Optional {
@JohnSundell
JohnSundell / CrossPlatformImages.swift
Last active November 22, 2022 06:29
An easy way to make code that uses UIImage cross-platform between iOS/tvOS & macOS
// Either put this in a separate file that you only include in your macOS target
// or wrap the code in #if os(macOS) / #endif
import Cocoa
// Step 1: Typealias UIImage to NSImage
typealias UIImage = NSImage
// Step 2: You might want to add these APIs that UIImage has but NSImage doesn't.
extension NSImage {
public func with<T>(_ item: inout T, action: (inout T) -> Void) {
action(&item)
}
public func with<T>(_ item: T, action: (T) -> Void) {
action(item)
}
public func with<T: AnyObject>(_ item: T, action: (T) -> Void) {
action(item)