Skip to content

Instantly share code, notes, and snippets.

@benfoxall
benfoxall / resetMacAddr.sh
Last active Aug 8, 2022
Reset MAC address (for rejoining time-limited wifi)
View resetMacAddr.sh
# turn off wifi
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
# set mac address to random value
NEW_MAC=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
sudo ifconfig en0 lladdr $NEW_MAC
View demo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<nav>
<ol>
@benfoxall
benfoxall / extract-functions.js
Last active Jan 29, 2022
Extract functions from js source code
View extract-functions.js
import { opendir, readFile } from 'fs/promises';
import { join } from 'path'
import * as parser from "@babel/parser";
import _traverse from "@babel/traverse";
const traverse = _traverse.default;
for await (const file of allFiles('javascript')) {
if (file.endsWith('.js')) {
const buffer = await readFile(file)
@benfoxall
benfoxall / generate.sh
Last active Mar 31, 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() {