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 / 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
@shanewholloway
shanewholloway / README.md
Last active October 24, 2023 13:05
SHTC3 and RaspberryPI over Qwiic
@shanewholloway
shanewholloway / icos_indexer.js
Created December 13, 2016 05:53
Navigating through Triangle Meshes Implemented as Linear Quadtrees
'use strict'
/*
* Adapted from: https://github.com/rpsirois/icosindexer
* Who aadapted it from: Lee, Michael and Samet, Hanan. (April 2000).
* Navigating through Triangle Meshes Implemented as Linear Quadtrees.
* ACM Transactions on Graphics, Vol. 19, No. 2.
* Retrieved from https://pdfs.semanticscholar.org/a5c8/8b53174405e5ff512ff5ffa8a56df3c8e2df.pdf
*
* Authors:
* - [Robert Sirois](https://github.com/rpsirois)
@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 / docker-stackfile.yml
Last active August 4, 2022 03:44
Example Docker Stack Deploy with Node/Service/Task values
## docker stack deploy -c docker-stackfile.yml gist_demo
version: "3.8"
services:
playground:
image: node:alpine
hostname: '{{.Task.Name}}'
environment:
SWARM_TASK: '{{.Task.Name}}'
SWARM_PEERS: "tasks.{{.Service.Name}}"
@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)}