Skip to content

Instantly share code, notes, and snippets.

@agmm
agmm / lightsensor.mm
Last active April 16, 2024 13:56
Ambient light sensor reader (macOS)
// References:
// https://stackoverflow.com/questions/17625495/how-do-you-programmatically-access-the-ambient-light-sensor-on-mac-os-x-10-5
// https://stackoverflow.com/a/73955907
// Build command:
// clang -o lightsensor lightsensor.mm -F /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/PrivateFrameworks -framework Foundation -framework IOKit -framework CoreFoundation -framework BezelServices
#include <mach/mach.h>
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
@agmm
agmm / youtube-ublock-filter.txt
Created April 12, 2024 16:44
uBlock filter to disable YouTube's new UI
! uBlock filter to disable YouTube's new UI
youtube.com##+js(set, yt.config_.EXPERIMENT_FLAGS.kevlar_watch_grid, false)
@agmm
agmm / setpam.sh
Last active January 1, 2024 13:45
Script to enable Touch ID authentication for sudo commands
#!/bin/bash
# Script to enable Touch ID authentication for sudo
echo "Current config:"
cat /etc/pam.d/sudo
echo "Press ENTER to continue"
read
@agmm
agmm / raspi-leds.sh
Created September 9, 2023 12:10
Script to control the onboard LEDs of the Raspberry Pi
#!/bin/bash
# Usage: leds <state>, where state can be 0 or 1
sudo sh -c "echo $1 > /sys/class/leds/PWR/brightness"
sudo sh -c "echo $1 > /sys/class/leds/ACT/brightness"
@agmm
agmm / yt-mp3.sh
Created March 24, 2023 15:29
Download Youtube video as MP3 using Podman
podman run -i --rm -v "$(pwd)":/data w33ble/youtube-dl -x --audio-format mp3 "$1"
@agmm
agmm / bt-scan-1.sh
Created January 21, 2023 20:01
Bluetooth Scan Method 1
sudo hcitool lescan --duplicates
@agmm
agmm / enable-gpio-shutdown-raspberry-pi.md
Created September 11, 2022 14:01
enable-gpio-shutdown-raspberry-pi.md

Edit /boot/config.txt and add the following line:

dtoverlay=gpio-shutdown,gpio_pin=3
@agmm
agmm / pi-temperature-fahrenheit.md
Created August 24, 2022 17:25
pi-temperature-fahrenheit
/usr/bin/vcgencmd measure_temp | awk -F "[=']" '{print($2 * 1.8)+32}'
@agmm
agmm / pam-sudo-lifesaver.md
Last active March 31, 2022 16:33
Quick guide to restore /etc/pam.d/sudo

Quick guide to restore /etc/pam.d/sudo

  1. Create a file named sudo with the following content:
# sudo: auth account password session
auth sufficient pam_smartcard.so
auth required pam_opendirectory.so
account required pam_permit.so
password required pam_deny.so
session required pam_permit.so
@agmm
agmm / hot-corners.sh
Last active March 29, 2022 12:16
Script to configure the bahavior of hot corners programatically (macOS)
# Possible values:
# 0: no-op
# 2: Mission Control
# 3: Show application windows
# 4: Desktop
# 5: Start screen saver
# 6: Disable screen saver
# 7: Dashboard
# 10: Put display to sleep
# 11: Launchpad