Skip to content

Instantly share code, notes, and snippets.

@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;
@wd5gnr
wd5gnr / Program.cpp
Created May 5, 2023 21:29
1802 Literate Assembler Examples
// Simple 1802 Literate Program
#include "lit1802.h"
#define ON 1
#define OFF 0
#define DELAYPC 9 // delay subroutine
#define DELAYR 8 // delay count register
#define MAINPC 3 // Main routine PC
@wd5gnr
wd5gnr / hilo.sh
Last active March 29, 2023 20:02
A simple hilo game using Gum (https://github.com/charmbracelet/gum)
#!/bin/bash
clear
# init colors
FG="#00ffff"
BFG="#00ff00"
# if you wonder why true is in there https://www.shellcheck.net/wiki/SC2015
gum confirm --default --affirmative="Play now" --negative="Dump source first" --timeout=10s "Would you like to view the source code before playing?" && true || ( gum format -t code <"$0" )
# get initial info
gum style --foreground "$FG" --border-foreground "$BFG" --border double --align center --width 64 --margin "1 2" --padding "2 4" \
@wd5gnr
wd5gnr / baloo-nice
Created June 1, 2022 14:43
A script to move baloo to a cgroup to limit both memory and disk I/O
#!/bin/bash
#baloo-nice by Al Williams
if [ "$1" == "fast" ]
then
RLIMIT=100048576 # bps limit (read)
WLIMIT=100048576 # bps limit (write)
else
RLIMIT=548576 # bps limit (read)
WLIMIT=548576 # bps limit (write)
@wd5gnr
wd5gnr / main.c
Created April 25, 2021 19:43
Simple SQLite example
#include <sqlite3.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
sqlite3 *db;
sqlite3_stmt *sql;
int rv;
rv=sqlite3_open("parts.db",&db);