Skip to content

Instantly share code, notes, and snippets.

View thinkjrs's full-sized avatar
🎯
Focusing

Jason R. Stevens, CFA thinkjrs

🎯
Focusing
View GitHub Profile
@thinkjrs
thinkjrs / 404Links.tsx
Created March 6, 2024 21:44
Next.js 404 Links
@thinkjrs
thinkjrs / 404.tsx
Created March 6, 2024 21:42
Next.js Custom 404
import React from 'react'
import { HomeLink404, DashboardLink404 } from '@/components/404Links'
export default function NotFound() {
return (
<>
<section className="bg-primary relative z-10 py-[120px]">
<div className="container mx-auto">
<div className="-mx-4 flex">
<div className="w-full px-4">
<div className="mx-auto max-w-[400px] text-center">
@thinkjrs
thinkjrs / uploadS3NextjsAppRouter.md
Last active December 27, 2023 15:55
Steps to create buckets and upload files using AWS S3 and the Next.js App Router
@thinkjrs
thinkjrs / dark-mode-image.html
Created December 12, 2023 16:17
How to add dark and light mode adjustments for an image in HTML
<!-- https://larsmagnus.co/blog/how-to-make-images-react-to-light-and-dark-mode -->
<picture>
<source
srcset="dark-image.png"
media="(prefers-color-scheme: dark)"
/>
<img
src="light-image.png"
alt="Browser with large and small images of a coffee cup and plants"
/>
@thinkjrs
thinkjrs / responseSize.ts
Created December 5, 2023 00:46
Get the response size in TypeScript of a request payload
// https://github.com/vercel/vercel/issues/3825#issuecomment-961295566
function formatBytes(bytes: number, decimals = 2) {
if (bytes === 0) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
@thinkjrs
thinkjrs / ssh-copy-id.md
Created March 4, 2023 20:20
Copy an SSH key to a server

Copy an SSH key to a server

Use the built-in ssh-copy-id command to copy keys to servers.

Note: make sure you have enabled password authentication on the server ssh server configuration, first!

ssh-copy-id -i ~/.ssh/mykey user@host
@thinkjrs
thinkjrs / remove-docker-volumes.md
Created February 28, 2023 23:50
Remove all docker volumes

Removing Docker Volumes

It's a common need to remove docker volumes (e.g. Gitlab runners that polute your system).

The command

Below is a quick 'n dirty command to get the job done.

sudo docker volume rm $(sudo docker volume ls -q)
@thinkjrs
thinkjrs / python-date-range.md
Last active February 19, 2023 01:32
Date range in Python

Date Range in Python

This covers how to get a date range in Python using only standard library modules.

The code

"""
MIT LICENSED
(c) 2023 Jason R. Stevens, CFA
"""
@thinkjrs
thinkjrs / README.md
Created November 30, 2022 02:14 — forked from tomi/README.md
Saving and reading private key to env variables using base64

Encoding the private key as base64

  • Copy the private key to clipboard
  • Run command pbpaste | base64 | pbcopy on mac or xclip -selection clipboard -o | base64 -w 0 | xclip -selection clipboard on 'nix systems
  • The private key is now base64 encoded in the clipboard. Paste it to env variable e.g. to heroku or to .env file

Decoding the private key from base64 in node.js

const private_key = new Buffer(process.env.PRIVATE_KEY, 'base64').toString('ascii');
@thinkjrs
thinkjrs / git-index-permissions.md
Created November 12, 2022 22:22
Change the permissions of a file in a Git index.

From Github's documentation, the below demonstrates how-to explicitly change the permission mode of a file so that it doesn’t get reset every time there is a clone/fork.

git update-index --chmod=+x <filename>

For example, to give entrypoint.sh executable permissions: