Skip to content

Instantly share code, notes, and snippets.

@gma
gma / vscode-auto-format-astro-on-save.md
Last active April 26, 2022 11:08
Configuring VS Code to format Astro files with Prettier

Configuring VS Code to format Astro files with Prettier

There's an Astro extension for VS Code that provides syntax highlighting, completion and emmet support, but as of April 2022 it doesn't support auto-formatting.

There's a prettier plugin for Astro. We can install that and then configure VS Code to run Prettier when we save a file.

Installing prettier

Let's start by installing prettier and the Astro plugin into our project:

npm install -D prettier prettier-plugin-astro
@gma
gma / pacman.py
Created September 16, 2021 18:33
Python NW group coding session
# Pac-man orientation: v < > ∧
# . . .
# .V.
# . . .
grid = [
[1, 1, 1, 1, 1],
@gma
gma / tm.sh
Last active September 12, 2021 21:07
tm script for launching tmux via fzf
#!/bin/sh
TM_ROOT="${TM_ROOT:-$HOME/Projects}"
TM_DEPTH=${TM_DEPTH:-4}
TM_PROJECT_CONTAINS="${TM_PROJECT_CONTAINS:-.git}"
TM_CRITERIA="${TM_CRITERIA:--type d -name $TM_PROJECT_CONTAINS}"
TM_FILTER="${TM_FILTER:-cat}"
TM_EDITOR="${TM_EDITOR:-vi -c 'set number relativenumber'}"
## Functions
@gma
gma / cheat.sh
Created September 8, 2021 22:18
Script that hits cht.sh with query, results in a new tmux window
#!/bin/bash
## Functions
usage()
{
echo "Usage: $(basename $0) <arg> [args...]" 1>&2
exit 1
}
#!/bin/bash
GIGABYTES="${1:-1}"
ITERATIONS="${2:-1}"
MOUNT="/mnt/tank"
sshhh() {
grep -v "+0 records"
}
@gma
gma / build-kernel.sh
Created April 30, 2020 20:30
Work in progress to build patched Pop kernel
#!/bin/sh
set -e
apt-get source linux
pushd linux-*
# modify debian.master/changelog at this point
patch -p1 < <(curl URL of patch)
fakeroot debian/rules clean
fakeroot debian/rules binary-headers binary-generic binary-perarch skipmodule=true skipabi=true skipretpoline=true
popd
@gma
gma / x230-screen-and-aspm.patch
Last active December 7, 2021 05:02
Linux kernel patch for ThinkPad X230 with FHD (1080p) screen mod
diff -aur linux-5.13.0/drivers/acpi/pci_root.c linux-5.13.0-x230/drivers/acpi/pci_root.c
--- linux-5.13.0/drivers/acpi/pci_root.c 2021-09-14 20:19:11.000000000 +0100
+++ linux-5.13.0-x230/drivers/acpi/pci_root.c 2021-09-18 10:33:18.099360328 +0100
@@ -508,7 +508,6 @@
* flag here, to defer the action until after the ACPI
* root scan.
*/
- *no_aspm = 1;
}
}
@gma
gma / route.js
Created December 2, 2019 16:53
Stubbing XHR in Cypress
import axios from 'axios';
describe('Cypress', function() {
it('stubs a GET request', function() {
cy.server();
const endpoint = 'http://my-api-host/path';
cy.route('GET', endpoint, {
attr: [{ thing: 1234 }]
@gma
gma / mkvenv.sh
Created October 19, 2019 12:20
function for making Python 3 virtual env
mkvenv()
{
local prompt="${1:-$(basename $(pwd))}"
shift
command -v deactivate >/dev/null && deactivate
[ -d .venv ] && echo "ERROR: .venv exists" 1>&2 && return 1
python3 -m venv .venv --prompt "\[\033[1;34m\]$prompt\[\033[0m\]" $*
activate
}
@gma
gma / stripe-fixtures-customer-ids.rb
Last active November 4, 2016 12:56
Creating fixtures for Stripe's JSON events
customer_events = %w(
charge.captured.json
charge.failed.json
charge.refunded.json
charge.succeeded.json
charge.updated.json
customer.card.created.json
customer.card.deleted.json
customer.card.updated.json
customer.created.json