1. 27

Recently, I wanted to convey to a non-technical friend how easy it is to build file transfer tools. I remembered Ed Felten’s TinyP2P from 2004 (!!), small enough that it could be printed on a single piece of paper or a T-shirt.

I’m looking for other useful tools that are similarly small: something that could fit on an artistically-arranged poster or a T-shirt, effectively turning that thing into a way to show how little code it can take to write something impactful and useful, even if a little obtuse and user-unfriendly.

My next target is to find an audio codec that is similarly succinct. The input would probably be PCM audio ripped straight from a CD or recorded from the airwaves using software-defined radio with a goal of achieving a highest compression possible with the smallest code size. The goal would be to use only what’s included in the standard distribution of a language - no network connectivity allowed, just like TinyP2P. I think enough languages’ standard library ships with zlib that it might be enough but maybe there are techniques achievable compress audio better than zlib.


    1. 1

      Yeah! This is great. I forgot about this one!

    2. 7

      If you allow me the self-advertising remark, check out suckless.org, especially our repositories. We strive to keep our code as short as possible and concise and our projects cover a large range of problems; of especial note are dwm (window manager), st (terminal emulator), dmenu (program launcher), slock (screen locker), sbase and ubase (coreutils replacement) and quark (web server).

      Something that can be printed on a T-Shirt is our sinit, which is an init(1) written in under 100 LOC and a counterposition against systemd.

      Considering you mentioned interest in a simple codec, you might be interested in farbfeld, which approaches image formats in a simple manner using UNIX-principles.

      1. 7

        The RSA munition T-Shirt is a classic example of this: http://www.cypherspace.org/adam/shirt/design/

        1. 1

          Fantastic example! Thank you!

        2. 5

          This may not be quite what you’re looking for, but the 500 Lines or Less book has some interesting examples all of which come in (unsurprisingly) under 500 Lines.

          1. 5

            maybe not quite right, but just to get things started, i really love these two tools by my friend:

            it’s especially neat because they work together really nice. the commando code is probably too long for a t-shirt; but these days it could be shortened down.

            1. 4

              A 2D graphics library that fits on a single page, replacing 10,000 lines of C in the Cairo library. See page 4 of this PDF: https://raw.githubusercontent.com/wiki/damelang/nile/socal.pdf

              1. 2

                A ray tracer, written in C, that fits on a business card: http://fabiensanglard.net/rayTracing_back_of_business_card/index.php

                1. 5

                  This is a famous APL program that computes the next generation in John Conway’s “Game of Life”:

                    life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}

                  When I was a teenager, some kids were passing this around, and it got me interested in programming.

                  1. 5

                    An alternate version to contemplate:

                    life ← { ⊃ 1 ⍵ ∨.∧ 3 4 = 1 0 ¯1 +.(⌽∘⍉)⍣2 ⊂⍵ }
                2. 1

                  This is pretty cool. Thank you!

                3. 3

                  Where Ruby is concerned, minitest has a reputation of being small but mighty: https://github.com/seattlerb/minitest . Not sure if it would fit on a t-shirt, but it’s substantially smaller than its alternatives.

                  1. 3

                    It might be a stretch, but the IOCCC 2018 Best of Show entry may be deemed useful in its target niche.

                    Also, r/tinycode is ostensibly aimed at sharing code with qualities similar to what you describe, but personally I don’t find the subreddit to be working well w.r.t. fulfilling this premise, unfortunately.

                    1. 1

                      Thank you for the suggestions! /R/tinycode is a shove in the direction.

                    2. 2

                      http://microjs.com/ is a collection of JavaScript libraries, all 5kb or less. Some much less. Not sure if it fits what you’re looking for though since it’s libraries and not applications.

                      Found years ago through this presentation which is interesting if you’re interested in cutting down on JavaScript size.

                      1. 2
                        1. 2

                          Oh man that’s hilarious. The fact they even went so far as to create an init file and everything.

                        2. 1

                          What about coreutils?

                          I mean, the codebase isn’t small, but it consists of quite a few standalone applications that are super small. And they are highly impactfull for sure!

                          1. 2

                            I found coreutils surprisingly easy to hack on, when I wanted to work around Emacs hanging at 100% CPU when given very long lines (which are quite common when running terminals inside Emacs). I wanted to pipe everything through the fold command to insert newlines every 1000 characters, but that didn’t work since it buffers the content (i.e. the current line, containing the shell prompt and the command we’re writing, wouldn’t appear until it reached 1000 characters). I ended up forking it, ripping out a bunch of optional stuff (including memory allocations) and hard-coding it to my use-case, and it works really well.

                            I know it’s only a small, standalone utility (as you say), but I was surprised how trivial I found it; considering that I generally try to avoid touching C, and have heard horror stories about GNU’s coding conventions, build system, etc.

                          2. 1

                            Years ago I made a few small Python scripts along similar lines, although they’re meant to be idiomatic (that TinyP2P is rather minified/obfuscated). They include:

                            These mostly show how much functionality is provided by Python libraries, and how easy things are when we hard-code everything and don’t handle errors ;)