Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
🧱
make, break, patch, repeat ad infinitum

Nicholas Berlette nberlette

🧱
make, break, patch, repeat ad infinitum
View GitHub Profile
@nberlette
nberlette / HTMLRewriter.js
Last active June 29, 2021 02:10
Cheerio + HTMLRewriter for Cloudflare Workers
/**
* Cheerio Wrapper for HTMLRewriter on Cloudflare Workers®
*
* Usage of cheerio here only simulates stream-oriented parser! It is slow!
*/
import cheerio from 'cheerio'
function replace(content, options) {
this[0].nodeValue = content
}
@nberlette
nberlette / require-json.mjs
Created June 28, 2021 11:12
2 lines of code to require() JSON in ES modules.
#!/usr/bin/env node
import { createRequire } from "module"
const require = createRequire(import.meta.url)
const data = require("./data.json")
@nberlette
nberlette / str.scss
Last active January 10, 2024 22:42
SASS string functions for kebabCase, camelCase, titleCase, etc.
/* * * * * * * * * * * * * * * * * * * * * * * * *
SASS string functions:
camelCase, kebabCase, titleCase, toLower, etc.
-------------------------------------------------
2021 Nicholas Berlette - https://git.io/Js3HD
* * * * * * * * * * * * * * * * * * * * * * * * */
@use "sass:string";
/*
upperCase($string)
@nberlette
nberlette / DBC_Specification.md
Last active May 26, 2021 07:22
DBC Specification for automotive/industrial CAN networks. Lifted from CANpy repo.

DBC Specification

Format description

<...> Required field
<A|B> A or B required
[...] Optional field
[A|B] A or B optional
## Purge macOS Time Machine's Local Snapshots
## By Nicholas Berlette <github.com/nberlette>
## Usage:
## purge_local_snapshots [-q|--quiet]
function purge_local_snapshots() {
quiet=$(echo ${1,,} | grep "\-q")
snapshots=$(tmutil listlocalsnapshotdates | grep "-")
@nberlette
nberlette / bmw-e90.dbc
Last active April 16, 2025 20:20
BMW E90 CAN bus definitions
VERSION "BMW_E90_0.0.8"
NS_ :
NS_DESC_
CM_
BA_DEF_
BA_
VAL_
CAT_DEF_
CAT_
@TheSherlockHomie
TheSherlockHomie / RenewExpiredGPGkey.md
Created January 3, 2021 16:36
Updating expired GPG keys and backing them up 🔑🔐💻

Updating expired GPG keys and their backup 🔑🔐💻

I use a GPG key to sign my git commits.

An error like this one might be a sign of an expired GPG key.

error: gpg failed to sign the data fatal: failed to write commit object
@peltho
peltho / svelte.md
Last active January 20, 2025 08:08
Svelte cheatsheet
/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;
@dikiaap
dikiaap / git-io-custom-url.md
Last active December 5, 2024 06:42
git.io custom URL

Update: As of 11 January 2022, git.io no longer accepts new URLs.

Command:

curl https://git.io/ -i -F "url=https://github.com/YOUR_GITHUB_URL" -F "code=YOUR_CUSTOM_NAME"

URLs that can be created is from:

  • https://github.com/*
  • https://*.github.com