Skip to content

Instantly share code, notes, and snippets.

@dennislysenko
dennislysenko / BKTree.swift
Created June 11, 2015 02:09
Fuzzy String Matching (BK Tree)
// Fuzzy string-matching algorithm
// Implementation of algorithm described at: http://blog.notdot.net/2007/4/Damn-Cool-Algorithms-Part-1-BK-Trees
// Essentially builds an index of strings by levenshtein distance (N-ary tree) on which you can run range queries.
// The root node can be chosen arbitrarily. Each node holds a string and a collection of edges, representing distance to other strings, which then have their own children and so on, building a complete index.
// See https://github.com/vy/bk-tree for (impressive) performance statistics despite this tending to create an unbalanced N-ary tree
class BKTreeNode {
var value: String
var edges: Dictionary<Int, BKTreeNode>
@nlutsenko
nlutsenko / yolo.sh
Last active October 20, 2025 22:14
Fast Xcode builds
defaults write xcodebuild PBXNumberOfParallelBuildSubtasks 4
defaults write xcodebuild IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4
defaults write com.apple.xcode PBXNumberOfParallelBuildSubtasks 4
defaults write com.apple.xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4
@vasanthk
vasanthk / System Design.md
Last active November 7, 2025 20:14
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
import Foundation
protocol Monoid {
static var zero: Self { get }
func appending(_: Self) -> Self
}
struct AnyMonoid<Type> {
var zero: Type
let append: (Type, Type) -> Type
@0xjac
0xjac / private_fork.md
Last active November 7, 2025 23:54
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare [email protected]:usi-systems/easytrace.git

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active October 31, 2025 02:41
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

@CrystDragon
CrystDragon / ExploreSRGB.swift
Last active October 24, 2022 15:03
Explore gamma correction related properties on iOS
// test in playground targeting iOS
import UIKit
import QuartzCore
let sRGBSpace = CGColorSpace(name: CGColorSpace.sRGB)!
let linearSpace = CGColorSpace(name: CGColorSpace.linearSRGB)!
func dumpImageFirstPixel(_ image: UIImage) {
guard let cgImage = image.cgImage,
let dataBuffer = cgImage.dataProvider?.data as Data?,
@RobRuana
RobRuana / AgileContractGuide.md
Last active October 1, 2023 17:41
Agile Contract Guide

Agile Contract Guide

This document is a guide to writing agile contracts. Unlike traditional contracts, an agile contract does not specify individual tasks to be completed by the Contractor. Rather, an agile contract specifies how the Client and Contractor interact, and how the Contractor is paid. The Deliverable Work performed for the contract is determined through an ongoing collaboration between the Client and the Contractor.

Agile contracts require a great deal of trust from both the Client and the Contractor. This trust is fostered through tight feedback cycles and well-defined responsibilities that both parties can expect from each other. More so than traditional contracts, an agile contract requires active participation from the Client.

@vahan3x
vahan3x / Shaders.metal
Created October 1, 2018 17:41
Displaying image with normalized Display P3 colors. For use with Metal textures using bgra10_xr_srgb pixel format.
// Simple RGB to Linear RGB function respecting negative values
half channelToLinearChannel(half channel) {
if (fabs(channel) <= 0.04045) {
return channel / 12.92;
}
return sign(channel) * pow((fabs(channel) + 0.055) / 1.055, 2.4);
}
// Converting RGB to Linear RGB
@dsabanin
dsabanin / enable-xcode-debug-menu.sh
Last active November 7, 2022 16:17
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode