Skip to content

Instantly share code, notes, and snippets.

View MaxDesiatov's full-sized avatar
🇺🇦
#StandWithUkraine

Max Desiatov MaxDesiatov

🇺🇦
#StandWithUkraine
View GitHub Profile
@ole
ole / thirty-days-of-metal.md
Last active May 1, 2024 19:19
Warren Moore – Thirty Days of Metal
@DougGregor
DougGregor / macros.md
Last active October 24, 2023 16:42
A possible vision for macros in Swift

A Possible Vision for Macros in Swift

As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.

There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable conformances, for ex

@slimsag
slimsag / ramblings.md
Last active December 13, 2023 08:02
Because cross-compiling binaries for Windows is easier than building natively

Because cross-compiling binaries for Windows is easier than building natively

I want Microsoft to do better, want Windows to be a decent development platform-and yet, I constantly see Microsoft playing the open source game: advertising how open-source and developer friendly they are - only to crush developers under the heel of the corporate behemoth's boot.

The people who work at Microsoft are amazing, kind, talented individuals. This is aimed at the company's leadership, who I feel has on many occassions crushed myself and other developers under. It's a plea for help.

The source of truth for the 'open source' C#, C++, Rust, and other Windows SDKs is proprietary

You probably haven't heard of it before, but if you've ever used win32 API bindings in C#, C++, Rust, or other languages, odds are they were generated from a repository called microsoft/win32metadata.

# $ ruby ./bisect-toolchain-snapshot.rb swift-wasm-DEVELOPMENT-SNAPSHOT-2021-12-12-a swift-wasm-DEVELOPMENT-SNAPSHOT-2022-04-06-a run.sh --workdir /tmp/toolchain-bisect
require "date"
require "net/http"
require "json"
require "tmpdir"
def bisect_date_seq(candidates)
bad = 0
good = candidates.length - 1
@keith
keith / README.md
Last active January 9, 2024 07:52
A test of `@_dynamicReplacement` in Swift

Usage

  1. swiftc main.swift -emit-module-path main.swiftmodule -emit-executable -enable-private-imports -Xfrontend -enable-implicit-dynamic
  2. ./main -> prints From original bar()
  3. swiftc -emit-library inject.swift -o inject.dylib -I . -Xlinker -undefined -Xlinker suppress -Xlinker -flat_namespace -Xfrontend -disable-access-control
  4. DYLD_INSERT_LIBRARIES=inject.dylib ./main -> prints From replacement bar()

Notes

  • Passing -Xfrontend -enable-implicit-dynamic removes you from having to add dynamic to everything you want to be replacable
@nicklockwood
nicklockwood / JaroWinkler.swift
Created December 21, 2020 18:52
Swift code to calculate the Jaro-Winkler edit distance between two strings
/// The Jaro-Winkler edit distance between two strings (0 - 1)
func editDistance(_ lhs: String, _ rhs: String) -> Double {
return 1 - jaroWinklerSimilarity(Array(lhs), Array(rhs))
}
/// Jaro-Winkler similarity between two strings (0 - 1)
/// https://www.geeksforgeeks.org/jaro-and-jaro-winkler-similarity/
private func jaroWinklerSimilarity(_ s1: [Character], _ s2: [Character]) -> Double {
var jaro = jaroSimilarity(s1, s2)
# IDA (disassembler) and Hex-Rays (decompiler) plugin for Apple AMX
#
# WIP research. (This was edited to add more info after someone posted it to
# Hacker News. Click "Revisions" to see full changes.)
#
# Copyright (c) 2020 dougallj
# Based on Python port of VMX intrinsics plugin:
# Copyright (c) 2019 w4kfu - Synacktiv
@dabrahams
dabrahams / Example1.swift
Last active August 4, 2021 18:28
Ambiguity problems with giving generic types the right behavior with conditional conformances
protocol P { var pop: String { get } }
extension P {
var pop: String { "slow" }
var pop1: String { pop }
}
protocol Q: P {}
extension Q { var pop: String { "fastQ" } }
protocol R: P {}
@dabrahams
dabrahams / FactoryInitialization.swift
Last active October 22, 2022 13:46
Class factory initializers
/// Classes whose initializers actually create derived classes
protocol FactoryInitializable {
/// The type of the least-derived class declared to be FactoryInitializable.
///
/// - Warning: Do not define this in your FactoryInitializable type!
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self
// This associatedtype is a trick that captures `Self` at the point where
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self`
// refers to the most-derived type.
}
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))