Hacker News new | past | comments | ask | show | jobs | submit login

I make a shell script to accompany all code; I basically think of it as an "executable README". A README or blog post often contains shell commands. So I just copy those into a script.

And more often than not I add my own tests and demos. Sometimes I write a main() program, if it's C. If it's JS, then add an HTML skeleton and a script that runs a web server to demo it (e.g. python -m SimleHTTPServer). If it's Python, install any deps necessary. And often you will want to run the same script with many parameters to fully demo it.

The idea is to basically prove to yourself that the code works, without necessarily having to understand everything about it. Then when you see it later, your brain knows you can go back to it. You won't feel lazy like "oh man I have to go back and find the web page I saw 3 months ago, download code, pore through instructions to figure out how to build it". That part is already done.

For example, here's a snippet I did when testing out cityhash. It's usually much messier/longer than this.

    run.sh:

    #!/bin/bash
    readonly CITY_SRC=~/src/cityhash-1.1.1
    download() {
      ... <wget tarball> ...
    }
    hello() {
      g++ -I$CITY_SRC -I$CITY_SRC/src -o hello $CITY_SRC/src/city.cc hello.cc
     ./hello "$@"
    }
    "$@"


    hello.cc:

    #include <cstdio>
    #include <string.h>  // strlen

    #include "city.h"

    int main(int argc, char** argv) {
      if (argc >= 2) {
        char* s = argv[1];
        unsigned u = CityHash32(s, strlen(s));
        printf("hash = %x\n", u);
        return 3;
      }
    }
Then I just check those two files into ~/git/scratch/cityhash. Then I can reproduce it on any computer with a couple short commands.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: