Skip to content

Instantly share code, notes, and snippets.

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

YVV VadimYakovliev

👻
BO0o...
  • Kyiv, Ukraine
  • 05:47 (UTC +03:00)
View GitHub Profile
// Original article here: https://www.fivestars.blog/code/swiftui-hierarchy-list.html
import SwiftUI
struct FileItem: Identifiable {
let name: String
var children: [FileItem]?
var id: String { name }
import UIKit
struct Action {
let title: String
let style: UIAlertAction.Style
let action: () -> Void
}
extension Action {
static func `default`(_ title: String, action: @escaping () -> Void) -> [Action] {
@VadimYakovliev
VadimYakovliev / PreviewingMultipleStates.swift
Last active October 21, 2019 07:14 — forked from mattt/UIViewControllerPreview.swift
Generic structures to host previews of UIView and UIViewController subclasses.
Group {
UIViewPreview {
let button = FavoriteButton(frame: .zero)
return button
}
UIViewPreview {
let button = FavoriteButton(frame: .zero)
button.isFavorited = true
return button
}
public protocol RichTextEditorDelegate: class {
func textDidChange(text: String)
func heightDidChange()
}
fileprivate class WeakScriptMessageHandler: NSObject, WKScriptMessageHandler {
weak var delegate: WKScriptMessageHandler?
init(delegate: WKScriptMessageHandler) {
self.delegate = delegate
@VadimYakovliev
VadimYakovliev / programmatic-dynamic-images.m
Created June 11, 2019 05:43 — forked from timonus/programmatic-dynamic-images.m
Programmatically create iOS 13 dynamic images
- (UIImage *)dynamicImage
{
UITraitCollection *const baseTraitCollection = /* an existing trait collection */;
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]];
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]];
__block UIImage *lightImage;
[lightTraitCollection performAsCurrentTraitCollection:^{
lightImage = /* draw image */;
@VadimYakovliev
VadimYakovliev / model_binding_demo.dart
Last active May 9, 2019 06:42 — forked from HansMuller/model_binding_demo.dart
[-Flutter- Model binding]
/*
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
tap "ethereum/ethereum"
tap "heroku/brew"
tap "homebrew/boneyard"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "paritytech/paritytech"
cask "java"
brew "ansible"
@VadimYakovliev
VadimYakovliev / duplicate_line_xcode.md
Created February 13, 2019 16:44 — forked from emotality/duplicate_line_xcode.md
Xcode - Duplicate Line key binding

Xcode line duplicate

Bind keys to duplicate lines in Xcode

  1. Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
import UIKit
import Foundation
func test(named: String,
_ work: (_ assert: @escaping (Bool) -> Void, _ done: @escaping () -> Void) -> Void) {
var testPass = true
var assertCount = 0
let assert: (Bool) -> Void = { value in
assertCount = assertCount + 1
testPass = testPass && value
{% for type in types.based.JSONAutoRepresentable| %}
// sourcery:inline:auto:{{ type.name }}.JSONAutoRepresentable
init(_ json: JSON) {
{% for variable in type.storedVariables where variable|!annotated:"skip" %}
{% elif variable.type.based.JSONAutoRepresentable %}
{{ variable.name }} = {{ variable.unwrappedTypeName }}(json["{{ variable.name|camelToSnakeCase }}"])
{% elif variable.isArray %}
{{ variable.name }} = json["{{ variable.name|camelToSnakeCase }}"].arrayValue.map({{ variable.typeName.array.elementTypeName.unwrappedTypeName }}.init)
{% elif variable.type.kind == "enum" %}
{{ variable.name }} = {{ variable.unwrappedTypeName }}(rawValue: json["{{ variable.name|camelToSnakeCase }}"].stringValue) ?? {{ variable.defaultValue }}