Skip to content

Instantly share code, notes, and snippets.

View shanewholloway's full-sized avatar
🗜️
I may be slow to respond.

Shane Holloway shanewholloway

🗜️
I may be slow to respond.
View GitHub Profile
@shanewholloway
shanewholloway / searchFragment.js
Created February 2, 2023 14:30
Search a page using text-fragment in the URL hash.
// See https://web.dev/text-fragments/
// location.hash = searchFragment('text to find in page')
export const searchFragment = txt => `#:~:text=${encodeURI(txt)}`
@shanewholloway
shanewholloway / box.css
Created June 15, 2022 19:06
aspect-ratio center box CSS
/* from Kevin Powell's [3 useful CSS tricks](https://www.youtube.com/watch?v=HOM47v73yG8)
* for <div class=box></div>
* useful for iframes, videos, pictures, etc.
*/
.box {
width: 25rem;
aspect-ratio: 1 / 1;
position: fixed;
inset: 0rem; /* sets top/bottom/left/right to same value */
@shanewholloway
shanewholloway / iter_subnet_matches.js
Created May 5, 2022 04:57
NodeJS snippet for iterating the `networkInterfaces()` in the same subnet as `ip_query`
import {networkInterfaces} from 'os'
import {isIP, BlockList} from 'net'
export function * iter_subnet_matches(ip_query) {
let family = isIP(ip_query)
let ipv = 'ipv'+family
for (let [if_name, if_addrs] of Object.entries(networkInterfaces())) {
for (let each of if_addrs) {
if (family != each.family)
@shanewholloway
shanewholloway / blobAsDataURL.js
Last active November 17, 2021 15:56
async blobAsDataURL using FileReader
async function blobAsDataURL(blob) {
let rdr = new FileReader()
await new Promise((onload, onerror) => {
rdr.onload = onload
rdr.onerror = onerror
rdr.readAsDataURL(blob) })
return rdr.result
}
@shanewholloway
shanewholloway / dom-document-tricks.mjs
Created October 13, 2021 17:12
DOM parsing and serializing
export function parse_html(raw_html_string) {
return new DOMParser()
.parseFromString(raw_html_string, 'text/html') }
export function dom_to_html_blob(dom) {
let html_doc = new XMLSerializer()
.serializeToString(dom)
return new Blob([html_doc], {type: 'text/html'}) }
export function dom_to_html_blob_url(dom) {
class CBORDecoderBase {
// Possible monkeypatch apis responsibilities:
// decode() ::
// *iter_decode() ::
// async decode_stream() ::
// async * aiter_decode_stream() ::
static options(options) {
return (class extends this {})
.compile(options)}
@shanewholloway
shanewholloway / README.md
Last active October 24, 2023 13:05
SHTC3 and RaspberryPI over Qwiic
@shanewholloway
shanewholloway / fun_class_attrs_iffe.js
Created October 31, 2020 18:38
Fun with class attrs and immediately invoked function expressions
class Awesome {
fn = ns => (console.log('instance function', this), this)
static s_fn = ns => (console.log('static function', this), this)
val = (ns => (console.log('instance iife', this), this))()
static s_val = (ns => (console.log('static iife', this), this))()
}
console.log('Awesome.s_val', Awesome.s_val === Awesome, Awesome.s_val)
// true
@shanewholloway
shanewholloway / worker_from_blob.js
Created May 20, 2020 23:02
Worker from Blob URL -- works in Browser; how about Deno?
const worker_src = `
console.log("Worker from a Blob URL:", typeof self)
`
const blob_worker = new Blob([worker_src], {type: 'application/javascript'})
const bloburl_worker = URL.createObjectURL(blob_worker)
console.log({bloburl_worker})
const wkr = new Worker(bloburl_worker, {type: 'module'})
@shanewholloway
shanewholloway / export-yubi-to-ssh-key.sh
Created December 4, 2019 00:07
Export a Yubikey certificate to an ssh-keygen compatible key.
#!/bin/sh
# Seems to only support RSA keys...
ykman piv export-certificate 9a public-cert.pem
openssl x509 -in public-cert.pem -noout -pubkey > public-key.pem
ssh-keygen -i -m pkcs8 -f ./public-key.pem > id_yubi_9a.pub