Skip to content

Instantly share code, notes, and snippets.

View arctic-hen7's full-sized avatar

Sam Brew arctic-hen7

View GitHub Profile
@arctic-hen7
arctic-hen7 / org_timestamp.py
Created August 7, 2023 11:15
Some simple code that parses Org mode timestamps in Python. No support for ranges yet, but works nicely with repeats from my testing.
import re
from datetime import datetime, timedelta, date
class Timestamp:
"""
A representation of a timestamp parsed from Org mode.
"""
def __init__(self, timestamp_str):
self.timestamp_str = timestamp_str
self.start_date = None
@arctic-hen7
arctic-hen7 / whisper_transcribe.py
Created July 17, 2023 01:12
A Python script that records audio from the microphone into a temporary file until the user presses Enter, and that then transcribes that audio using Whisper. A plug-and-play way of adding voice non-real-time voice command to Python apps!
import whisper
import pyaudio
import wave
import sys
import tempfile
from ctypes import *
# Load the Whisper model once
model = whisper.load_model("base.en")
@arctic-hen7
arctic-hen7 / pvpn-server-loads.js
Created April 11, 2022 07:40
A simple JS script to extract server loads from ProtonVPN's website. This is designed to be run a DevTools console.
// RUN THIS AT <https://protonvpn.com/vpn-servers/>
SELECTOR = "#collapseNLfree > div:nth-child(1) > ul:nth-child(1) > .list-group-item"; // Change this to change the servers listed, this defaults to the Netherlands free servers
// As Proton change their website design, this will likely need to be changed
freeServers = document.querySelectorAll(SELECTOR);
loads = Array.from(freeServers).map(elem => {
const [name, load] = elem.innerText.split("Load ");
return name.trim() + ": " + load.trim();
// All our changes occur here
#[component(App<G>)]
fn app() -> Template<G> {
let root_ref = NodeRef::new();
template! {
// The router will use `root_ref`, so it needs to be `move` to avoid lifetime errors
Router(RouterProps::new(HistoryIntegration::new(), /* NEW START */ move /* NEW END */ |route: StateHandle<Routes>| {
// Template interpolation is the problem, so we get rid of it
// let template = Signal::new(Template::empty()); // OLD
@arctic-hen7
arctic-hen7 / index.hbs
Created September 19, 2021 21:11
Temporary fix for mdBook #1331
{{!-- This is copied from the upstream mdBook repository to fix #1331--}}
<!DOCTYPE HTML>
<html lang="{{ language }}" class="sidebar-visible no-js {{ default_theme }}">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>{{ title }}</title>
{{#if is_print }}
@arctic-hen7
arctic-hen7 / extraction.rs
Created September 1, 2021 10:05
Temporary fix for `include_dir` #59
// This file contains a temporary fix for the issues with recursive extraction in `include_dir`
// Tracking issue is https://github.com/Michael-F-Bryan/include_dir/issues/59
use std::path::Path;
use include_dir::Dir;
use std::io::Write;
/// Extracts a directory included with `include_dir!` until issue #59 is fixed on that module (recursive extraction support).
pub fn extract_dir<S: AsRef<Path>>(dir: Dir, path: S) -> std::io::Result<()> {
let path = path.as_ref();
@arctic-hen7
arctic-hen7 / getcontainerid.sh
Last active April 15, 2021 23:41
Script to get the ID of a Docker container by its name
#!/bin/bash
containername=$1
# Feed the list of currently running containers into an Awk script that declares the container name a variable and then gets the outputs of running it as a regex pattern, printing the first word
id=$(docker ps | awk -v containername="$containername" '$0 ~ containername{print $1}');
# Check if there is an image ID or not
if [[ -z $id ]]; then
echo "No images match that pattern. Try broadening your search, you can enter regex patterns to this command to if you'd like, but be aware of Awk syntax.";
else
echo "$id";
@arctic-hen7
arctic-hen7 / Dockerfile
Last active September 22, 2022 23:48
Starter Dockerfile with ZSH (Alpine)
# Setup Stage - set up the ZSH environment for optimal developer experience
FROM alpine:latest AS setup
# Let scripts know we're running in Docker (useful for containerised development)
ENV RUNNING_IN_DOCKER true
# Use the unprivileged `main` user (created without a password ith `-D`) for safety
RUN adduser -D main
RUN mkdir -p /app \
&& chown -R main:main /app
# Set up ZSH and our preferred terminal environment for containers
RUN apk --no-cache add zsh curl git
@arctic-hen7
arctic-hen7 / Dockerfile
Last active February 4, 2024 20:36
Starter Dockerfile with ZSH (NodeJS)
# Setup Stage - set up the ZSH environment for optimal developer experience
FROM node:14-alpine AS setup
# Let scripts know we're running in Docker (useful for containerised development)
ENV RUNNING_IN_DOCKER true
# Use the unprivileged `node` user (pre-created by the Node image) for safety (and because it has permission to install modules)
RUN mkdir -p /app \
&& chown -R node:node /app
# Set up ZSH and our preferred terminal environment for containers
RUN apk --no-cache add zsh curl git
RUN mkdir -p /home/node/.antigen
@arctic-hen7
arctic-hen7 / .dockershell.sh
Last active March 28, 2024 00:30
ZSH configuration for nice Docker shells in Alpine
# Note: for this to do anything, use my starter Dockerfile config (https://gist.github.com/arctic-hen7/10987790b86360820e2790650e289f0b)
# This file contains ZSH configuration for your shell when you interact with a container
# (we wouldn't want any boring `sh` now would we?)
# Please feel free to set up your own ZSH config in here!
# It gets mapped to your `.zshrc` for the root user in the container
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.