Skip to content

Instantly share code, notes, and snippets.

View hguandl's full-sized avatar

Hao Guan hguandl

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / now-playing.js
Last active July 3, 2025 05:25
AppleScript and JXA scripts to get Now Playing info. Works on macOS 15.4+, including macOS 26 beta 1.
function run() {
const MediaRemote = $.NSBundle.bundleWithPath('/System/Library/PrivateFrameworks/MediaRemote.framework/');
MediaRemote.load
const MRNowPlayingRequest = $.NSClassFromString('MRNowPlayingRequest');
const appName = MRNowPlayingRequest.localNowPlayingPlayerPath.client.displayName;
const infoDict = MRNowPlayingRequest.localNowPlayingItem.nowPlayingInfo;
const title = infoDict.valueForKey('kMRMediaRemoteNowPlayingInfoTitle');
@thelastlin
thelastlin / libsk-libfido2_BUILD_FROM_OPENSSH.md
Last active March 22, 2025 14:07
Build libsk-libfido2.so from OpenSSH-portable

Tested on macOS Sonoma Developer beta 2 (23A5276g)

Build libsk-libfido2.so

Prerequisite

  1. Download openssh-portable source code, install libcrypto, libfido2;
  2. Configure openssh-portable build system by ./configure # [options].

Apply patch

@joelekstrom
joelekstrom / SwiftUIDoubleClickModifier.swift
Last active February 22, 2025 21:22
A view modifier that can reliably detect double clicks on macOS, even in List
extension View {
/// Adds a double click handler this view (macOS only)
///
/// Example
/// ```
/// Text("Hello")
/// .onDoubleClick { print("Double click detected") }
/// ```
/// - Parameters:
/// - handler: Block invoked when a double click is detected
@kenji21
kenji21 / xcode-previous-older-sdks.md
Last active April 13, 2025 17:23
Use previous/older SDKs with Xcode
@luncliff
luncliff / test_libdispatch.cpp
Last active January 18, 2024 21:56
C++ 20 Coroutines with libdispatch (Apple platform)
/**
* @author github.com/luncliff ([email protected])
* @brief Personal experiment with libdispatch in Apple platform.
*
* @note clang++ -std=c++2a -stdlib=libc++ -fcoroutines-ts
* @see https://developer.apple.com/library/archive/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html
* @see https://apple.github.io/swift-corelibs-libdispatch/tutorial/
*/
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_FAST_COMPILE
@importRyan
importRyan / whenHovered.md
Last active June 28, 2025 09:03
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@hishnash
hishnash / ExampleWindowReaderApp.swift
Created December 21, 2020 05:59
Access to the underlying UIWindow & NSWindow in swiftUI gives access to window methods and attributes.
//
// ExampleWindowReaderApp.swift
// Shared
//
// Created by Matthaus Woolard on 21/12/2020.
//
import SwiftUI
@main
@mohammadnassiri
mohammadnassiri / numpy_big_sur_issues.md
Last active November 27, 2020 03:20
numpy and its related packages (matplotlib, scipy, pandas, etc) installation problems in MacOS 11 (Big Sur)

If you have issues with installing numpy related packages on Big sur, these steps helped me: 1- Uninstall pyhon installed with homebrew and use python-installer. This resolves numpy issue. And it's better to install 1.18 or just anything bellow 1.19.

brew uninstall python

And install it from: https://www.python.org/downloads/
Then:

pip install numpy==1.18
@dragolabs
dragolabs / ubuntu-vnc-without-monitor.md
Created April 29, 2020 20:09
Run VNC without connected monitor to ubuntu Desktop

Install Video Dummy Package

sudo apt-get install xserver-xorg-video-dummy

Create Default X Windows Configuration File

Create / Edit xorg.conf file Rename file if already exists for backup

@Thomvis
Thomvis / Migrated.swift
Last active October 30, 2024 07:43
An approach towards migrating properties in a Codable struct without having to write a custom Codable implementation
import Cocoa
// Say we have a Person model
enum V1 {
struct Person: Codable {
let name: String
var age: Int
}
}