Skip to content

Instantly share code, notes, and snippets.

View RhetTbull's full-sized avatar

Rhet Turnbull RhetTbull

View GitHub Profile
@kitschpatrol
kitschpatrol / apple-photos-export.applescript
Last active May 7, 2024 20:09
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 April 22, 2024 08:47
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
@tech234a
tech234a / README.md
Last active June 10, 2023 14:03
Using unmodified third-party Reddit apps with a custom server
@kconner
kconner / macOS Internals.md
Last active May 25, 2024 19:26
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

@rain-1
rain-1 / LLM.md
Last active May 26, 2024 17:46
LLM Introduction: Learn Language Models

Purpose

Bootstrap knowledge of LLMs ASAP. With a bias/focus to GPT.

Avoid being a link dump. Try to provide only valuable well tuned information.

Prelude

Neural network links before starting with transformers.