Skip to content

Instantly share code, notes, and snippets.

View Alexander-Ignition's full-sized avatar
:atom:

Alexander Ignition Alexander-Ignition

:atom:
View GitHub Profile
@Alexander-Ignition
Alexander-Ignition / codecov.rb
Last active November 26, 2021 09:49
Swift pacakge manager code coverage
require 'pathname'
# Swift pacakge manager code coverage
#
# Usage:
# ruby codecov.rb $(swift test --show-codecov-path)
class Codecov
def initialize(path)
# /Users/<user-name>/<package-name>/.build/x86_64-apple-macosx/debug/codecov/<package-name>.json
@path = Pathname.new(path)
@Alexander-Ignition
Alexander-Ignition / swift_concurrency.md
Last active September 13, 2022 13:19
Swift Concurrency

Swift Concurrency

Flavors of tasks

Type Launched by Launchable from Lifetime Cancellation Inherits from origin
async-let tasks async let async functions scoped by statement automatic prioprity, task-local values
Group tasks group.async withTaskGroup scoped by task group automatic prioprity, task-local values
Unstructured tasks Task.init anywhere unscoped Task.cancel() prioprity, task-local values, actor
Detached tasks Task.detached anywhere unscoped Task.cancel() nothing
@Alexander-Ignition
Alexander-Ignition / codecov.py
Created December 30, 2020 11:57
swift code coverage
import json
import subprocess
from pathlib import Path
def shell(cmd, stdout=None) -> str:
return subprocess.run(cmd.split(' '), stdout=stdout, check=True, text=True).stdout
def get_package() -> dict:
return json.loads(shell('swift package describe --type json', stdout=subprocess.PIPE))
struct ServerRoute {
typealias Handler = (_ request: Request, _ count: Int) -> Response?
enum Method: String {
case GET, POST
}
let method: Method
let pattern: String
let handler: Handler
@Alexander-Ignition
Alexander-Ignition / ArrayBuilder.swift
Last active May 13, 2021 14:36
Simple Swift function builder
@resultBuilder
enum ArrayBuilder {
@inlinable
static func buildExpression<T>(_ expression: T) -> [T] {
[expression]
}
@inlinable
static func buildBlock<T>(_ components: [T]...) -> [T] {
@Alexander-Ignition
Alexander-Ignition / test.sh
Created June 13, 2020 08:07
swift test code coverage
swift test --enable-code-coverage
BINARY_PATH=".build/x86_64-apple-macosx/debug/CombineCoreDataPackageTests.xctest/Contents/MacOS/CombineCoreDataPackageTests"
PROF_DATA_PATH=".build/x86_64-apple-macosx/debug/codecov/default.profdata"
xcrun llvm-cov report \
$BINARY_PATH \
--format=text \
-instr-profile="$PROF_DATA_PATH" \
-ignore-filename-regex=Tests
[1, 2].publisher // Publishers.Sequence<[Int], Never>
Result<Int, Never>.success(1).publisher // Result<Int, Never>.Publisher
Optinal.some(1).publisher // Error! But have Optional.Publisher
// Missing extention
extension Optional {
public var publisher: Optional.Publisher {
Optional.Publisher(self)
func == <T, U>(
keyPath: KeyPath<T, U>,
value: U
) -> (T) -> Bool where U: Equatable {
return { $0[keyPath: keyPath] == value }
}
struct User {
let name: String
}