Skip to content

Instantly share code, notes, and snippets.

View radiofreejohn's full-sized avatar

John Clover radiofreejohn

View GitHub Profile
@radiofreejohn
radiofreejohn / randword.c
Created April 4, 2011 02:52
open a dictionary file and return a random word
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
/*
I wrote this as a sort of challenge, I wanted to pass random words into the K&R exercise
that generates a hash table of key value pairs to see how quickly the hashes stack up on
one another. I could have easily piped random words to the input, but that's not painful
at all...
*/
@radiofreejohn
radiofreejohn / btree-norec.c
Created May 27, 2011 16:42
non-recursive binary search tree without return
#include <stdio.h>
#include <stdlib.h>
#include "numbers.h" // https://gist.github.com/911872
struct node {
int key;
struct node *l;
struct node *r;
};
@radiofreejohn
radiofreejohn / kr5-3.c
Created March 12, 2011 05:33
K&R exercise 5-3, strcat
#include <stdio.h>
void *strcatsnot(char *s, const char *t);
void *strcatsnot(char *s, const char *t)
{
while (*++s)
;
while (*s++ = *t++)
;
@radiofreejohn
radiofreejohn / async.go
Created May 3, 2018 16:06
adding callback hell to go, why not?
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"sync"
)
@radiofreejohn
radiofreejohn / mergesort.c
Created April 15, 2011 01:13
Simple mergesort from Sedgewick's Algorithms in C++
#include <stdio.h>
#include "numbers.h" // https://gist.github.com/911872
int main()
{
struct numbers a;
struct numbers b;
/*
I feel like a tool, sort of. I spent more time than I should admit using
generateRandoms here, forgetting that mergesort can only merge two arrays
@radiofreejohn
radiofreejohn / keybase.md
Created July 18, 2016 15:57
Keybase Verification

Keybase proof

I hereby claim:

  • I am radiofreejohn on github.
  • I am radiofreejohn (https://keybase.io/radiofreejohn) on keybase.
  • I have a public key whose fingerprint is 1C44 2943 B328 703E FBF2 F180 A91A DB31 84F2 2D74

To claim this, I am signing this object:

@radiofreejohn
radiofreejohn / poker.c
Created March 25, 2012 06:33
Poker game solver
/*
input is 1 line with 10 cards, black first, white second
cards are sorted by value (suit is disregarded when sorting)
when tested for hand type -- they are sorted again based on the
order of evaluation of the hand when comparing the two, so
full house will put the 3 of a kind highest, then the 2 of a kind.
A pair will have the pair as the last two cards, and the rest
sorted by from lowest to highest. This makes it easy to determine
the winner by comparing down from the top.
@radiofreejohn
radiofreejohn / check-frag.c
Created January 20, 2012 02:00
check individual files for fragmentation on Mac OS X
/*
check-frag filename [blocksize guess]
blocksize default is 4096 -- smaller and seeks take too long
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>
@radiofreejohn
radiofreejohn / newc.sh
Created January 16, 2012 05:40
create a skeleton C source with main() and includes
#!/bin/bash
#+
# Usage
# newc filename [include[.h] ...]
#
# Output
# Creates a file (filename) with a skeleton main function, with
# optional include files in the header. If the file exists in
# /usr/include then #include <include.h> is added, if it is not
# found in /usr/include, but is found in the current directory
@radiofreejohn
radiofreejohn / nv3h_read_gz.c
Created January 11, 2012 02:12
IDL dlm to read formatted ASCII files
/*
* gcc nv3h_read_gz.c -shared -Bsymbolic -I/zshare/rsi/idl_6.3/external/include -L/zshare/rsi/idl_6.3/bin/bin.linux.x86_64 -lidl -o nv3h_read_gz.so -fPIC -lz -ldl
*
* requires zlib 1.2.5 for gzbuffer -- will check for right version
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <zlib.h>