Skip to content

Instantly share code, notes, and snippets.

View regexident's full-sized avatar

Vincent Esche regexident

View GitHub Profile
@quad
quad / 0-modular-errors-with-rusts-thiserror.md
Last active April 20, 2024 07:22
Modular Errors with Rust's thiserror

I've been writing Rust full-time with a small team for over a year now. Throughout, I've lamented the lack of clear best practices around defining error types. One day, I'd love to write up my journey and enumerate the various strategies I've both seen and tried. Today is not that day.

Today, I want to reply to a blog post that almost perfectly summarised my current practice.

Go read it; I'll wait!


@bjhomer
bjhomer / cross-view-lines.swift
Last active November 5, 2022 05:31
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
@catlan
catlan / README.md
Last active February 27, 2023 16:19 — forked from zrxq/.lldbinit
Execute lldb command and open its output in Kaleidoscope diff

Diff output of two lldb commands

Setup

  1. Copy the contents of the last snippet (lldbinit) from the gist page, and paste into your .lldbinit file. This makes the ksdiff macro known inside lldb.
  2. Put file ksdiff.py in ~/.lldb/
  3. sudo pip install temp
  4. Restart Xcode debug session

Example

(lldb) ksdiff ;

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@bkase
bkase / algorithm-w.swift
Created January 5, 2018 06:00
Type Inference Algorithm W (ported from Swift Sandbox)
// Algorithm W
// From Principal Types for functional programs
// http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_types.pdf
// by bkase
// STD library
infix operator <>: AdditionPrecedence
extension Dictionary {
static func <>(lhs: Dictionary, rhs: Dictionary) -> Dictionary {
var d: [Key: Value] = [:]
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
@anandabits
anandabits / HKT.swift
Last active December 25, 2023 00:57
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`