Skip to content

Instantly share code, notes, and snippets.

View sophec's full-sized avatar
🖤
[[maybe_unused]]

Sophie Eccles sophec

🖤
[[maybe_unused]]
View GitHub Profile
@sophec
sophec / shellandc.c
Last active May 29, 2026 18:44
A C program (*with $ in identifiers) which is also a valid bash script, and vice versa.
#include <stdio.h>
#define $x ,x
#define $i ,i
#define eval int
#define read scanf
#define $scanfpat "%d", &
#define $(x) ,(x)
#define $open (
#define $close )
#define do {
@sophec
sophec / gpioutil.c
Last active June 19, 2020 14:31
A simple command-line utility for managing GPIO devices
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <fcntl.h>
static enum MODE {
INFO,
EXPORT,
@sophec
sophec / sockets.h
Last active May 29, 2026 18:40
Cross-platform socket header for both POSIX sockets and Winsock
/*
* File: sockets.h
* Author: Sophie Eccles
* Date: 2020-03-12
*
* 1. Description
*
* This header attempts to make it easy to use sockets across platforms,
* for both Windows and POSIX systems. While Winsock is often somewhat
* compatible with Berkeley sockets, it is not strictly compatible,
@sophec
sophec / cp.c
Last active February 18, 2020 23:52
recursive file copying function in C
// note there is no check for excessive recursion so if something has already been copied it will be tried again
int cpfile(const char* src, const char* dst) {
char* b = basename(src);
if (b != NULL && (0 == strcmp(b, ".") || 0 == strcmp(b, ".."))) {
return 0;
}
struct stat srcstat, dststat;
bool dstexist = false;
int s = 0;
@sophec
sophec / gpiodetails.sh
Created January 3, 2020 13:19
A script to get the details of an exported GPIO device.
#! /bin/bash -e
if [[ $# < 2 ]]; then
echo "Example usage: $0 1 27"
echo "This would get the details of GPIO1_27 if it's exported."
exit 1
fi
DEVNUM=$(( 32 * $1 + $2 ))
@sophec
sophec / listfonts.sh
Last active January 2, 2020 22:50
Take screenshots of all fonts in a linux console.
#! /bin/bash -e
if ! command -v fbgrab &>/dev/null; then
echo "Please install fbgrab before running this."
exit 1
fi
fontpath="${FONTPATH:-/usr/share/consolefonts}"
cd "$fontpath"
@sophec
sophec / conway.c
Last active December 4, 2019 17:36
Conway's Game of Life in C
/*
* Input is from stdin. The first line should be the width of the grid.
* The second line should be the height.
* The third line should be the length of a generation in microseconds.
* The rest of the file is assumed to be the grid itself
* Anything out of bounds will be cut off.
* A space is a "dead" cell; anything else is assumed to be a "living" cell.
*
* This implementation doesn't allow cells to wrap around. Edges are solid
* and block cells.
@sophec
sophec / scpitester.c
Last active November 10, 2023 21:09
/* Compile with -DUSE_READLINE and -lreadline to use readline for input. */
#include <arpa/inet.h>
#include <errno.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
@sophec
sophec / svnsettle.sh
Last active May 29, 2026 18:41
Shell script that adds unknown files to SVN and removes missing files from SVN.
#! /bin/bash
# File: svnsettle
# Author: Sophie Eccles
# Date: 2019-08-14T07:42R
# Description: This script takes any unknown files in an SVN repo (not counting
# ignored ones, obviously) and adds them. If there are any missing files, it
# will remove them from SVN. Note that this is not necessarily a perfect
# solution, but it does what I wanted it to. It's definitely not the cleanest
@sophec
sophec / bmp2arduino.cs
Last active May 29, 2026 18:42
A simple program to convert a Windows bitmap to an Adafruit GFX library bitmap array for monochrome OLED displays.
/*
* bmp2arduino.cs
* Sophie Eccles 2019
*
* Takes a Windows bitmap file and outputs a C header containing a bitmap array
* to be used with the Adafruit GFX library. Only works for monochrome files at this time.
* All pixels that are not black or transparent are assumed to be white.
*
* Run with no arguments to see usage.
*