Skip to content

Instantly share code, notes, and snippets.

Avatar

Ilya Puchka ilyapuchka

View GitHub Profile
View NestedDecodable.swift
import Foundation
public struct Unit: Codable, Equatable {
init() {}
public init(from decoder: Decoder) {}
public func encode(to encoder: Encoder) throws {}
public static func ==(lhs: Self, rhs: Self) -> Bool {
return true
}
}
View Stringify.swift
func stringify(@StringBuilder _ value: () -> Stringified) {
print(value().value)
}
struct Stringified {
let value: String
init(_ value: String) {
self.value = "stringified " + value
}
}
@ilyapuchka
ilyapuchka / create_xcode_snippets.rb
Last active Sep 9, 2018
Generate Xcode snippets from XCTest_Gherkin step definitions
View create_xcode_snippets.rb
#!/usr/bin/env ruby
# Usage:
# chmod 755 create_xcode_snippets.rb
# ./create_xcode_snippets.rb --project_path "path-to-project-file.xcodeproj"
require 'xcodeproj'
$project_path = File.expand_path(ARGV.find.with_index { |item, index| ARGV[index - 1] == "--project_path" })
$snippets_path = File.expand_path("~/Library/Developer/Xcode/UserData/CodeSnippets/")
$snippet_prefix = "STEP-"
View Assert.swift
func AssertNoThrow<T>(_ expression: @autoclosure () throws -> T, file: StaticString = #file, line: UInt = #line) rethrows -> T {
do {
return try expression()
} catch {
XCTFail("\(error)", file: file, line: line)
throw error
}
}
func returnSomethingOrThrow() throws -> Int { ... }
@ilyapuchka
ilyapuchka / Enums.swift
Created Nov 6, 2017
Codable tips suggestions
View Enums.swift
/*
Instead of using enum it's possible to use RawRepresentable struct that will give you support for "unsupported" values,
but will cost you excastive switches (you'll alwyas have to handle default case, which will stand for those "unsupported" values)
It's defenetely more code than if using optional, but might be better if it comes to unwrapping this value everywhere.
*/
//enum System: String, Decodable {
// case ios, macos, tvos, watchos
//}
struct System: RawRepresentable, Decodable {
@ilyapuchka
ilyapuchka / Export in Paw.workflow
Last active Dec 22, 2017
Export to Paw automation script
View Export in Paw.workflow
// First make sure that you have granted access to Automator, Xcode and Paw in accessibility section in Security & Privacy settings.
// Then create a new Service workflow in Automator with following actions:
1. Copy to clipboard
2. Launch Application: "Paw"
3. Run AppleScript:
tell application "System Events"
tell process "Paw"
click menu item "Text" of menu 1 of menu item "Import" of menu 1 of menu bar item "File" of menu bar 1
View references.swift
//: Playground - noun: a place where people can play
import Foundation
final class Disposable {
private let dispose: () -> ()
init(_ dispose: @escaping () -> ()) {
self.dispose = dispose
}
@ilyapuchka
ilyapuchka / lint.sh
Last active Jul 15, 2019
Run swiftlint only on files changed from the latest commit
View lint.sh
!/bin/sh
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
FILES=($(git ls-files -m | grep ".*\.swift$" | grep -v ".*R.generated.swift$"))
if [[ ${FILES[@]} ]]; then
export "SCRIPT_INPUT_FILE_COUNT"="${#FILES[@]}"
for i in "${!FILES[@]}"; do
export "SCRIPT_INPUT_FILE_$i"="${FILES[$i]}"
done
@ilyapuchka
ilyapuchka / StickyLayout.swift
Last active Jun 2, 2020
Really sticky collection view layout
View StickyLayout.swift
// The issue with sectionHeadersPinToVisibleBounds and sectionFootersPinToVisibleBounds is that they do not pin
// first header and last footer when bouncing. This layout subclass fixes that.
class StickyLayout: UICollectionViewFlowLayout {
override init() {
super.init()
self.sectionFootersPinToVisibleBounds = true
self.sectionHeadersPinToVisibleBounds = true
}
View EmbassyRedirectUITests.swift
import XCTest
import Ambassador
import Embassy
class EmbassyRedirectUITests: XCTestCase {
var app: XCUIApplication!
var router: Router!
private var eventLoop: EventLoop!
You can’t perform that action at this time.