Skip to content

Instantly share code, notes, and snippets.

View EvanBalster's full-sized avatar

Evan Balster EvanBalster

View GitHub Profile
@EvanBalster
EvanBalster / forgejo-user.md
Created February 28, 2024 10:25
Steps for installing forgejo without root access (eg, on Dreamhost VPS)

Setting up Forgejo without root access / running under a single user. I devised these steps to deploy Forgejo on a Dreamhost VPS which only provided an SSH user.

  • Create user folders and install forgejo to use these rather than system paths.
    • Download forgejo to ~/bin/forgejo. Make sure ~/bin is in your path (for example by editing your .bashrc file)
    • Download the forgejo.service script to ~/.config/systemd/user.
    • Create the following folders:
      • ~/var/lib/forgejo
      • ~/etc/forgejo
  • Edit the forgejo.service script to run under the current user.
    • Delete the lines assigning User and Group.
@EvanBalster
EvanBalster / CircuitPlayground_TeaTimer.cpp
Last active July 10, 2023 22:16
Tea timer for circuit playground. RB cycles steeps & green/black, LB starts timer. When idle, lights auto-dim.
#include <Adafruit_CircuitPlayground.h>
const long FrameDT = 16;
unsigned long frame_index = 0;
unsigned long frame_mark = 0;
struct Timer
@EvanBalster
EvanBalster / async_ring.hpp
Last active March 7, 2022 22:04
C++98 lockfree ringbuffer without <atomic> (reliable under MSVC, no issues observed on ARM)
#ifndef PLAID_ASYNC_RING_H
#define PLAID_ASYNC_RING_H
#include <algorithm>
namespace plaid
{
/*
This class houses general-purpose logic for managing asynchronous ringbuffers.
*/
@EvanBalster
EvanBalster / visitor_guard.hpp
Last active March 6, 2022 23:28
A tiny non-blocking reference counter for recyclable objects.
#include <atomic> // Requires C++11 or a suitable polyfill
/*
A reference counting guard for reusable objects.
Works similar to the mechanisms of weak_ptr.
Any number of accessors may visit() the passage if not closed.
After successful entry they should call exit().
*/
struct visitor_guard
@EvanBalster
EvanBalster / weak_anchor.hpp
Last active June 9, 2021 00:01
Facilitate weak_ptr to non-heap objects (for AIO / observer patterns)
#pragma once
#include <memory>
#include <thread>
#include <atomic>
/*
weak_anchor is used to produce weak_ptr to a non-heap object.
@EvanBalster
EvanBalster / dream_many.bat
Created May 30, 2021 20:59
Interactive script to run big-sleep many times on the same training phrase
@echo off
setlocal EnableDelayedExpansion
cd %~dp0
echo
set /p FOLDER=Name directory:
echo ... Multiple training phrases or penalized phrases may be separated with vertical bar characters...
echo ... Penalized phrases will be avoided in image generation.
@EvanBalster
EvanBalster / pk_notarize_app.sh
Created April 29, 2020 19:05
Mac OS X notarization script
#!/bin/sh -u
ASC_PROVIDER="$1"
ASC_USERNAME="$2"
ASC_PASSWORD="$3"
BUNDLE_ID="$4"
BUNDLE_PKG="$5"
@EvanBalster
EvanBalster / rb_generated_fast_roots.h
Created December 14, 2019 07:59
Procedurally generated fast approximated root functions
#pragma once
// Functions optimized for worst-case error, accept any finite positive y
/*
approximate x^0.5 with 1 newtonian steps, x=[1,4]
RMS error: 0.000228909
mean error: 0.00017966
worst error: 0.000601098
@EvanBalster
EvanBalster / google_compute_reviver.sh
Last active April 16, 2023 19:09
WIP: A Google Cloud startup-script to automatically revive preemptible compute instances.
#!/bin/bash
#
# GCloud startup script to auto-restart any instances with 'revive' tag.
# The calling machine must have Read/Write access to compute API!!
# I use this to reboot preemptible instances.
# Output is logged to /tmp/revive.log
indent() { sed 's/^/ /'; }
revive_instances() {
@EvanBalster
EvanBalster / NumberStringSane.js
Created January 14, 2018 18:39
Reasonable JavaScript Number-to-String
/*
Convert a number to a string, rounding off apparent floating-point error.
Developed by Evan Balster for the TiddlyWikiFormula plugin.
Rules:
- Don't change the integer part.
- Don't change the first significant digit.
- Preserve the exponential part.
- Upon encountering five or more fractional 0s, round them off.
- Upon encountering five or more fractional 9s, round them up.