Skip to content

Instantly share code, notes, and snippets.

@joeyadams
joeyadams / long-division.c
Created March 14, 2011 21:07
Long division sample program and test suite
#if 0
function invoke {
n=$1
d=$2
# Add a line below to call your program. Examples:
# ./program-taking-arguments $n $d
# { echo $n; echo $d; } | ./program-reading-stdin
}
@joeyadams
joeyadams / expected
Created March 15, 2011 15:01
Plain-text alternative to long division test suite
22
----
56|1234
112
---
114
112
---
2
83501
/*
* Copyright (C) 2011 Joseph Adams <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@joeyadams
joeyadams / million-random-lines.c
Created April 19, 2011 20:05
Benchmarking data for line sorting
/*
* Generate 1,000,000 lines of pseudorandom text.
* Each line matches ([\x20-\x7E]|[\xA0-\xFF]){0,127}\n
*
* sha256sum of output:
* 64a9d302d9fc1d0dc9d351c706153dfdd7821182ac8c3d7ed5581850c13ae240
*
* sha256sum of output, sorted with LC_ALL=C sort :
* 6e1e5b2cdb848c02c304d08c565dbd34d394b5ee322019098e10a5b7210f314b
*/
@joeyadams
joeyadams / gist:930486
Created April 20, 2011 06:21
Benchmarking tool for sort function
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sort(const char **strings, size_t count, const char **out);
/* Macros grabbed from my darray module:
* http://ccan.ozlabs.org/info/darray.html */
#define darray(type) struct {type *item; size_t size; size_t alloc;}
#define darray_new() {0,0,0}
@joeyadams
joeyadams / ci.c
Created April 23, 2011 13:13
CI: A simple self-interpreter that's actually a compiler
/*
* Copyright (C) 2011 Joseph Adams <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@joeyadams
joeyadams / randfile.hs
Created June 18, 2011 20:54
Pick a file by randomly descending until one is found.
import Prelude hiding (catch)
import Control.Applicative
import Control.Exception
import System.Directory
import System.Exit
import System.FilePath
import System.Posix.Files
import System.Random
@joeyadams
joeyadams / hpool.c
Created June 29, 2011 04:47
Simple, fast memory pool implementation for TI-68k, including demo game.
/*
Copyright (C) 2011 Joseph A. Adams ([email protected])
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
#!/bin/bash
if [ $# -lt 1 ] ; then
echo "Usage: $0 ./command" >& 2
exit 1
fi
if [ $# -eq 1 ] ; then
if [ ! -f "$(which "$1" 2>/dev/null)" ] ; then
if [ -f "./$1" ] ; then
@joeyadams
joeyadams / connectex-bind.cpp
Created November 28, 2012 04:07
Working ConnectEx example
#include <stdio.h>
#include <WinSock2.h>
#include <MSWSock.h>
#include <WS2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
struct mswsock_s {
LPFN_CONNECTEX ConnectEx;
} mswsock;