Programming Sans Internet

The Internet is down
The Internet is down

Software development is tightly coupled to the Internet. Some programs refuse to run or fail catastrophically without an Internet connection. For most people a computer becomes a useless pile of metal without the Internet. My circumstances have required the dreaded skill of programming without the Internet. The This post was completed just before the power company tripped over itself. and Here’s to hoping that the Starlink project becomes successful and affordable. infrastructure in my country royally sucks.

Keeping in a state of “flow” when the Internet goes down is difficult. Let’s take a look at my basic approach to remedying the difficulty of programming without an Internet connection.

Offline The Documentation

Many kind people exist in this world. Some of them write manuals that no one reads. Linux based distributions have first class support for POSIX style programming. One could run man to bring up any function or program instruction in the POSIX programmer’s manual. If we wanted to know how to use mmap we could run man mmap.

Manpage for mmap
Manpage for mmap

Manpages are so old school now that it’s somewhat rare to see anyone using man let alone Create manpages with the troff and groff typsetting family of programs. localized manuals.

“Knowledge is of two kinds. We know a subject ourselves, or we know where we can find information upon it. When we enquire into any subject, the first thing we have to do is to know what books have treated of it. This leads us to look at catalogues, and at the backs of books in libraries.” Samuel Johnson, The Life of Samuel Johnson

Manpages are faster than a search engine lookup if you know what you are looking for. Search engine lookups can be expensive Multitasking. Every context switch has a mental cost. switching actions, but you often get what you’re looking for quickly. Good manuals contain a synopsis of a program or function, an example of its usage pattern, return value references, and most important of them all — error handling instructions.

Ensure that you have manpages for all tools and target languages that you work with if available. Check your local distribution repositories to see if there are any extra manuals available. Run man -k . to see On NixOS 20.03 man is broken. You’ll need to wire up mandb or wait until release 20.09. manuals on the system. Display manuals containing a keyword with man -k <keyword>. PDF version of mmap’s manpage PDF version of mmap’s manpage manuals to PDF format by using man -Tpdf <keyword>. Pipe the output into the PDF reader of choice.

shell
man -Tpdf mmap | zathura -

Zeal offers an offline graphical documentation browser for many popular programming APIs (Application Programming Interfaces). Install zeal and download the documentation sets that are relevant to your programming environment.

Zeal documentation browser interface
Zeal browser showing JavaScript’s Math.floor() function documentation.

Offline The Wiki

The Arch Wiki is a well known and respected documentation source. If you find a wiki that you visit more than once — offline it. Relegate any downloaded wiki to a directory where you can grep (global regular expression print) or search through the files.

This applies doubly so for any GitHub wiki. Extract markdown copies of a repository’s wiki by using the git clone command.

shell
git clone https://github.com/koalaman/shellcheck.wiki.git

GitHub’s pull requests and issues contain critical information. Grab all pull requests and issues from any working There should be an offline copy of any repository you work with. using the Github API (Application Programming Interface).

text
https://api.github.com/repos/<repo-owner>/<repo-name>/issues?state=all
https://api.github.com/repos/<repo-owner>/<repo-name>/pulls?state=all

Offline The REPLs

REPL stands for read, evaluate, print, and loop. It’s a command line shell for your language. Get comfortable using a REPL just like any other familiar shell to reduce Internet lookups and context switching. Most of us use our heads as rudimentary REPLs — basically, we write a piece of code with a general imagination of its action and return state.

Eventually there’s a point where you’re doing that weird JavaScript style crash and burn programming. The target code is now large enough that it can’t fit inside your head, so you’ll edit what you approximate is wrong, and run it again to see if it doesn’t crash and burn. Repeat ad nauseam.

Unpacking a tricky error state is often much quicker in a REPL than with an Internet search or using a crude crash and burn method. This saves time and having to context switch to a search lookup for some common or obscure error message. Make sure to have all REPLs offline for any language or tool you use if available.

Elixir's REPL
Messing around with Elixir’s REPL iex in Vim

Offline The Static Code Analysis

Static code analysis offers refactoring advice, sniffing out high level coding errors, and correcting naive approaches to simple problems. Static code analysis tools can hold your hand and carry you a good distance. In fact, there are some static analysis tools that are so Haskell’s ghc and hlint as well as Unix Shell’s shellcheck. that if you have good cursory knowledge of a language, you can learn the ins and outs quicker than reading a book.

The authors of static code analysis tools know more than you — it’s as simple as that. Static analysis coalesces a collection of common questions, answers, and pitfalls that experienced people have encountered time and time again. Even How many of us are familiar with vulnerabilities such as HTTP request and response splitting? based programs like Nginx have their own static analysis tools like gixy. Ensure you have all static analysis tools for any language or program that you work with offline.

Offline The Editor

Most programmers use integrated development environments (IDE) nowadays which handles most of the above (with or without Internet probably), but in a situation without an Internet connection — having a flexible editor is paramount.

This means an editor like vim or emacs. In the wastelands, you don’t have the luxury of downloading a plugin or extra feature to assist you. Flexible editors have configuration that is dynamic enough to code your own plugins trivially on the fly.

Emacs uses Emacs Lisp, and Vim uses Vimscript. Vim itself has one of the most thorough manuals in existence, so implementing an ad hoc plugin for an odd workflow is not too difficult as long as you know how to read.

Offline NixOS Documentation

Bonus section for NixOS users. NixOS offline documentation is impeccable. You can run the command line tool man on configuration.nix, nix.conf, nixos-rebuild and more. The Documentation lookups have yet to be implemented. is the nix REPL. The nix REPL doesn’t have the ability to lookup function documentation strings. A function’s documentation requires a search of the source code, and that’s not fun. The plugin nix-doc adds this feature to the nix REPL. Let’s wire it up while we wait on upstream. Create a basic default.nix for nix-doc using rustPlatform.

nix
{ lib, rustPlatform, fetchgit, pkgs }:

rustPlatform.buildRustPackage rec {
  pname = "nix-doc";
  version = "v0.3.1";

  src = fetchgit {
    rev = version;
    url = "https://github.com/lf-/nix-doc.git";
    sha256 = "1hiz0fsbsl74m585llg2n359gs8i2m6jh8zdikkwxd8xq7qmw032";
  };

  buildInputs = with pkgs; [ boost nix ];

  nativeBuildInputs = with pkgs; [ pkg-config ];

  cargoSha256 = "1d1gvx14yai4dyz44pp2ffx2swfxnm0fwvldy96dw9gqmar69cpv";

  meta = with lib; {
    homepage = url;
    license = licenses.lgpl3;
    description = "A Nix documentation lookup tool that quickly dumps the docs of the library function";
  };
}

Install the program using environment.systemPackages and its plugin using nix.extraOptions where ./nix-doc/default.nix is the path to the derivation.

nix
{ pkgs, ... }:

{
  nix.extraOptions = ''
    plugin-files = ${pkgs.callPackage ./nix-doc/default.nix {}}/lib/libnix_doc_plugin.so
  '';

  environment.systemPackages = with pkgs; [
    (callPackage ./nix-doc/default.nix {})
  ];
}

The nix REPL now has access to the documentation lookup function builtins.doc and the command line utility nix-doc.

30 July 2020 — Written
10 March 2022 — Updated
Thedro Neely — Creator
programming-sans-internet.md — Article

More Content

Openring

Web Ring

Comments

References

  1. https://thedroneely.com/git/
  2. https://thedroneely.com/
  3. https://thedroneely.com/posts/
  4. https://thedroneely.com/projects/
  5. https://thedroneely.com/about/
  6. https://thedroneely.com/contact/
  7. https://thedroneely.com/abstracts/
  8. https://ko-fi.com/thedroneely
  9. https://thedroneely.com/tags/general/
  10. https://thedroneely.com/posts/programming-sans-internet/#isso-thread
  11. https://thedroneely.com/posts/rss.xml
  12. https://thedroneely.com/images/programming-sans-internet.png
  13. https://en.wikipedia.org/wiki/Starlink
  14. https://thedroneely.com/posts/programming-sans-internet/#offline-the-documentation
  15. https://thedroneely.com/images/mmap-manpage.png
  16. https://linux.die.net/man/1/troff
  17. https://linux.die.net/man/1/groff
  18. https://nixos.org/
  19. https://github.com/NixOS/nixpkgs/pull/86489
  20. https://thedroneely.com/images/mmap-pdf-manpage.png
  21. https://thedroneely.com/posts/programming-sans-internet/#code-block-43252bd
  22. https://zealdocs.org/
  23. https://en.wikipedia.org/wiki/API
  24. https://thedroneely.com/images/programming-sans-internet-zeal.png
  25. https://thedroneely.com/posts/programming-sans-internet/#offline-the-wiki
  26. https://wiki.archlinux.org/
  27. https://www.archlinux.org/packages/community/any/arch-wiki-docs/
  28. https://github.com/
  29. https://thedroneely.com/posts/programming-sans-internet/#code-block-a292cb6
  30. https://thedroneely.com/posts/programming-sans-internet/#code-block-b292b90
  31. https://thedroneely.com/posts/programming-sans-internet/#offline-the-repls
  32. https://thedroneely.com/images/iex-repl.gif
  33. https://thedroneely.com/posts/programming-sans-internet/#offline-the-static-code-analysis
  34. https://nginx.org/en/docs/contributing_changes.html
  35. https://github.com/yandex/gixy
  36. https://thedroneely.com/posts/programming-sans-internet/#offline-the-editor
  37. https://thedroneely.com/posts/programming-sans-internet/#offline-nixos-documentation
  38. https://github.com/NixOS/nix/pull/1652
  39. https://github.com/lf-/nix-doc
  40. https://github.com/NixOS/nixpkgs/pull/95161
  41. https://thedroneely.com/posts/programming-sans-internet/#code-block-624328d
  42. https://thedroneely.com/posts/programming-sans-internet/#code-block-f29e254
  43. https://www.thedroneely.com/posts/programming-sans-internet.md
  44. https://thedroneely.com/posts/running-nixos-linux-containers/
  45. https://thedroneely.com/posts/finding-that-one-percent/
  46. https://thedroneely.com/posts/nixos-in-the-wild/
  47. https://git.sr.ht/~sircmpwn/openring
  48. https://drewdevault.com/2022/11/12/In-praise-of-Plan-9.html
  49. https://drewdevault.com/
  50. https://mxb.dev/blog/the-indieweb-for-everyone/
  51. https://mxb.dev/
  52. https://www.taniarascia.com/simplifying-drag-and-drop/
  53. https://www.taniarascia.com/
  54. https://thedroneely.com/posts/programming-sans-internet#isso-thread
  55. https://thedroneely.com/posts/programming-sans-internet#offline-the-documentation
  56. https://thedroneely.com/posts/programming-sans-internet#code-block-43252bd
  57. https://thedroneely.com/posts/programming-sans-internet#offline-the-wiki
  58. https://thedroneely.com/posts/programming-sans-internet#code-block-a292cb6
  59. https://thedroneely.com/posts/programming-sans-internet#code-block-b292b90
  60. https://thedroneely.com/posts/programming-sans-internet#offline-the-repls
  61. https://thedroneely.com/posts/programming-sans-internet#offline-the-static-code-analysis
  62. https://thedroneely.com/posts/programming-sans-internet#offline-the-editor
  63. https://thedroneely.com/posts/programming-sans-internet#offline-nixos-documentation
  64. https://thedroneely.com/posts/programming-sans-internet#code-block-624328d
  65. https://thedroneely.com/posts/programming-sans-internet#code-block-f29e254
  66. https://thedroneely.com/posts/variable-dump-to-error-log/
  67. https://thedroneely.com/posts/good-evil-and-the-law/
  68. https://thedroneely.com/posts/nixos-pins-and-needles/
  69. https://thedroneely.com/projects/news-aggregator/
  70. https://thedroneely.com/posts/writing-strategy/
  71. https://drewdevault.com/2022/09/16/Open-source-matters.html
  72. https://mxb.dev/blog/make-free-stuff/
  73. https://thedroneely.com/sitemap.xml
  74. https://thedroneely.com/index.json
  75. https://thedroneely.com/resume/
  76. https://gitlab.com/tdro
  77. https://github.com/tdro
  78. https://codeberg.org/tdro
  79. https://thedroneely.com/analytics
  80. https://thedroneely.com/posts/programming-sans-internet#
  81. https://creativecommons.org/licenses/by-sa/2.0/
  82. https://thedroneely.com/git/thedroneely/thedroneely.com
  83. https://opensource.org/licenses/GPL-3.0
  84. https://www.thedroneely.com/
  85. https://thedroneely.com/posts/programming-sans-internet/#