Skip to content

Instantly share code, notes, and snippets.

View francisrstokes's full-sized avatar
🎥
Low Byte Productions on YouTube

Francis Stokes francisrstokes

🎥
Low Byte Productions on YouTube
View GitHub Profile
@francisrstokes
francisrstokes / cb.h
Last active December 16, 2024 10:27
Reusable header-only circular buffer library in C
#pragma once
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
// Defines
#define CBT_MIN(a, b) ((a) < (b) ? (a) : (b))
// Checks
@francisrstokes
francisrstokes / Shell_Keybindings.md
Created December 13, 2024 10:04 — forked from 2KAbhishek/Shell_Keybindings.md
Keyboard shortcuts for bash/zsh

Shell Keybindings

Navigation 🚀

Keybinding Action
Alt + f/b Move cursor to previous/next word
Ctrl + a/e Move cursor to beginning/end of command
Ctrl + xx Toggle between the start of line and current cursor position
@francisrstokes
francisrstokes / what-did-i-work-on.sh
Created November 8, 2024 10:47
What did I work on in the last week
#!/bin/bash
# Default value for days
DAYS=7
# Check if a custom number of days is provided as an argument
if [ "$1" ]; then
DAYS=$1
fi
@francisrstokes
francisrstokes / .tmux.conf
Created November 1, 2024 08:46
tmux config
# Allow mouse interaction
set -g mouse on
# Don't rename windows automatically
set-option -g allow-rename off
# Use C-a instead of C-b
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
@francisrstokes
francisrstokes / protocol-decoder.py
Last active October 20, 2024 21:43
Decodes SPI transactions for the ENC28J60 chip recorded and exported from the Saleae logic2 software
import pandas as pd
import sys
from enum import Enum
""" protocol-decoder.py <saleae csv file>
Takes in an exported csv file from the Saleae logic2 software, where the SPI analyzer was used to trace communication with an enc28j60 ethernet
chip from Microchip, and produces the instructions and responses the communication represents.
- Software resets
@francisrstokes
francisrstokes / raw_eth.py
Created October 10, 2024 21:22
Sending raw ethernet packets with python
from socket import socket, AF_PACKET, SOCK_RAW
ETH_P_ALL = 0x0003
print("Starting")
interface = "enx7cc2c65485c0"
# interface_mac = 7c:c2:c6:54:85:c0
# Note: When sending ethernet frames, only the following data is actually supplied at this level:
@francisrstokes
francisrstokes / windowed_sinc_filter.py
Created October 9, 2024 13:42
Creating and using windowed sinc filters (low-pass and high pass) from scratch
import math
import numpy as np
import matplotlib.pyplot as plt
# Generate a lowpass filter using a windowed sinc function
def sinc(x):
if x == 0:
return 1
return math.sin(math.pi * x) / (math.pi * x)
@francisrstokes
francisrstokes / dft.py
Last active June 28, 2024 07:29
Discrete Fourier Transform From Scratch
# X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-\frac{j 2 \pi k n}{N}}
# X_k = \sum_{n=0}^{N-1} x_n \cdot [\cos(-\frac{2 \pi k n}{N}) + j\sin(-\frac{2 \pi k n}{N})]
import math
import cmath
def generate_data(timespan=64):
data = []
for i in range(timespan):
ni = i/timespan
@francisrstokes
francisrstokes / fixcallgrind.py
Created December 13, 2023 08:34
Just a hacky script to fix the output of callgrid captures for Zig binaries
import re
import sys
import subprocess
callgrind_file = sys.argv[1]
executable_file = sys.argv[2]
if len(sys.argv) < 3:
print("Usage: fix-callgrind.py <callgrind file> <executable>")
sys.exit(1)
@francisrstokes
francisrstokes / machine.c
Created July 31, 2023 17:56
Simple State Machine Base
#include "machine.h"
void state_machine_step(state_machine_t* descriptor) {
state_transition_t* transition;
uint32_t current_state = *descriptor->state_index;
for (uint32_t i = 0; i < descriptor->num_transitions; i++) {
transition = &descriptor->transitions[i];
if ((transition->from_state == current_state) && (transition->condition(current_state))) {
descriptor->on_state_change(current_state, transition->to_state);