Skip to content

Instantly share code, notes, and snippets.

humblehacker /
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 /
Last active January 22, 2024 07:07
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
    cd opencv
  2. Disable building with libjpeg-turbo[^1] by applying a patch:
    git apply path/to/opencv-5-28-50.patch
humblehacker / Kotlin generic type constraints are ignored when the inferred type is an
Last active December 18, 2022 17:37
Kotlin generic type constraints are ignored when the inferred type is an
View Kotlin generic type constraints are ignored when the inferred type is an

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 {
humblehacker /
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:

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 / 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.
View LaunchVSMac.applescript
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 / swiftui-prefs.swift
Created January 2, 2020 21:42
Demonstrates setting a preference based on an action
View swiftui-prefs.swift
import SwiftUI
struct ContentView: View {
var body: some View {
WrapperView {
VStack {
humblehacker / George
Created November 12, 2019 23:25
George holder
humblehacker / KeychainItem.swift
Last active September 28, 2019 22:27
Chris Eidhof's KeychainItem property wrapper made generic
View KeychainItem.swift
// KeychainItem.swift
// Created by David Whetstone on 9/28/19.
// Original code by Chris Eidhof
// As yet unlicensed
humblehacker /
Last active March 25, 2023 02:14
Don't expose MutableLiveData
humblehacker / Sequence_associateBy.swift
Created June 27, 2017 23:11
Swift 3 implementation of Kotlin's associateBy for transforming a Sequence to a Dictionary
View Sequence_associateBy.swift
extension Sequence
/// Returns a Dictionary using the result of `keySelector` as the key, and the result of `valueTransform` as the value
public func associateBy<T, K: Hashable, V>(_ keySelector: (T) -> K, _ valueTransform: (T) -> V) -> [K:V] where T == Iterator.Element
var dict: [K:V] = [:]
for element in self {
dict[keySelector(element)] = valueTransform(element)