yo here's a link.
14 |
--------------------------------------------------------------------------------
/web/darkmode3.html:
--------------------------------------------------------------------------------
1 |
2 | dark mode theme test
3 |
5 |
6 | heading
7 | yo here's a link.
8 | yo here's another link.
9 |
--------------------------------------------------------------------------------
/web/drop-alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nico/hack/f9e9573f1afb48f9dd30f4d225d78fcd6bbb3bca/web/drop-alpha.png
--------------------------------------------------------------------------------
/web/drop-color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nico/hack/f9e9573f1afb48f9dd30f4d225d78fcd6bbb3bca/web/drop-color.png
--------------------------------------------------------------------------------
/web/webgl/README.txt:
--------------------------------------------------------------------------------
1 | Start a local webserver to look at stuff in this directory:
2 |
3 | python3 -m http.server
4 |
--------------------------------------------------------------------------------
/web/webgl/jimmy.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nico/hack/f9e9573f1afb48f9dd30f4d225d78fcd6bbb3bca/web/webgl/jimmy.jpg
--------------------------------------------------------------------------------
/wpng/gz.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Test program to write uncompressed gzip file.
4 |
5 | clang -o gz gz.c -Wall
6 | ./gz | gunzip
7 |
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | // http://www.ietf.org/rfc/rfc1952.txt
15 | uint32_t crc_table[256];
16 | void make_crc_table(void) {
17 | for (int n = 0; n < 256; n++) {
18 | uint32_t c = (uint32_t) n;
19 | for (int k = 0; k < 8; k++)
20 | if (c & 1)
21 | c = 0xedb88320u ^ (c >> 1);
22 | else
23 | c = c >> 1;
24 | crc_table[n] = c;
25 | }
26 | }
27 | uint32_t update_crc(uint32_t crc, const unsigned char *buf, int len) {
28 | uint32_t c = crc ^ 0xffffffffu;
29 | for (int n = 0; n < len; n++)
30 | c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
31 | return c ^ 0xffffffffu;
32 | }
33 | uint32_t crc(const unsigned char *buf, int len) {
34 | return update_crc(0, buf, len);
35 | }
36 |
37 | void fput_n_le(uint32_t u, FILE* f, int n) {
38 | for (int i = 0; i < n; i++) fputc(u >> (8*i), f);
39 | }
40 | int main() {
41 | make_crc_table();
42 |
43 | const unsigned char data[] = "Hello gzip\n";
44 |
45 | // header
46 | fputc(31, stdout); // magic number 1
47 | fputc(139, stdout); // magic number 2
48 | fputc(8, stdout); // compression method: deflate
49 | fputc(0, stdout); // flags
50 | fput_n_le(0, stdout, 4); // mtime
51 | fputc(0, stdout); // extra flags
52 | fputc(0xff, stdout); // OS
53 |
54 | // data
55 | fputc(1, stdout); // Final block, compression method: uncompressed
56 | fput_n_le(sizeof(data), stdout, 2);
57 | fput_n_le(~(uint16_t)sizeof(data), stdout, 2);
58 | fwrite(data, 1, sizeof(data), stdout);
59 |
60 | // footer
61 | fput_n_le(crc(data, sizeof(data)), stdout, 4); // crc32
62 | fput_n_le(sizeof(data), stdout, 4); // ISIZE
63 | }
64 |
--------------------------------------------------------------------------------
/wpng/wpng.c:
--------------------------------------------------------------------------------
1 | /* Bare-bones png writer. Just uncompressed rgba png, no frills. Build like:
2 | clang -o wpng wpng.c -Wall
3 | */
4 |
5 | #include
6 | #include
7 |
8 | void wpng(int w, int h, const uint8_t* pix, FILE* f) { // pix: rgba in memory
9 | uint32_t crc_table[256], crc = ~0;
10 | for (uint32_t n = 0, c = 0; n < 256; n++, c = n) {
11 | for (int k = 0; k < 8; k++) c = -(c & 1) & 0xedb88320L ^ (c >> 1);
12 | crc_table[n] = c;
13 | }
14 | #define CRCWRITE(d, len) fwrite(d, 1, len, f); for (int n = 0; n < len; n++) \
15 | crc = crc_table[(crc ^ (d)[n]) & 0xff] ^ (crc >> 8)
16 | #define U32BE(b, u) b[0] = (u)>>24; b[1] = (u)>>16; b[2] = (u)>>8; b[3] = (u)
17 | uint8_t I[] = "\x89PNG\r\n\x1a\n\0\0\0\xdIHDRwid0hyt0\x8\6\0\0\0", B[4];
18 | fwrite(I, 1, 12, f);
19 | U32BE((I + 16), w); U32BE((I + 20), h); CRCWRITE(I+12, 17);
20 | U32BE(B, ~crc); fwrite(B, 1, 4, f); // IHDR crc32
21 | uint16_t scanl = w*4 + 1;
22 | U32BE(B, 6 + (5 + scanl)*h); fwrite(B, 1, 4, f);
23 | crc = ~0; CRCWRITE("IDAT\x8\x1d", 6);
24 | uint32_t a1 = 1, a2 = 0;
25 | for (int y = 0; y < h; ++y, pix += w*4) {
26 | uint8_t le[] = { y == h - 1, scanl, scanl >> 8, ~scanl, ~scanl >> 8, 0 };
27 | CRCWRITE(le, 6);
28 | CRCWRITE(pix, w*4);
29 | const int P = 65521;
30 | a2 = (a1 + a2) % P;
31 | for (int n = 0; n < w*4; n++) { a1 = (a1+pix[n]) % P; a2 = (a1+a2) % P; }
32 | }
33 | U32BE(B, (a2 << 16) + a1); CRCWRITE(B, 4); // adler32 of uncompressed data
34 | U32BE(B, ~crc); fwrite(B, 1, 4, f); // IDAT crc32
35 | #undef CRCWRITE
36 | #undef U32BE
37 | fwrite("\0\0\0\0IEND\xae\x42\x60\x82", 1, 12, f); // IEND + crc32
38 | }
39 |
40 | int main() {
41 | uint8_t pix[256*125*4];
42 | for (size_t i = 0; i < sizeof(pix); ++i) pix[i] = i*i;
43 | wpng(125, 256, pix, stdout);
44 | }
45 |
--------------------------------------------------------------------------------
/wpng/wtga.c:
--------------------------------------------------------------------------------
1 | /* tga writer. Build like:
2 | clang -o wtga wtga.c -Wall
3 | */
4 |
5 | #include
6 | #include
7 |
8 | // pix: bgra in memory, bottom-most scanline first
9 | void wtga(uint16_t w, uint16_t h, const uint8_t* pix, FILE* f) {
10 | uint8_t head[] = { 0,0,2,0,0,0,0,0,0,0,0,0,w,w>>8,h,h>>8,32,0 };
11 | fwrite(head, 1, sizeof(head), f);
12 | fwrite(pix, 1, w*h*4, f);
13 | }
14 |
15 | int main() {
16 | uint8_t pix[] = {0xff,0,0,0xff, 0,0xff,0,0xff, 0,0,0xff,0xff, 0xff,0,0,0x80};
17 | wtga(2, 2, pix, stdout);
18 | }
19 |
--------------------------------------------------------------------------------
/xmltest_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | text&more@
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/xmltest_msxml_import.cc:
--------------------------------------------------------------------------------
1 | // cl /nologo xmltest.cc
2 | // msxml6.tlh autolinks ole32.lib oleaut32.lib comsuppw.lib
3 | #import // Generates and includes msxml6.tlh msxml6.tli
4 | #include
5 |
6 | // Note: MSXML2::IFooPtr is different from ::IFooPtr.
7 | // The MSXML2 types use exceptions instead of HRESULT.
8 |
9 | void print(MSXML2::IXMLDOMNodePtr n, int indent) {
10 | variant_t node_value = n->nodeValue;
11 | bstr_t node_value_str;
12 | if (node_value.GetVARIANT().vt != VT_NULL)
13 | node_value_str = (bstr_t)node_value;
14 | for (int i = 0; i < indent; ++i) printf(" ");
15 | printf("%d/%S %S %S %S\n", n->nodeType, (BSTR)n->nodeTypeString,
16 | (BSTR)n->nodeName, (BSTR)node_value_str, (BSTR)n->namespaceURI);
17 |
18 | if (MSXML2::IXMLDOMNamedNodeMapPtr attribs = n->attributes)
19 | for (long i = 0; i < attribs->length; ++i)
20 | print(attribs->item[i], indent + 2);
21 |
22 | MSXML2::IXMLDOMNodeListPtr children = n->childNodes;
23 | for (long i = 0; i < children->length; ++i)
24 | print(children->item[i], indent + 2);
25 | }
26 |
27 | void DumpFile(const char* filename) {
28 | MSXML2::IXMLDOMDocumentPtr xml_doc;
29 | xml_doc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
30 | xml_doc->async = VARIANT_FALSE;
31 | xml_doc->validateOnParse = VARIANT_FALSE;
32 | xml_doc->resolveExternals = VARIANT_FALSE;
33 | if (xml_doc->load(filename) != VARIANT_TRUE) {
34 | // Failed to load xml, get last parsing error
35 | printf("Failed to load DOM from stocks.xml. %S\n",
36 | (BSTR)xml_doc->parseError->reason);
37 | return;
38 | }
39 | print(xml_doc, 0);
40 | }
41 |
42 | int main(int argc, char *argv[]) {
43 | CoInitialize(NULL);
44 | for (int i = 1; i < argc; ++i)
45 | DumpFile(argv[i]);
46 | CoUninitialize();
47 | }
48 |
--------------------------------------------------------------------------------
/yak/.gitignore:
--------------------------------------------------------------------------------
1 | yak
2 | yak.o
3 |
--------------------------------------------------------------------------------
/yak/Makefile:
--------------------------------------------------------------------------------
1 | .POSIX:
2 | CC = cc
3 | CFLAGS = -Wall -Wextra -Wconversion -O2 -std=c17
4 |
5 | all: yak
6 | yak: yak.o
7 | $(CC) -o yak yak.o
8 | yak.o: yak.c
9 | clean:
10 | rm -f yak yak.o
11 |
--------------------------------------------------------------------------------