Skip to content

Instantly share code, notes, and snippets.

grrowl / tryParseJson.ts
Last active July 20, 2023 04:32
JSON.parse with self-healing (for LLM output)
import { jsonrepair } from "jsonrepair";
export function tryParseJson<T>(json: string): T | undefined {
try {
return JSON.parse(jsonrepair(json));
} catch (error) {
// throw new Error(`Failed to parse JSON ${error}`);
return undefined;
title: "Hibernate When Network Idle"
date: 2020-04-14T20:57:40+10:00
draft: true
- linux
i have a pc at home which is often on, but not so often used. i'd like it to hibernate most of the time, unless i want to use it or it is doing something itself. it's possible, stringing together a few things:
function lazy_nvm {
unset -f nvm
unset -f npm
unset -f node
unset -f npx
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/" # linux
grrowl /
Created October 22, 2019 00:51
Updated version of - + Forwards a list of known ports from localhost to a host
if [[ $# -lt 2 ]]
echo "Usage: port-forward HOST REMOTE_PORT [LOCAL_PORT]";
grrowl /
Created January 11, 2019 22:51
Show AC wattage and battery drain (for bitbar)
# <bitbar.title>ac-wattage</bitbar.title>
# <bitbar.version>1.0</bitbar.version>
# <>Tom McKenzie</>
# <>grrowl</>
# <bitbar.desc>Shows the currently AC Charger wattage, if any.</bitbar.desc>
# Get SPPowerDataType
powerdata=$(system_profiler SPPowerDataType)
connected=$(echo "$powerdata" | grep 'Connected:' | awk 'END{print $2}')
tell application "Finder"
-- get desktop dimensions (dw = desktop width; dh = desktop height)
set db to bounds of window of desktop
set {dw, dh} to {item 3 of db, item 4 of db}
end tell
tell application "System Events"
repeat with proc in application processes
tell proc
repeat with win in windows
grrowl / apache-plex-reverse-proxy.vhost
Created January 8, 2018 12:48 — forked from hazcod/apache-plex-reverse-proxy.vhost
Apache2 reverse proxy vhost configuration for Plex. Rerquires modules ssl, proxy, wstunnel
ServerSignature Off
ServerTokens Prod
<VirtualHost *:80>
# This VirtualHost redirects everything to HTTPS on port 443.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  • when should this compacter run?
    • every n actions added (compactEvery)
    • when history is at n length (highWaterMark, compactAtLength)
  • can the function signal when it should?
    • run the compacter every time
    • needs a private state (below) or
    • getCompacter({ n, highwater }) => compactingDispatcher()

we can compactingReducer, basically searches the last 50 actions for "stop" or

grrowl /
Last active November 20, 2016 08:27 — forked from christophermanning/
Voronoi Diagram with Force Directed Nodes and Delaunay Links

Created by Christopher Manning


Nodes are linked to nodes in neighboring cells. The cell's color is a function of its area.

The white lines are the Delaunay triangulation and the purple cells are the Voronoi diagram.


grrowl / Signature.js
Created November 19, 2016 02:35
React component to provide ed25519 key generation, signing and verification
import React, { Component, PropTypes } from 'react'
import elliptic, { eddsa as EdDSA } from 'elliptic'
function toHex(arr) {
return elliptic.utils.toHex(arr).toUpperCase()
function fromHex(hex) {
return elliptic.utils.toArray(hex, 'hex')