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 / module.py
Created August 31, 2024 17:26
Import a Python module from a Hugging Face repo
# https://hf.co/spaces/briaai/BRIA-2.3-T5/blob/main/app.py
import sys
from huggingface_hub import snapshot_download
repo_path = snapshot_download(repo_id="org/repo")
sys.path.append(repo_path)
from my_module import my_function # my_module.py
from my_other_module import my_other_function # my_other_module.py
@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 / secrets.md
Last active July 22, 2024 19:18
Setting Secrets Privately with `read`

Setting Secrets Privately with read

Instead of entering export GH_TOKEN=your_token, you can use read to set the variable without exposing it in your history:

read -s GH_TOKEN && export GH_TOKEN
@adamelliotfields
adamelliotfields / cell.md
Created July 19, 2024 21:56
JupyterLab Cell Toolbar Items

JupyterLab Cell Toolbar Items

To add an item to the cell toolbar, go to Settings > Settings Editor > Cell Toolbar. Each item gets a name, command, and icon.

Run Cell

  • Unique name: run-cell
  • Command id: notebook:run-cell
  • Item icon id: ui-components:run
@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 October 18, 2024 07:20
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 / deno.ts
Last active December 31, 2023 18:08
Deno by Example All-in-One for Prompting
/**
* @title Benchmarking
* @difficulty beginner
* @tags cli
* @run deno bench <url>
* @resource {https://deno.land/[email protected]/tools/benchmarker} Manual: Benchmarker tool
* @resource {/http-requests} Example: HTTP Requests
*
* When writing libraries, a very common task that needs to be done is
* testing the speed of methods, usually against other libraries. Deno