Skip to content

Instantly share code, notes, and snippets.

View adamelliotfields's full-sized avatar
🤗
hf.co/adamelliotfields

Adam Fields adamelliotfields

🤗
hf.co/adamelliotfields
View GitHub Profile
@adamelliotfields
adamelliotfields / aspect_ratio.py
Created August 26, 2024 20:21
Python Aspect Ratio
def aspect_ratio(width=0, height=0):
if width <= 0 or height <= 0:
return None
a, b = width, height
while b:
a, b = b, a % b
gcd = a
return (width // gcd, height // gcd)
@adamelliotfields
adamelliotfields / scripts.md
Created July 12, 2024 12:21
Maintain Relative Paths in Shell Scripts

You can use the $0 variable to get the script's path:

cat "$(dirname $0)/some/file.txt"

If you have Bash, you can use ${BASH_SOURCE[0]} instead of $(dirname $0), to avoid spawning a subshell. To test, create 2 files in /tmp/test:

mkdir -p /tmp/test
@adamelliotfields
adamelliotfields / civitai.md
Last active March 24, 2025 11:40
Download CivitAI Files from Command Line

Use token query param not Authorization header. Ensure URL has "download" in it. Creating an API token is at the bottom of Account Settings.

Curl

curl -Lo add-detail-xl.safetensors https://civitai.com/api/download/models/135867?token=$CIVIT_TOKEN

Wget

@adamelliotfields
adamelliotfields / cuda.md
Last active August 4, 2024 22:49
Install NVIDIA CUDA and cuDNN on WSL2 for TensorFlow

When neural network frameworks are built, they are dynamically linked to CUDA and cuDNN libraries. These are so or shared object files that are loaded at runtime. The LD_LIBRARY_PATH environment variable tells Ubuntu where to look for these files.

On Windows, these are dll or dynamic link library files.

Why?

GPUs were originally designed for graphics. When you're running a neural network, you're not using the GPU for graphics. CUDA (Compute Unified Device Architecture) is a general-purpose computing on GPUs (GPGPU) platform that allows C-code to run on the GPU. cuDNN (CUDA Deep Neural Network) is a library of primitives like matrix multiplication and convolution that are optimized for GPUs.

To ensure everything works, you want your system to provide the versions of CUDA and cuDNN that your software expects.

@adamelliotfields
adamelliotfields / tunnel.md
Last active October 15, 2024 22:46
Cloudflare Tunnel Instructions

Cloudflare Tunnel Instructions

This assumes you have a free Cloudflare account and you're already using it as your DNS provider. Also, this is going to be using cloudflared directly on-demand, rather than an always-on systemd service. Based on the official tutorial.

Install cloudflared

Installing the system service is optional.

# mac
@adamelliotfields
adamelliotfields / typography.md
Last active December 29, 2023 03:08
Tailwind Typography Markdown Sample Copy

Tailwind Typography

Until now, trying to style an article, document, or blog post with Tailwind has been a tedious task that required a keen eye for typography and a lot of complex custom CSS.

By default, Tailwind removes all of the default browser styling from paragraphs, headings, lists and more. This ends up being really useful for building application UIs because you spend less time undoing user-agent styles, but when you really are just trying to style some content that came from a rich-text editor in a CMS or a markdown file, it can be surprising and unintuitive.

We get lots of complaints about it actually, with people regularly asking us things like:

Why is Tailwind removing the default styles on my h1 elements? How do I disable this? What do you mean I lose all the other base styles too?

@adamelliotfields
adamelliotfields / alert_blockquotes.md
Last active August 31, 2023 19:37
New GitHub Markdown Alert Blockquotes

These are so sweet. I didn't see an announcement or blog post; first noticed them in vitest-axe. Here's the community discussion on them.

> [!NOTE]  
> Highlights information that users should take into account, even when skimming.

Note

Highlights information that users should take into account, even when skimming.

@adamelliotfields
adamelliotfields / favicon.sh
Last active April 5, 2024 17:58
Favicon and Webmanifest Script
#!/usr/bin/env bash
set -euo pipefail
# Generates favicons and a webmanifest from a single image
# https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs
#
# Usage:
# favicon.sh <file> [dir] [flags]
#
# Args:
@adamelliotfields
adamelliotfields / github_projects_emoji.md
Created August 6, 2023 15:10
GitHub Projects Emoji Categorization

GitHub Projects uses emoji for status, priority, and sizing which I happen to think is very refreshing 🍹

Statuses

  • 🆕: New (:new:)
  • 📋: Backlog (:clipboard:)
  • 🔖: Ready (:bookmark:)
  • 🏗️: In progress (:building_construction:)
  • 👀: In review (:eyes:)
  • ✅: Done (:white_check_mark:)
@adamelliotfields
adamelliotfields / show_minimap_setting.py
Created August 5, 2023 19:32
Sublime Text 4 Show/Hide Minimap Setting
import sublime
import sublime_plugin
"""
Put this in your user packages:
```
mv ~/Downloads/show_minimap_setting.py ~/Library/Application\ Support/Sublime\ Text/Packages/User
```
Then add the setting to Preferences.sublime-settings: