Skip to content

Instantly share code, notes, and snippets.

View RhetTbull's full-sized avatar

Rhet Turnbull RhetTbull

View GitHub Profile
@melonamin
melonamin / GetFavoritePhotos.swift
Created September 21, 2024 01:20
Script to get filenames of Favorite photos from Photos.app
import Foundation
import Photos
func requestPhotoLibraryAccess(completion: @escaping (Bool) -> Void) {
PHPhotoLibrary.requestAuthorization { status in
completion(status == .authorized)
}
}
func fetchFavoritePhotos(startDate: Date) -> PHFetchResult<PHAsset> {
@jonashaag
jonashaag / Use macOS OCR engine from Python.md
Last active November 13, 2024 09:42
Use macOS OCR engine from Python

macOS Live Text has a very good quality/speed tradeoff.

Compared to Tesseract, it has much higher quality and is up to 3x as fast.

@adtac
adtac / README.md
Last active October 27, 2024 08:53
Using your Kindle as an e-ink monitor

3.5 fps, Paperwhite 3
@adtac_

step 1: jailbreak your Kindle

mobileread.com is your best resource here, follow the instructions from the LanguageBreak thread

I didn't really follow the LanguageBreak instructions because I didn't care about most of the features + I was curious to do it myself, but the LanguageBreak github repo was invaluable for debugging

@kitschpatrol
kitschpatrol / apple-photos-export.applescript
Last active December 9, 2024 10:10
AppleScript to automate image export from Apple Photos
-- Export images from Photos via automated GUI manipulation
-- It's an unsavory approach, but no other means of automation seems to yield higher quality edited image exports (so far)
-- Arguments are passed in their order of appearance in the GUI, and expect values exactly matching the UI strings in Photos.app
-- Accepts an individual photo UUID, or an album UUID (use osxphotos query to look up UUIDs)
on run { uuid, exportDirectory, photoKind, jpegQuality, tiffBitDepth, colorProfile, photoSize, maxSizeType, maxSizeValue, includeMetadata, includeLocation , fileName, sequentialPrefix, subfolderFormat}
tell application "System Events"
set wasRunning to (name of processes) contains "Photos"
end tell
@willmcgugan
willmcgugan / last_lines.py
Created March 2, 2024 16:10
Get the last lines from a file
import mmap
def get_last_lines(path: str, count: int) -> list[str]:
"""Get count last lines from a file."""
with open(path, "r+b") as text_file:
text_mmap = mmap.mmap(text_file.fileno(), 0, mmap.ACCESS_READ)
position = len(text_mmap)
while count and (position := text_mmap.rfind(b"\n", 0, position)) != -1:
count -= 1
@AlexWaygood
AlexWaygood / last_n_lines.py
Last active March 10, 2024 16:30
Script to find the last `n` lines of a file
import os
from collections import deque
from collections.abc import Iterator, Sequence
from typing import Final, Protocol
class SeekableBytesFile(Protocol):
def seek(self, position: int, whence: int = ..., /) -> int: ...
def read(self, amount: int, /) -> bytes: ...
@RhetTbull
RhetTbull / copyfile.py
Created September 18, 2023 00:24
Copy a file on macOS with Python using native NSFileManager method which takes advantage of copy-on-write on APFS formatted volumes.
"""Copy a file on macOS using native API.
This allows copied files to use copy-on-write when used on a volume formatted with APFS.
When used on an APFS volume, a file copied with this function will be copied almost instantly
and will not use any additional disk space until the file is modified.
To use, you will need to install pyobjc-core and pyobjc-framework-Cocoa:
`python3 -m pip install pyobjc-core pyobjc-framework-Cocoa`
@davidad
davidad / lead.py
Created August 4, 2023 20:14
Lead poisoning data analysis (thanks GPT-4)
import pandas as pd
# Load the data
df = pd.read_excel('pnas.2118631119.sd01.xlsx')
import matplotlib.pyplot as plt
# Filter the data for ages 22-35
df_filtered = df[(df['AGE'] >= 22) & (df['AGE'] <= 35) & (df['YEAR'] >= 1955) & (df['YEAR'] <= 2040)]
@adrienbrault
adrienbrault / llama2-mac-gpu.sh
Last active December 5, 2024 17:40
Run Llama-2-13B-chat locally on your M1/M2 Mac with GPU inference. Uses 10GB RAM. UPDATE: see https://twitter.com/simonw/status/1691495807319674880?s=20
# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# Build it
make clean
LLAMA_METAL=1 make
# Download model
export MODEL=llama-2-13b-chat.ggmlv3.q4_0.bin
#include <stdio.h>
#include <stdint.h>
// Philips Sonicare NFC Head Password calculation by @atc1441 Video manual: https://www.youtube.com/watch?v=EPytrn8i8sc
uint16_t CRC16(uint16_t crc, uint8_t *buffer, int len) // Default CRC16 Algo
{
while(len--)
{
crc ^= *buffer++ << 8;
int bits = 0;
do