Skip to content

Instantly share code, notes, and snippets.

@mofosyne
mofosyne / generate_markdown_toc.sh
Created April 25, 2024 14:08
Generate A Markdown TOC from a pdf via this bash function (Useful for Obsidian Note Taking)
# Usage: generate_markdown_toc "AS 3000-2018 Wiring Rules.pdf" 3
generate_markdown_toc() {
local pdf_file="$1"
local max_level="$2"
pdftk "$pdf_file" dump_data | awk -v max_level="$max_level" '/BookmarkTitle:/ {gsub("BookmarkTitle: ", ""); title=$0} /BookmarkPageNumber:/ {gsub("BookmarkPageNumber: ", ""); page=$0} /BookmarkLevel:/ {gsub("BookmarkLevel: ", ""); level=$0; if (level <= max_level) printf("%s- [ ] %s (Page %s)\n", sprintf("%" level*2 "s", ""), title, page)}'
}
@mofosyne
mofosyne / strtok_escaped.c
Last active April 22, 2024 11:37
alternative to strtok but with escaped character support for deliminating a string with a single char (e.g. csv or psv)
#include <stdio.h>
#include <string.h>
char *strtok_escaped(char *str, const char *delim) {
// Tokenise a string from a single char deliminator
// (strtok can deal with a deliminator string but for my purpose of splitting a psv table I only need one char)
// (There are better ways to optimise this, but just wanted something to work for now)
// https://gist.github.com/mofosyne/81c94740c0f33259606afa823562914c
static char *last_token_end = NULL;
@mofosyne
mofosyne / llamafilerepack.sh
Last active April 17, 2024 18:27
This script facilitates the repackaging and upgrading of llamafile archives generated by Llama.cpp
#!/bin/bash
# Llama.cpp Repackaging Script
# This script facilitates the repackaging and upgrading of llamafile archives generated by Llama.cpp.
# This is particularly useful for users with limited internet access, by preserving existing gguf and .arg settings while replacing the llamafile engine.
#
# Usage: llamafilerepack [-h] [-f] <old> <new>
# -h: Display usage information.
# -f: Skip Version Check.
# -v: Verbose Mode
# <old>: The name of the old llamafile archive to be upgraded.
@mofosyne
mofosyne / minimal-autotool-setup-script.sh
Created April 16, 2024 04:32
This is a helper script to generate a minimum gnu autotools C based repo
#!/bin/bash
# INITIALIZE MINIMAL AUTOTOOLS BASED C PROGRAM (Brian Khuu 2024)
# https://briankhuu.com/blog/2024/04/11/initialise-minimal-autotools-script/
set -euo pipefail
# Function to display usage
show_usage() {
echo "Usage: $0 [PACKAGE_NAME]"
@mofosyne
mofosyne / openAI_frontmatter_updator.py
Last active December 13, 2023 16:24
This script is to assist users in filling in summaries, tags, categories and other relevant fields this is especially helpful for blog posts as it makes it easier to search for posts later on.
#!/usr/bin/env python3
# LLM Based Frontmatter updator for Jekyll and MkDocs
# By Brian Khuu (2023)
# This script is to assist users in filling in summaries, tags, categories and other relevant fields
# this is especially helpful for blog posts as it makes it easier to search for posts later on.
# You would need an OPENAI_API_KEY to use this script so make sure to include it in your ~/.bashrc startup script
import os
import re
import sys
@mofosyne
mofosyne / DailyNotes.template
Last active September 15, 2023 06:04
my obsidian daily note template
---
creation date: <%tp.date.now()%>
date: <%tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD")%>
tags: <%tp.date.now("GGGG-[W]WW-E", 0, tp.file.title, "YYYY-MM-DD")%>, <%tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD")%>
alias: <%tp.date.now("dddd Do MMMM YYYY", 0, tp.file.title, "YYYY-MM-DD")%>
---
# <%tp.date.now("dddd Do MMMM YYYY", 0, tp.file.title, "YYYY-MM-DD")%> | <%tp.date.now("[Week] W", 0, tp.file.title, "YYYY-MM-DD")%>
- ISO_8601: <%tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD")%>
- ISO_week_date: <%tp.date.now("GGGG-[W]WW-E", 0, tp.file.title, "YYYY-MM-DD")%>
- [[Index#Quick reference]]
@mofosyne
mofosyne / install_android_studio.sh
Last active August 31, 2023 15:47
Install Android Studio From Website Onto Debian
#!/usr/bin/env bash
# Based on https://techviewleo.com/how-to-install-android-studio-on-debian/
## You may need to update the url from https://developer.android.com/studio
DOWNLOAD_LINK=https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2022.3.1.19/android-studio-2022.3.1.19-linux.tar.gz
ZIPNAME=android-studio-2022.3.1.19-linux.tar.gz
## Get latest jdk
sudo apt-get update
sudo apt-get install default-jdk
#!/usr/bin/env bash
# Automated application of WiFi Print Server: From a Raspberry Pi Zero W to Windows 10/11 By brighterfusion from instructables
# This helper script was written by Brian Khuu on 2023 for https://www.instructables.com/WiFi-Print-Server-From-a-Raspberry-Pi-Zero-W-to-Wi/
# To run this shell script on gist (ref: https://gist.github.com/mob-sakai/174a32b95572e7d8fdbf8e6f43a528f6)
# Run this script via curl:
# bash <(curl -sL https://gist.githubusercontent.com/mofosyne/6baab7509ccd93f74d3fa225ea57d75d/raw/rpi_print_server_setup.bash)
# Run this script via wget:
# bash <(wget -o /dev/null -nv -O - https://gist.githubusercontent.com/mofosyne/6baab7509ccd93f74d3fa225ea57d75d/raw/rpi_print_server_setup.bash)
@mofosyne
mofosyne / gitsubprocess.py
Last active November 15, 2022 10:41
dependency free subprocess parsing of git output in python
# gitsubprocess.py
# Dependency free subprocess parsing of git output in python
# Public Domain. Intended to be copy pasted into various internal build scripts as needed.
# Feel free to suggest changes https://gist.github.com/mofosyne/cdb18587ab6dd0457d63afe6219a320d
#
# By Brian Khuu 2022
#
# ## Staging and working file status type quick reference ##
# Reference: https://git-scm.com/docs/git-status#_short_format
# ' ' = unmodified
@mofosyne
mofosyne / palletColorParse.c
Last active January 8, 2022 15:49
Parse web color hexes for pallet (e.g. `0xFFAD63, ...`) (e.g. `#FFAD63, ...`)
#include <stdio.h>
#include <stdint.h>
int palletColorParse(uint32_t *palletColor, const int palletColorSize, const char * parameterStr)
{
// Parse web color hexes for pallet (e.g. `0xFFAD63, ...`) (e.g. `#FFAD63, ...`)
// This was created for the cdecoder in https://github.com/mofosyne/arduino-gameboy-printer-emulator
// https://gist.github.com/mofosyne/b1fc240b64c520c0bf3541a029e3dcc3
// Brian Khuu 2021
if (!parameterStr)