Skip to content

Instantly share code, notes, and snippets.

@ashwch
ashwch / git-worktrees-zero-to-hero.md
Last active December 8, 2025 08:30
Git Worktrees: From Zero to Hero - A comprehensive guide to using Git worktrees with submodules
@fatbobman
fatbobman / dynamicHeightSheet.swift
Created April 5, 2024 06:59
a dynamic sheet demo
import SwiftUI
struct ContentView: View {
@State var show = false
@State var height: CGFloat = 250
var body: some View {
List {
Button("Pop Sheet") {
height = 250
show.toggle()
@NoahKamara
NoahKamara / CompoundPredicate.swift
Last active November 12, 2025 16:41
Combining New Swift Predicates
import Foundation
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
/// Allows you to use an existing Predicate as a ``StandardPredicateExpression``
struct VariableWrappingExpression<T>: StandardPredicateExpression {
let predicate: Predicate<T>
let variable: PredicateExpressions.Variable<T>
func evaluate(_ bindings: PredicateBindings) throws -> Bool {
// resolve the variable
extension Task where Failure == Error {
// Start a new Task with a timeout. If the timeout expires before the operation is
// completed then the task is cancelled and an error is thrown.
init(priority: TaskPriority? = nil, timeout: TimeInterval, operation: @escaping @Sendable () async throws -> Success) {
self = Task(priority: priority) {
try await withThrowingTaskGroup(of: Success.self) { group -> Success in
group.addTask(operation: operation)
group.addTask {
try await _Concurrency.Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))
@bennlee
bennlee / remapping-keys-via-hidutil.md
Created November 19, 2021 05:39
How to remapping keys on macOS without thirdparty applications.

How to remapping keys on macOS without thirdparty applications.

You could remapping keys via the macOS embedded command line tool hidutil.


Key IDs Table
Usage Usage ID (hex) Usage Usage ID (hex) Usage Usage ID (hex) Usage Usage ID (hex)
@mjackson
mjackson / composing-route-in-react-router-v6.md
Last active October 30, 2025 21:05
Notes on route composition in React Router v6, along with a suggested improvement you can make today to start upgrading

Composing <Route> in React Router v6

Composition of <Route> elements in React Router is changing in v6 from how it worked in v4/5 and in Reach Router. React Router v6 is the successor of both React Router v5 and Reach Router.

This document explains our rationale for making the change as well as a pattern you will want to avoid in v6 and a note on how you can start preparing your v5 app for v6 today.

Background

In React Router v5, we had an example of how you could create a element](https://github.com/remix-run/react-router/blob/320be7afe44249d5c025659bc00c3276a19f0af9/packages/react-router-dom/examples/Auth.js#L50-L52) to restrict access to certain routes on the page. This element was a simple [wrapper around an actual element that made a simple decision: is the user authenticated or not? If so, ren

@Mordo95
Mordo95 / keyboard_shortcuts.js
Last active July 29, 2024 21:16
Keyboard shortcuts for google and youtube
// ==UserScript==
// @name Keyboard shortcuts for google and youtube
// @version 0.1
// @description Adds shortcuts for google and youtube
// @author Mordo95
// @match *://*/*
// @icon https://www.google.com/s2/favicons?domain=google.nl
// @grant none
// ==/UserScript==
@slikts
slikts / advanced-memo.md
Last active February 25, 2025 15:19
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
@fewlinesofcode
fewlinesofcode / RedBlackTree.swift
Created February 10, 2020 16:14
Red-Black Tree implementation in Swift
//
// main.swift
// Beachline
//
// Created by Oleksandr Glagoliev on 1/4/20.
// Copyright © 2020 Oleksandr Glagoliev. All rights reserved.
//
import Foundation
@VictorDarvariu
VictorDarvariu / np_seed_contextmanager.py
Created February 5, 2020 10:11
Example of managing NumPy seed with contextmanager
import contextlib
import numpy as np
# For info on contextlib, see https://docs.python.org/3/library/contextlib.html
@contextlib.contextmanager
def local_seed(seed):
state = np.random.get_state()
np.random.seed(seed)
try:
yield