Skip to content

Instantly share code, notes, and snippets.

@jrc03c
jrc03c / working-with-luks.sh
Created May 10, 2022 17:14
working with LUKS
# assuming a partition already exists, apply LUKS formatting to it
sudo cryptsetup luksFormat /dev/whatever
# open it
sudo cryptsetup luksOpen /dev/whatever mapping_name
# format it to ext4 (or whatever)
sudo mkfs.ext4 /dev/mapper/mapping_name
# mount it

Modifiers

Description Code
Reset \x1b[0m
Bright \x1b[1m
Dim \x1b[2m
Underscore \x1b[4m
Blink \x1b[5m
Reverse \x1b[7m
@jrc03c
jrc03c / get-scrollbar-width.js
Created July 31, 2021 21:03
Get the width of a browser scrollbar
// from: https://davidwalsh.name/detect-scrollbar-width
function getScrollbarWidth() {
const div = document.createElement("div")
div.style = `
width: 100px;
height: 100px;
overflow: scroll;
position: absolute;
@jrc03c
jrc03c / copy-text.js
Last active April 19, 2023 20:00
Copy arbitrary text to the clipboard in the browser
// 🚨 🚨 🚨
// NOTE: According to MDN, `document.execCommand()` is deprecated. See:
// https://developer.mozilla.org/en-US/docs/Web/API/document/execCommand
// Instead, use the Clipboard API:
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
// 🚨 🚨 🚨
function copy(text) {
const input = document.createElement("input")
input.type = "text"
@jrc03c
jrc03c / high-dpi-canvas.js
Last active March 7, 2021 23:51
Create a high-DPI-compatible canvas element
function createHighDPICanvas(width, height){
let dpi = window.devicePixelRatio || 1
let canvas = document.createElement("canvas")
canvas.width = width * dpi
canvas.height = height * dpi
canvas.style.width = width + "px"
canvas.style.height = height + "px"
canvas.getContext("2d").scale(dpi, dpi)
return canvas
}
@jrc03c
jrc03c / download-text.js
Last active September 30, 2024 11:13
Download text as a file
function downloadText(filename, text){
const a = document.createElement("a")
a.href = "data:text/plain;charset=utf-8," + encodeURIComponent(text)
a.download = filename
a.dispatchEvent(new MouseEvent("click"))
}
@jrc03c
jrc03c / download-canvas-as-image.js
Created February 13, 2020 15:10
Download the contents of an HTML5 canvas as an image
function downloadCanvasAsImage(canvas, filename){
let a = document.createElement("a")
a.href = canvas.toDataURL()
a.download = filename
a.dispatchEvent(new MouseEvent("click"))
}
@jrc03c
jrc03c / git.txt
Last active April 19, 2023 20:05
Git Cheat Sheet
##################
Basic Git Commands
##################
git init = turns the current working directory into a repository
git clone = downloads a remote repository to your machine
Syntax: git clone <source> <destination>
Example: git clone https://github.com/willfind/uplift-website /home/josh/projects/uplift.app
@jrc03c
jrc03c / spiro2.js
Last active February 27, 2017 00:48
More spirographs.
var n = 7;
var angles, speeds, lengths;
function setup(){
createCanvas(window.innerWidth, window.innerWidth);
background(255);
fill(0, 20);
frameRate(9999);
angles = [];
@jrc03c
jrc03c / spiro.js
Created February 26, 2017 16:00
A Spirograph
var n = 4;
var angles;
var speeds;
var lengths;
function setup(){
createCanvas(window.innerWidth, window.innerHeight);
stroke(0, 10);
fill(0);
frameRate(99999999999);