Skip to content

Instantly share code, notes, and snippets.

View jimfinnis's full-sized avatar

Jim Finnis jimfinnis

View GitHub Profile
@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>