Skip to content

Instantly share code, notes, and snippets.

View regexident's full-sized avatar

Vincent Esche regexident

View GitHub Profile
@anandabits
anandabits / HKT.swift
Last active May 7, 2026 01:30
Emulating HKT in Swift
// This example shows how higher-kinded types can be emulated in Swift today.
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation.
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
/// `ConstructorTag` represents a type constructor.
/// `Argument` represents an argument to the type constructor.
struct Apply<ConstructorTag, Argument> {
/// An existential containing a value of `Constructor<Argument>`
/// Where `Constructor` is the type constructor represented by `ConstructorTag`
@harlanhaskins
harlanhaskins / swift-format.swift
Created October 26, 2017 19:48
Simple Swift Formatter using SwiftSyntax
import Foundation
import SwiftSyntax
func main() throws {
guard CommandLine.arguments.count > 1 else {
print("usage: swift-format [file]")
exit(-1)
}
let url = URL(fileURLWithPath: CommandLine.arguments[1])
@kamyuentse
kamyuentse / cargo-clean.sh
Created October 12, 2017 15:40
Clean cargo project directory recursively
#!/bin/bash
# This a simple bash script to run `cargo clean` recursively.
#
# Usage: `bash cargo-clean.sh target_dir`
clean_recursive() {
# First, check whether current directiry is the root of a cargo project.
if [ -f "Cargo.toml" ]; then
echo "Cleaning \"$(pwd)\""
@frankrausch
frankrausch / String+Hyphenation.swift
Last active June 15, 2023 16:45
Returns a String with soft hyphens (U+00AD)
import Foundation
extension String {
func hyphenated(languageCode: String) -> String {
let locale = Locale(identifier: languageCode)
return self.hyphenated(locale: locale)
}
func hyphenated(locale: Locale) -> String {
@DevAndArtist
DevAndArtist / guardedAreaLayoutGuide.md
Created September 13, 2017 20:47
A layout guide for iOS 10 that is very similar to the `safeAreaLayoutGuide` from iOS 11.

A layout guide for iOS 10 that is very similar to the safeAreaLayoutGuide from iOS 11.

extension UIView {
	///
	private final class LayoutGuide : UILayoutGuide {}
	
	///
	var guardedAreaLayoutGuide: UILayoutGuide {
		if #available(iOS 11, *) {
/*:
This is an implementation of Algorithm W, as found in [Principal Types for functional programs](http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_types.pdf).
We'll start by defining literals and expressions:
*/
enum Literal {
case string(String)
case int(Int)
@CodaFi
CodaFi / AlgorithmW.swift
Last active March 30, 2026 20:33
A Swift Playground containing Martin Grabmüller's "Algorithm W Step-by-Step"
/// Playground - noun: a place where people can play
/// I am the very model of a modern Judgement General
//: # Algorithm W
//: In this playground we develop a complete implementation of the classic
//: algorithm W for Hindley-Milner polymorphic type inference in Swift.
//: ## Introduction
@eisisig
eisisig / tomono.sh
Created November 18, 2016 08:17
convert multiple repos to monorepo
#!/bin/bash
# Merge multiple repositories into one big monorepo. Migrates every branch in
# every subrepo to the eponymous branch in the monorepo, with all files
# (including in the history) rewritten to live under a subdirectory.
#
# To use a separate temporary directory while migrating, set the GIT_TMPDIR
# envvar.
#
# To access the individual functions instead of executing main, source this
@CanTheAlmighty
CanTheAlmighty / DisplayLink.swift
Last active May 24, 2025 06:45
DisplayLink for OSX