Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@helje5
helje5 / CompareAnySwift57.swift
Created August 2, 2023 16:20
Compare Any w/ Swift 5.7
func isEqual(_ lhs: Any, _ rhs: Any) -> Bool {
guard let lhs = lhs as? any Equatable else { return false }
func isEqual<T: Equatable>(lhs: T, rhs: Any) -> Bool {
guard let rhs = rhs as? T else { return false }
return lhs == rhs
}
return isEqual(lhs: lhs, rhs: rhs)
}
@maelvls
maelvls / How-to-automate-build-bottles-your-homebrew-tap.md
Last active October 31, 2023 03:33
Automate build workflow for Homebrew tap bottles (Linux and macOS)

How to automate the build of bottles on your Homebrew tap

Note on Oct 4, 2018: due to a change in Homebrew's brew test-bot behaviour, the user must set HOMEBREW_TRAVIS_CI and HOMEBREW_TRAVIS_SUDO appropriately (it was previously using Travis-CI-provided TRAVIS and TRAVIS_SUDO).

This tutorial is a follow-up to the discussion we had on davidchall/homebrew-hep#114. It relies on a fork of the test-bot provided by davidchall; you can get it with brew tap maelvalais/test-bot. First:

  1. the Github project must be of the form https://github.com//homebrew- with the following tree
@finestructure
finestructure / Charting.swift
Last active October 23, 2023 20:22
Swift playground example to create charts with a PDF export button
import SwiftUI
import Charts
import PlaygroundSupport
let spiData: [(package: String, fileCount: Int, mbSize: Int)] = [
(package: "swift-markdown-ui", fileCount: 3796, mbSize: 44),
(package: "Microya", fileCount: 414, mbSize: 4),
(package: "swift-url-routing", fileCount: 9430, mbSize: 101),
@chriseidhof
chriseidhof / helloworld.swift
Created May 28, 2018 13:58
NIO Hello World
import Foundation
import NIO
import NIOHTTP1
// Inspired/parts copied from http://www.alwaysrightinstitute.com/microexpress-nio/
final class HelloHandler: ChannelInboundHandler {
typealias InboundIn = HTTPServerRequestPart
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {

Writing template strings in Markdown

With template strings coming to ES6, the backtick (`) means something in Markdown and in JavaScript. If you write this:

To display a message, write `alert(`hello world!`)`.

it'll render like this:

To display a message, write alert(hello world!).

/// - returns: `true` when dynamic type is `Equatable` and `==` returns `true`, otherwise `false`.
func areEquatablyEqual(_ lhs: Any, _ rhs: Any) -> Bool {
func receiveLHS<LHS>(_ typedLHS: LHS) -> Bool {
guard
let rhsAsLHS = rhs as? LHS
else { return false }
return areEquatablyEqual(typedLHS, rhsAsLHS)
}
return _openExistential(lhs, do: receiveLHS)
}
@IanKeen
IanKeen / FocusState.swift
Last active June 30, 2023 17:00
SwiftUI: FocusedState shim for < iOS15
import Combine
import SwiftUI
extension View {
public func focused<T>(file: StaticString = #file, _ state: FocusState<T>, equals value: T) -> some View {
modifier(FocusedModifier(state: state, id: value, file: file))
}
}
@propertyWrapper
@IanKeen
IanKeen / Combined+.swift
Last active March 23, 2023 18:21
Combined: A type composed of other types (potential alternative to my Partial<T> type)
@dynamicMemberLookup
struct Combined<A, B> {
private let a: A
private let b: B
init(a: A, b: B) { (self.a, self.b) = (a, b) }
subscript<T>(dynamicMember keyPath: KeyPath<A, T>) -> T {
return a[keyPath: keyPath]
}
@phranck
phranck / TassenGugelhupf.swift
Last active March 21, 2023 07:53
Backanleitung fuer einen Tassen-Gugelhupf
// TassenGugelhupf.swift
// Created by Frank Gregor on 18.03.23.
//
// This code compiles perfectly. Just paste it into a Playground and...
// "Let it go"
//
// You nay ask: "Why so complicated?"
// Well, the initial impulse came from this Mastodon thread:
// https://swiftdev.space/@phranck/110045414485613046
//