Skip to content

Instantly share code, notes, and snippets.

Modifiers

Description Code
Reset \x1b[0m
Bright \x1b[1m
Dim \x1b[2m
Underscore \x1b[4m
Blink \x1b[5m
Reverse \x1b[7m
@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
@jrc03c
jrc03c / rsync-alt-port.sh
Created June 1, 2022 12:47
Use `rsync` with alternate port
# from: https://stackoverflow.com/a/4630407
rsync -rvz -e "ssh -p <PORT>" --progress /source/path user@host:/target/path
@jrc03c
jrc03c / keybase.md
Created June 10, 2022 13:46
keybase.md

Keybase proof

I hereby claim:

  • I am jrc03c on github.
  • I am jrc03c (https://keybase.io/jrc03c) on keybase.
  • I have a public key whose fingerprint is 1033 6973 7373 5FD5 7AE9 5114 ED23 C1F4 B19A C886

To claim this, I am signing this object:

@jrc03c
jrc03c / __dirname.js
Last active September 2, 2022 15:34
Create `__dirname` variable when using `import` statements in Node
const __dirname = path.resolve(
import.meta.url.replace("file://", "").split("/").slice(0, -1).join("/")
)
@jrc03c
jrc03c / vite.config.js
Created September 2, 2022 15:39
Create a module resolution alias in (e.g.) Vite
// Note that this uses the __dirname definition from here:
// https://gist.github.com/jrc03c/6fbccd5af3a4d1b61f12e1e620e1c01b
import { defineConfig } from "vite"
import path from "path"
const __dirname = path.resolve(
import.meta.url.replace("file://", "").split("/").slice(0, -1).join("/")
)
@jrc03c
jrc03c / server.js
Created January 7, 2023 16:43
Basic HTTP / HTTPS server in Node w/ Express
const express = require("express")
const fs = require("fs")
const http = require("http")
const https = require("https")
// create a basic HTTP app that just redirects requests from HTTP to HTTPS
const httpApp = express()
httpApp.use((request, response) => {
return response.redirect("https://" + request.hostname + request.url)
@jrc03c
jrc03c / build.js
Last active June 13, 2023 17:21
generic build script
const process = require("process")
const watch = require("@jrc03c/watch")
function rebuild() {
console.log("-----")
console.log(`Rebuilding... (${new Date().toLocaleString()})`)
try {
// do stuff...
console.log("Done! 🎉")
@jrc03c
jrc03c / point-is-in-triangle.js
Last active January 23, 2023 16:36
check to see if a point lies inside a triangle
const ABOVE = "above"
const BELOW = "below"
const EXACTLY_ON = "exactly_on"
function getPointRelationToLine(point, pair) {
const [p1, p2] = pair
// if the pair have the same x-values, then they either lie on a
// vertical line or are identical
if (p2[0] - p1[0] === 0) {
@jrc03c
jrc03c / deep-sort.js
Last active May 29, 2023 01:07
Recursively / deeply sort an object or array in JS
function deepSort(x, fn) {
fn = fn || ((a, b) => (a < b ? -1 : 1))
if (typeof x === "object") {
if (x === null) return x
if (x instanceof Array) {
return x.map(v => deepSort(v, fn)).sort(fn)
}