diff --git a/doc/2012-07-DC20/generalstatics.com/bg.jpg b/doc/2012-07-DC20/generalstatics.com/bg.jpg new file mode 100644 index 0000000..0c8ec50 Binary files /dev/null and b/doc/2012-07-DC20/generalstatics.com/bg.jpg differ diff --git a/doc/2012-07-DC20/generalstatics.com/cgi.c b/doc/2012-07-DC20/generalstatics.com/cgi.c new file mode 100644 index 0000000..008a6ec --- /dev/null +++ b/doc/2012-07-DC20/generalstatics.com/cgi.c @@ -0,0 +1,241 @@ +#include +#include +#include +#include +#include "cgi.h" + +#ifdef NODUMP +# define DUMPf(fmt, args...) +#else +# define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#endif +#define DUMP() DUMPf("") +#define DUMP_d(v) DUMPf("%s = %d", #v, v) +#define DUMP_x(v) DUMPf("%s = 0x%x", #v, v) +#define DUMP_s(v) DUMPf("%s = %s", #v, v) +#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v) +#define DUMP_p(v) DUMPf("%s = %p", #v, v) + + +#define POST_MAX 1024 + +/* + * CGI + */ +static int is_cgi = 0; +static char **argv = NULL; + +static int +read_char_argv() +{ + static int arg = 0; + static char *p; + + if (NULL == argv) { + return EOF; + } + + if (0 == arg) { + arg = 1; + p = argv[1]; + } + + if (! p) { + return EOF; + } else if (! *p) { + arg += 1; + p = argv[arg]; + return '&'; + } + + return *(p++); +} + +static int +read_char_stdin() +{ + static int inlen = -1; + + if (-1 == inlen) { + char *p = getenv("CONTENT_LENGTH"); + if (p) { + inlen = atoi(p); + if (inlen > POST_MAX) { + inlen = POST_MAX; + } + if (inlen < 0) { + inlen = 0; + } + } else { + inlen = 0; + } + } + + if (inlen) { + inlen -= 1; + return getchar(); + } + return EOF; +} + +static int +read_char_query_string() +{ + static char *p = (char *)-1; + + if ((char *)-1 == p) { + p = getenv("QUERY_STRING"); + } + + if (! p) { + return EOF; + } else if (! *p) { + return EOF; + } else { + return *(p++); + } +} + +static int (* read_char)() = read_char_argv; + +int +cgi_init(char *global_argv[]) +{ + char *rm = getenv("REQUEST_METHOD"); + + if (! rm) { + read_char = read_char_argv; + argv = global_argv; + } else if (0 == strcmp(rm, "POST")) { + read_char = read_char_stdin; + is_cgi = 1; + } else if (0 == strcmp(rm, "GET")) { + read_char = read_char_query_string; + is_cgi = 1; + } else { + printf(("405 Method not allowed\r\n" + "Allow: GET, POST\r\n" + "Content-type: text/plain\r\n" + "\r\n" + "%s is not allowed.\n"), + rm); + return -1; + } + + return 0; +} + +static char +tonum(int c) +{ + if ((c >= '0') && (c <= '9')) { + return c - '0'; + } + if ((c >= 'a') && (c <= 'f')) { + return 10 + c - 'a'; + } + if ((c >= 'A') && (c <= 'F')) { + return 10 + c - 'A'; + } + return 0; +} + +static char +read_hex() +{ + int a = read_char(); + int b = read_char(); + + return tonum(a)*16 + tonum(b); +} + +/* Read a key or a value. Since & and = aren't supposed to appear + outside of boundaries, we can use the same function for both. +*/ +size_t +cgi_item(char *str, size_t maxlen) +{ + int c; + size_t pos = 0; + + while (1) { + c = read_char(); + switch (c) { + case EOF: + case '=': + case '&': + str[pos] = '\0'; + return pos; + case '%': + c = read_hex(); + break; + case '+': + c = ' '; + break; + } + if (pos < maxlen - 1) { + str[pos] = c; + pos += 1; + } + } +} + +void +cgi_head(char *title) +{ + if (is_cgi) { + printf("Content-type: text/html\r\n\r\n"); + } + printf(("\n" + "\n" + " \n" + " %s\n" + " \n" + " \n" + "

%s

\n"), + title, title); +} + +void +cgi_foot() +{ + printf("\n" + " \n" + "\n"); +} + +void +cgi_result(int code, char *desc, char *fmt, ...) +{ + va_list ap; + + if (is_cgi) { + printf("%d %s\r\n", code, desc); + } + cgi_head(desc); + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + cgi_foot(); + exit(0); +} + +void +cgi_page(char *title, char *fmt, ...) +{ + va_list ap; + + cgi_head(title); + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + cgi_foot(); + exit(0); +} + +void +cgi_error(char *text) +{ + cgi_result(500, "Internal error", "

%s

", text); +} + diff --git a/doc/2012-07-DC20/generalstatics.com/cgi.h b/doc/2012-07-DC20/generalstatics.com/cgi.h new file mode 100644 index 0000000..04eed9f --- /dev/null +++ b/doc/2012-07-DC20/generalstatics.com/cgi.h @@ -0,0 +1,14 @@ +#ifndef __CGI_H_ +#define __CGI_H_ + +#include + +int cgi_init(char *global_argv[]); +size_t cgi_item(char *str, size_t maxlen); +void cgi_head(char *title); +void cgi_foot(); +void cgi_result(int code, char *desc, char *fmt, ...); +void cgi_page(char *title, char *fmt, ...); +void cgi_error(char *text); + +#endif diff --git a/doc/2012-07-DC20/generalstatics.com/data.png b/doc/2012-07-DC20/generalstatics.com/data.png new file mode 100644 index 0000000..8580749 Binary files /dev/null and b/doc/2012-07-DC20/generalstatics.com/data.png differ diff --git a/doc/2012-07-DC20/generalstatics.com/index.html b/doc/2012-07-DC20/generalstatics.com/index.html new file mode 100644 index 0000000..44c59cc --- /dev/null +++ b/doc/2012-07-DC20/generalstatics.com/index.html @@ -0,0 +1,212 @@ + + + + General Statics + + + + + +

General Statics

+ +

+ General Statics is pleased to announce our shift into the casual gaming + market. Please try our new flagship product: Tic-Tac-Toe Extreme! +

+ + + + + + +
You play X. Reload this page to start over.
+ +

+ This strategic shift will bring our company back to the forefront + of revenue-generating companies. +

+ +

About Us

+ +

+ Most strategic planning involves thinking and talking + about the future. Crafting and executing strategy requires + actually making decisions and acting on the future. And doing + so in an “expeditionary” manner that enables continuous + change, flexibility, and adaptability. +

+ +

+ General Statics continuously delivers value through leveraging technology to + change behaviors, processes and practices. In the Knowledge Economy, many + of the most decisive sources of value are intangible. We + help our clients to optimize both tangible and intangible + + value. We deploy and leverage new technologies to change the + dynamics of organizational processes, relationships, and + interactions with customers, clients, partners, members, and + other stakeholders. This drives enhanced performance, reduces + costs, and enables enterprises to improve their competitive + advantage. +

+ +

+ Knowledge Age enterprises must realign their strategies, + processes and practices to the post-recession Economy. + New generations of measurement and analytics tools are + making it possible for enterprises to pursue new + strategies that lead them to higher planes of nimble + performance. +

+ +

+ Employee access: + +

+ + + diff --git a/doc/2012-07-DC20/generalstatics.com/msg.ogg b/doc/2012-07-DC20/generalstatics.com/msg.ogg new file mode 100644 index 0000000..bdae91f Binary files /dev/null and b/doc/2012-07-DC20/generalstatics.com/msg.ogg differ diff --git a/doc/2012-07-DC20/generalstatics.com/p2.png b/doc/2012-07-DC20/generalstatics.com/p2.png new file mode 100644 index 0000000..dc588d9 Binary files /dev/null and b/doc/2012-07-DC20/generalstatics.com/p2.png differ diff --git a/doc/2012-07-DC20/generalstatics.com/p2inv.png b/doc/2012-07-DC20/generalstatics.com/p2inv.png new file mode 100644 index 0000000..398c6c4 Binary files /dev/null and b/doc/2012-07-DC20/generalstatics.com/p2inv.png differ diff --git a/doc/2012-07-DC20/generalstatics.com/ttt.cgi.c b/doc/2012-07-DC20/generalstatics.com/ttt.cgi.c new file mode 100644 index 0000000..f902fcc --- /dev/null +++ b/doc/2012-07-DC20/generalstatics.com/ttt.cgi.c @@ -0,0 +1,198 @@ +#include +#include +#include +#include "cgi.h" + +const char *b64_aleph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@"; + +typedef int board_t[3][3]; + +void +b64_of_board(char *out, board_t board) +{ + int y, x; + + for (y = 0; y < 3; y += 1) { + int acc = 0; + + for (x = 0; x < 3; x += 1) { + acc <<= 2; + acc += board[y][x]; + } + out[y] = b64_aleph[acc]; + } +} + +void +board_of_b64(board_t out, char *b64) +{ + int y, x; + + for (y = 0; y < 3; y += 1) { + char *p = strchr(b64_aleph, b64[y]); + int acc = 0; + + if (p) { + acc = p - b64_aleph; + } + + for (x = 2; x >= 0; x -= 1) { + out[y][x] = acc & 3; + acc >>= 2; + } + } +} + +void +print_board(board_t board) +{ + int y, x; + + for (y = 0; y < 3; y += 1) { + for (x = 0; x < 3; x += 1) { + printf("%d", board[y][x]); + } + printf("\n"); + } +} + +int +winner(board_t board) +{ + int i, j, k; + + for (i = 0; i < 3; i += 1) { + for (k = 0; k < 3; k += 1) { + int winner = -1; + + for (j = 0; j < 3; j += 1) { + int b; + + switch (k) { + case 0: + b = board[i][j]; + break; + case 1: + b = board[j][i]; + break; + case 2: + /* This will happen 3× as often as it needs to. Who cares. */ + b = board[j][j]; + break; + } + + if (winner == -1) { + winner = b; + } else if (winner != b) { + winner = -1; + break; + } + } + if (winner > 0) { + return winner; + } + } + } + + return 0; +} + +void +claim(board_t board, int x, int y, int whom) +{ + int prev = board[x][y]; + int i; + + if (prev == whom) { + return; + } + + for (i = 0; i < 9; i += 1) { + if (! board[i/3][i%3]) { + board[i/3][i%3] = prev; + break; + } + } + + board[x][y] = whom; +} + +void +make_move(board_t board) +{ + switch (winner(board)) { + case 1: + printf("A WINNER IS YOU\n"); + exit(0); + case 2: + /* I win; we can keep playing though, because I (neale) + don't want to write any more code to handle this. */ + break; + case 3: + printf("A WINNER IS WHO?\n"); + exit(1); + } + + /* Reserve our final space */ + claim(board, 2, 2, 0); + + /* First move */ + if (board[1][1] != 2) { + claim(board, 1, 1, 2); + return; + } + + /* Second move */ + if (board[0][0] != 2) { + + /* Prevent them from winning legally */ + if (board[0][2]) { + claim(board, 1, 2, 0); + } + if (board[2][0]) { + claim(board, 2, 1, 0); + } + claim(board, 0, 0, 2); + return; + } + + /* Third move */ + claim(board, 2, 2, 2); +} + + +int +main(int argc, char *argv[]) +{ + char b64[4] = {0}; + board_t board = {0}; + + if (-1 == cgi_init(argv)) { + return 0; + } + + while (1) { + size_t len; + char key[20]; + + len = cgi_item(key, sizeof key); + if (0 == len) break; + switch (key[0]) { + case 'b': + cgi_item(b64, sizeof b64); + break; + default: + cgi_item(key, 0); + break; + } + } + + printf("Content-type: text/plain\r\n\r\n"); + board_of_b64(board, b64); + make_move(board); + b64_of_board(b64, board); + fwrite(b64, 1, 3, stdout); + + return 0; +} +