Skip to content

Instantly share code, notes, and snippets.

View adamelliotfields's full-sized avatar

Adam Fields adamelliotfields

View GitHub Profile
@adamelliotfields
adamelliotfields / msvc-windows-terminal.md
Last active January 24, 2026 15:53
MSVC (cl) in Windows Terminal

I wanted to build C programs on Windows 11 without WSL. I then wanted to be able to open a terminal tab with the MSVC compiler/linker (cl) environment set up.

Note

These instructions target x64; substitute the appropriate values for ARM.

Installation

Install Visual Studio Build Tools via Winget:

@adamelliotfields
adamelliotfields / bash-heredoc-variable-with-read.md
Last active January 24, 2026 15:53
Assign heredoc to variable in Bash

Instead of concatenation:

str=""
str+="This is a\n"
str+="multiline string"

You can use a heredoc:

@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 / relative-path-in-scripts.md
Last active January 24, 2026 15:54
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 / install-cuda-wsl2.md
Last active January 24, 2026 15:54
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 / cloudflare-tunnel-instructions.md
Last active January 24, 2026 15:55
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
brew install cloudflared
@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 / windows-ssh-no-password-with-keys-wsl2.md
Last active January 24, 2026 15:30
Windows SSH Server with Password-less Key Authentication and Default WSL2 Shell

I wanted to be able to SSH into my Windows laptop directly into Linux. I also wanted to disable password authentication and only allow public key (RSA in my case) authentication.

Scott Hanselman wrote a blog post on how to make your default WSL2 distro your default shell for SSH. Windows OS Hub published an article on using public key authentication. These were both helpful resources.

I'll assume you're already familiar with using SSH keys. If not, this article at DigitalOcean is very informative.

Add your public key to your authorized keys file

First thing you want to do is create the file $HOME\.ssh\authorized_keys. If you run into issues, it could be due to incorrect file ownership.

@adamelliotfields
adamelliotfields / index.scss
Created January 30, 2020 18:42
Bootstrap 4 Flex Grid
/*!
* Bootstrap Grid v4.4.1 (https://getbootstrap.com/)
* Copyright 2011-2019 The Bootstrap Authors
* Copyright 2011-2019 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
$grid-columns: 12 !default;
$grid-row-columns: 6 !default;
$grid-gutter-width: 30px !default;
@adamelliotfields
adamelliotfields / index.js
Last active August 11, 2023 16:17
Grafana Dashboard Screenshot using Puppeteer
#!/usr/bin/env node
/**
* Grafana Dashboard Screenshot
*
* Derived from https://github.com/sindresorhus/capture-website/blob/v0.8.0/index.js
* by @sindresorhus (MIT).
*/
const fs = require('fs');