Skip to content

Instantly share code, notes, and snippets.

@humblehacker
humblehacker / fork-2.46.2-bug-2024.10.26.md
Last active October 26, 2024 13:25
Fork 2.46.2 Bug: Hunk stage/discard buttons overlap search field

Steps:

  • View a file that has more changes than can fit on the screen.
  • Scroll the diff view up a bit so the top of the first hunk is off screen
  • Click in the diff viewer and type ⌘F so search field appears
  • Hover pointer over top hunk

Expected:

Hunk stage/discard buttons appear over diff viewer, below search field

Observed:

@humblehacker
humblehacker / transformingAttributes.swift
Created October 15, 2024 20:55
Experimenting with AttributedString.transformingAttributes
import SwiftUI
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@humblehacker
humblehacker / next-karabiner-profile.sh
Created January 14, 2024 18:05
Choose next Karabiner profile
#!/usr/bin/env zsh
alias kb="/Library/Application\ Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli"
# Get the list of items
IFS=$'\n' items=($(kb --list-profile-names))
# Get the current item
current_item=$(kb --show-current-profile-name)
@humblehacker
humblehacker / make-opencv2-xcframework.md
Last active September 6, 2024 09:46
Make opencv2.xcframework for iOS arm64, and iOSSimulator arm64 & x86_64

I had some trouble attempting to build an XCFramework of OpenCV, but I finally got a successful build with the following steps:

  1. Clone the OpenCV repo:
    git clone [email protected]:opencv/opencv.git
    cd opencv
    
  2. Disable building with libjpeg-turbo[^1] by applying a patch:
    git apply path/to/opencv-5-28-50.patch
@humblehacker
humblehacker / Kotlin generic type constraints are ignored when the inferred type is an interface.md
Last active December 18, 2022 17:37
Kotlin generic type constraints are ignored when the inferred type is an interface.md

tl;dr: I expect the following code to fail to compile as NotABlob fails the Blob type constraint:

open class Blob
interface NotABlob

fun <T: Blob> foo(): T {
   TODO()
}
@humblehacker
humblehacker / kotlin-inject-composable-viewmodel.md
Last active March 17, 2022 13:56
Injecting view models into Composable functions with kotlin-inject

According to the docs, the non-DI way to associate an view model with an @Composable is via the viewModel() function from androidx.lifecycle.viewmodel.compose.viewModel, like this:

@Composable
fun ProfileScreen(val viewModel: ProfileViewModel = viewModel() {
  ...

But if your view model requires dependencies, you have to pass a subclass of ViewModelProvider.Factory that holds the dependency and knows how to construct the view model for you. Like this:

@humblehacker
humblehacker / LaunchVSMac.applescript
Last active June 26, 2020 00:11
Given an absolute path, line number, and column number, launch Visual Studio for Mac and go there.
on run {filepath, linenumber, columnnumber}
tell application "Visual Studio" to activate
tell application "System Events"
-- ⌘O File → Open...
keystroke "o" using command down
delay 1
@humblehacker
humblehacker / swiftui-prefs.swift
Created January 2, 2020 21:42
Demonstrates setting a preference based on an action
import SwiftUI
struct ContentView: View {
var body: some View {
WrapperView {
VStack {
PrefView()
PrefView()
}
}
@humblehacker
humblehacker / George
Created November 12, 2019 23:25
George holder
george
@humblehacker
humblehacker / KeychainItem.swift
Last active September 28, 2019 22:27
Chris Eidhof's KeychainItem property wrapper made generic
//
// KeychainItem.swift
//
// Created by David Whetstone on 9/28/19.
//
// Original code by Chris Eidhof
// https://github.com/objcio/keychain-item
// As yet unlicensed