Skip to content

Instantly share code, notes, and snippets.

@wd5gnr
wd5gnr / .proj_dirs
Created March 5, 2025 21:15
Project CD (example of making a dual-mode script that can alter the caller's environment)
PROJ_DIRS["docs"]="~/library/documents"
PROJ_DIRS["video"]="~/library/videos"
PROJ_DIRS["arduino"]="/home/alw/projects/embedded/Arduino"
@wd5gnr
wd5gnr / Notes.md
Created February 11, 2025 15:34
Simple Custom WPSD remote setup

You need to do the following:

  1. Copy pistar-remote.wd5gnr to /usr/local/sbin/pistar-remote.wd5gnr AND /usr/local/sbin/pistar-remote.wd5gnr.backup (important!)
  2. Copy the files (remote-user-hook-example0, bm_tg.py, gnrcheck) for /usr/local/bin to your /usr/local/bin directory
  3. Edit (don't copy) your /etc/pistar-remote to look like the one below
  4. Copy and Edit /home/pi-star/user-hook-data to fit your needs
  5. Make all the files except user-hook-data executable (e.g., chmod +x gnrcheck)

Commands

@wd5gnr
wd5gnr / main.py
Created January 16, 2025 03:14
ToF Sensor for MicroPython
from machine import UART, Pin
import utime
from binascii import hexlify
# Configuration settings
UART_ID = 0 # UART instance ID
BAUD_RATE = 115200 # Baud rate for UART communication
TX_PIN = 16 # UART TX pin
RX_PIN = 17 # UART RX pin
SAMPLE_RATE_HZ = 4 # Sampling rate in Hz
@wd5gnr
wd5gnr / aplay.py
Created September 24, 2024 18:43
Klipper Aplay Extra
# Play a sound from gcode
#
# Copyright (C) 2023 Al Williams
#
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os
import shlex
import subprocess
import logging
@wd5gnr
wd5gnr / hackcurl.c
Created January 30, 2024 02:34
Simple libcurl example (uses autogenerated skeleton)
/********* Sample code generated by the curl command line tool **********
* All curl_easy_setopt() options are documented at:
* https://curl.se/libcurl/c/curl_easy_setopt.html
************************************************************************/
// Pick up Hackaday home page
#include <curl/curl.h>
@wd5gnr
wd5gnr / trigwave.ino
Created December 13, 2023 20:52
Trigger Demo Waveforms
// For best results use Normal trigger mode
#define CLOCK 6 // ch1
#define DATA 15 // ch2
#define RS232_OUT 0 // D0 -- by default; this symbol is not used
#define RS232_IN 1 // not really used
#define ANALOG_CLEAR 21 // Discharge analog capacitor fast
@wd5gnr
wd5gnr / badpython.py
Created November 7, 2023 22:47
Issue with Python Class Variables
# This is what's wrong with class variables in Python
# and yes, properties work (don't work) the same way
# This is a stupid but clean example where class A
# has a class variable x. It also has direct subclasses
# B and C
# Then there is a subclass of C named D
# None of them should have an x variable, but they all will get one
class A:
@wd5gnr
wd5gnr / test.py
Created October 25, 2023 19:44
Sample Python asyncio Test
import asyncio
import testb
state={'done': 0 }
async def taskA():
global done
print("A")
await asyncio.sleep(5)
print("A'")
@wd5gnr
wd5gnr / customprintf.c
Created October 3, 2023 16:32
Example of custom printf specifier
#include <stdio.h>
#include <stdlib.h>
#include <printf.h>
static int print_coin (FILE *stream,
const struct printf_info *info,
const void *const *args)
{
@wd5gnr
wd5gnr / rpn.c
Last active June 19, 2023 20:47
RPN in Python or C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
float stack[32];
unsigned sp=0;