Skip to content

Instantly share code, notes, and snippets.

View jimfinnis's full-sized avatar

Jim Finnis jimfinnis

View GitHub Profile
// The door name. Inner door, outer door and airvent must have this in the name.
// Doors must also have [OUTER] and [INNER] also, and the displays must have [DISP]
private string doorName = "vingdoor";
private const bool DISABLE_VENT = true; // if true, disable air vent when not using airlock
private int tick=-1; // how long we have been in the current state; -1 nonsense value at start.
private const float HIGH = 0.95f; // high pressure threshold
private const float LOW = 0.05f; // low pressure threshold
@jimfinnis
jimfinnis / moonphase_ST7735.cpp
Created April 20, 2025 09:47
Rendering the phase of the moon accurately on an ST7735 using Bodmer's TFT_eSPI library
void display_moon(float phase, int16_t x, int16_t y, int16_t r){
// phase here is 0-1, where 0 and 1 are new and 0.5 is full.
// The x and y are the centre of the moon, and size is the radius of the moon.
// Yes, there's a lot of duplication here. Could be tidied up.
float n; // generally means "amount illuminated" or "amount not illuminated"
if(phase<0.25){
// we fill a circle and then draw a black ellipse
@jimfinnis
jimfinnis / fup
Last active December 6, 2022 16:21
This is the magic behind the shell "up" command. You can do "up 3" to go up 3 levels in the directory hierarchy, or "up foo" to go up to a directory whose name contains "foo".
#!/usr/bin/python3
# Used as part of 'up' to move up complex directory trees:
# With no args, prints '..'
# With a numeric argument, prints '../../' up as many levels as the arg.
# With a string argument, looks for a string in the path, and prints '../'
# enough times to go up to that directory.
#
# You also need to add to your .bash (I use .bash_aliases):
#
double prevtime = now();
for(;;){
render();
double t = now() - prevtime;
prevtime = now();
while(t>MINUPDATETIME){
update(MINUPDATETIME);
t-=MINUPDATETIME;
}
update(t);
@jimfinnis
jimfinnis / timer.h
Created March 22, 2016 10:20
Linux timer code
#include <stdio.h>
#include <time.h>
// calculate time in seconds between two timespecs
inline double time_diff(timespec start, timespec end)
{
timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) {

Keybase proof

I hereby claim:

  • I am jimfinnis on github.
  • I am jimfinnis (https://keybase.io/jimfinnis) on keybase.
  • I have a public key ASA9c-OHMfFtiCUK2jIZN958JncMTZXfEJ3tDjtjKpKLHgo

To claim this, I am signing this object:

/**
* @file advent.cpp
* @brief Brief description of file.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <angort/angort.h>
f = open('jokes.txt','r')
jokes = [x.strip() for x in f.read().split('%%')]
...
j = random.choice(jokes)
@jimfinnis
jimfinnis / gist:6823802
Created October 4, 2013 10:13
C++/C code to send UDP packets.
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>