Skip to content

Instantly share code, notes, and snippets.

View PerArneng's full-sized avatar
💯

Per Arneng PerArneng

💯
View GitHub Profile
@PerArneng
PerArneng / mouse_debug.swift
Last active March 30, 2025 15:33
This gist demonstrates a Swift script that sets up a global event tap on macOS to capture mouse button presses. It logs which mouse button is pressed, along with the frontmost application’s bundle identifier and window title, requiring appropriate Accessibility permissions granted in System Settings → Privacy & Security → Accessibility.
#!/usr/bin/env swift
import Cocoa
import CoreGraphics
// We store the event tap reference globally so we can re-enable it if it's disabled:
var eventTapCFMachPort: CFMachPort?
// MARK: - Helper to Get Frontmost App Info
func frontmostAppInfo() -> (bundleID: String?, windowTitle: String?) {
# requires python 3
import getpass
import hashlib
import random
#from typing import List
import sys
import math
use std::io;
use std::io::Write;
fn main() {
let mut input = String::new();
let result = io::stdin().read_line(&mut input)
.map(|s:usize| input)
.and_then(|s:String| s.parse::<u32>());
@PerArneng
PerArneng / gist:13e90e0a7bdc2f6e8172
Created October 9, 2014 07:16
A Bash function to find a directory and `cd` in to the first match. It works with wildcards `*` and `?`
function cdf() { cd `find . -type d -name "$1" | head -n1`; }