Skip to content

Instantly share code, notes, and snippets.

View elfenlaid's full-sized avatar
Slow Distillation ⚗️💭

Egor Mihnevich elfenlaid

Slow Distillation ⚗️💭
View GitHub Profile
ole / HeterogeneousDictionary.swift
Last active May 17, 2023 19:23
Code for my article "A heterogeneous dictionary with strong types in Swift"
// A heterogeneous dictionary with strong types in Swift,
// Ole Begemann, April 2022
/// A key in a `HeterogeneousDictionary`.
public protocol HeterogeneousDictionaryKey {
/// The "namespace" the key belongs to. Every `HeterogeneousDictionary` has its associated domain,
/// and only keys belonging to that domain can be stored in the dictionary.
associatedtype Domain
/// The type of the values that can be stored under this key in the dictionary.
associatedtype Value
lydell / .gitignore
Last active December 28, 2022 04:33
Minify Elm code
nicklockwood / CodableVersioning.swift
Last active January 29, 2024 11:31
Example demonstrating how to use versioning for Codable structs
// This gist demonstrates how you can implement versioning for a Codable struct to support loading
// old serialized data after changing the structure. Notable features of this solution:
// * No need to make new properties optional, or to perform post-processing on the struct after
// loading in ordeer to populate missing values
// * No need to change the call site - from the outside this struct behaves just the same
// as if we had implemented codable directly in the normal way.
// * Versioning can be applied individually to parents or leaves in a larger tree of
// structs without affecting the other elements
// * This approach will work even if the original struct was not designed with versioning in mind
jverkoey / UIFont+CustomizedDynamicType.m
Created April 14, 2021 01:07
Dynamic Type system fonts with custom point sizes, weight, and italics
static const CGFloat kFontWeightEpsilon = FLT_EPSILON;
@implementation UIFont (CustomizedDynamicType)
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size
textStyle:(nonnull UIFontTextStyle)textStyle {
return [self preferredFontWithDefaultSize:size
krzysztofzablocki /
Created January 18, 2021 11:29
3rd party tooling processing script
cd "$(dirname "$0")/.."
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then
echo "Running in --fail-on-errors mode"
# make sure you have imagemagick installed: brew install imagemagick
# your file should have the correct permissions: run `chmod 775` in your terminal from where you put this file
# put your `my_icon.png` next to this file and run ./ to export your app icons
# delete the export directory so we start clean
davidsteppenbeck / PreviewProviderModifier.swift
Last active October 31, 2022 10:30
A SwiftUI view modifier for simple preview providers.
import SwiftUI
enum PreviewProviderMode: CaseIterable {
/// Use for a light appearance preview.
case lightMode
/// Use for a dark appearance preview.
case darkMode
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI {
VStack {
Text("Hello, World")
import UIKit
import LinkPresentation
class ViewController: UIViewController {
@IBOutlet weak var sharingButton: UIButton!
private var metaData: LPLinkMetadata = LPLinkMetadata() {
didSet {
DispatchQueue.main.async {