Skip to content

Instantly share code, notes, and snippets.

@benfoxall
benfoxall / generate.sh
Last active Jan 19, 2022
Generate video of satellite imagery
View generate.sh
# Extract frames from GEOS Image Viewer to generate a video
# https://www.star.nesdis.noaa.gov/goes/fulldisk_band.php?sat=G16&band=GEOCOLOR&length=12&dim=1
mkdir -p images output
BASE=https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/GEOCOLOR/
DIM=1808x1808
curl $BASE \
| grep -o -e "\".*GEOCOLOR-$DIM.jpg\"" \
View favicon.js
const set = favicon()
set('🐝')
//
function favicon() {
const link = document.createElement('link')
link.rel = 'icon'
document.head.appendChild(link)
@benfoxall
benfoxall / emoji.js
Created May 17, 2021
Function for parsing emoji sequences
View emoji.js
//
// https://unicode.org/Public/emoji/13.0/emoji-sequences.txt
export function* emojiList(sequences) {
const LINES = /^[0-9A-F\.\ ]*;/mg;
const TRAILER = /\W+;$/;
const RANGE = /(.*)\.\.(.*)/;
for (const line of sequences.match(LINES)) {
@benfoxall
benfoxall / unicorn-draw.html
Created May 15, 2021
A page for drawing on the Pi Pico Unicorn Pack over WebUSB – https://twitter.com/benjaminbenben/status/1379361185703849987
View unicorn-draw.html
<html>
<head>
<title>
pico serial
</title>
<style>
body {
font-family: sans-serif;
display: flex;
View 🍅.py
## Hacky pomodoro script for pi pico
from math import floor
import picounicorn
from machine import Pin, Timer
picounicorn.init()
w = picounicorn.get_width()
@benfoxall
benfoxall / gifsize.js
Created Jan 16, 2021
Find the size of a gif by requesting only 4 bytes
View gifsize.js
await gifsize('https://media.giphy.com/media/3ornjZLITGcFQVRbxK/source.gif')
// > {width: 500, height: 247}
async function gifsize (url) {
const result = await fetch(url, {headers: {Range: 'bytes=6-9'}})
const [width, height] = new Uint16Array(await result.arrayBuffer())
return {width, height}
View vis.js
class AudioVis {
constructor() {
this.analyser =
this.data = new Uint8Array()
this.frequencies = new Uint8Array()
}
populateArrays() {
@benfoxall
benfoxall / script.js
Last active Feb 13, 2018
A script that runs in 5 places
View script.js
if(typeof document !== 'undefined') {
// normal script tag
console.log("Hello #1")
navigator.serviceWorker.register(
document.currentScript.src
)
} else {
// running as a service worker
@benfoxall
benfoxall / font-sw.js
Last active Sep 22, 2017
Other Service Workers
View font-sw.js
importScripts('https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js')
toolbox.router.get('/:path*', toolbox.cacheFirst, {
origin: /fonts\.(gstatic|googleapis)\.com/,
cache: {
name: 'fonts-v1',
maxEntries: 10
}
}
)
View one-liners.js
let delayed = new Promise(r => setTimeout(r, 500, 'hello'))
let element = Object.assign(
document.createElement('div'),
{textContent: 'hello'}
)
Object.assign(element.style, {
background: 'red'
})