Skip to content

Instantly share code, notes, and snippets.

@calvinf
calvinf / Dockerfile
Last active February 15, 2025 20:37
Bun + Node.js Dockerfile
# Dockerfile for Bun (package manager) and Node.js (for runtime Next.js)
# this image includes Bun 1.x, Node.js 22, on Alpine, with Git
FROM imbios/bun-node:1-22-alpine-git AS base
RUN apk update && apk upgrade && apk add --no-cache dumb-init
RUN addgroup --system --gid 1002 nodejs
RUN adduser --system --uid 1002 nextjs
# Install dependencies only when needed
FROM base AS builder
WORKDIR /app
@calvinf
calvinf / bun-completion.sh
Last active January 31, 2025 01:48
Bun autocomplete for bash
#!/usr/bin/env bash
_bun_complete() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Define the main commands
local commands="add build create exec init install link outdated patch pm publish remove repl run test unlink update upgrade x"
@calvinf
calvinf / useNavigationLock.ts
Created December 27, 2022 21:28
Next.js Page Navigation Lock
import { useEffect } from 'react';
import { useRouter } from 'next/router';
// helpful issues/posts when building this
// https://github.com/vercel/next.js/issues/2694#issuecomment-732990201
// https://github.com/vercel/next.js/issues/2476#issuecomment-850030407
// https://github.com/vercel/next.js/discussions/32231#discussioncomment-1766752
// https://github.com/vercel/next.js/issues/2476#issuecomment-843311387
/**
@calvinf
calvinf / github-docker-build-and-push.yml
Created January 8, 2022 17:57
Github Action for Docker Build and Push to Google Artifact Registry
name: CI
on:
push:
branches:
- main
pull_request:
env:
# Github Container registry
@calvinf
calvinf / .babelrc.js
Last active April 24, 2018 02:51
Example Babel 7 config (Preact server-side, JSX, works with Jest)
// Example Babel 7 config
// Server-Side Preact Rendering
// with esm (most of the time)
// but Babel handles modules in test
// so Jest works
// target node version for Babel transpilation
const NODE_TARGET = 9;
// default settings for preset-env
@calvinf
calvinf / Highlight-Code-In-Keynote.md
Created July 19, 2017 18:07
Highlighting Code in Keynote

How to highlight code in Keynote slides

Install Highlight

On Mac, if you have Homebrew installed, run:

> brew install highlight

Add to your shell config or .aliases file:

@calvinf
calvinf / add-classes.html
Created July 1, 2017 02:07
Add Classes (without using classList or jQuery)
<!doctype html>
<html>
<head>
<title>Add Classes (without using classList or jQuery)</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.4.2/mocha.css">
</head>
<body>
@calvinf
calvinf / multiply.html
Created June 24, 2017 15:46
Curried Multiply
<!doctype html>
<html>
<head>
<title>Multiply</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.4.2/mocha.css">
</head>
<body>
@calvinf
calvinf / vs-code-user-settings.json
Last active October 10, 2017 00:02
Visual Studio Code - User Settings
// Place your settings in this file to overwrite the default settings
{
"editor.acceptSuggestionOnEnter": "off",
"editor.minimap.enabled": true,
"eslint.options": {
"configFile": "eslintrc.js"
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"flow.pathToFlow": "/usr/local/bin/flow",
@calvinf
calvinf / install-apparix.sh
Last active September 13, 2016 21:33 — forked from glombard/install-apparix.sh
Setting up Apparix for directory bookmarks on Mac OS X
brew install -v apparix
# Installed to: /opt/foo/Cellar/apparix/11-0/bin/apparix
# Add bm/to Bash functions from man page to .bashrc or .local.bash:
man -P cat apparix | awk '/BASH-style functions/{p=1} /---/{if(p==1)p=2; else p=0; next} p>1{print}' >> ~/.bash_profile
# Reload my bash config:
source ~/.bash_profile
# Now create a bookmark: