Browse Source

stub out programs/ - scripting chapter

pull/1/head
Brennen Bearnes 7 years ago
parent
commit
d33035abca
9 changed files with 136 additions and 80 deletions
  1. +1
    -1
      build.sh
  2. +2
    -2
      diff/index.md
  3. +75
    -49
      index.html
  4. +3
    -3
      literary_environment/index.md
  5. +9
    -21
      literary_problem/index.md
  6. +4
    -2
      programmerthink/index.md
  7. +39
    -0
      programs/index.md
  8. +1
    -1
      render.pl
  9. +2
    -1
      userland.css

+ 1
- 1
build.sh View File

@ -2,4 +2,4 @@
# yes this should be a Makefile shouldn't it
perl ./render.pl ./index.md ./literary_environment/index.md ./literary_problem/index.md ./programmerthink/index.md ./diff/index.md ./further_reading/index.md ./links.md | cat header.html - footer.html > index.html
perl ./render.pl ./index.md ./literary_environment/index.md ./literary_problem/index.md ./programmerthink/index.md ./diff/index.md ./programs/index.md ./further_reading/index.md ./links.md | cat header.html - footer.html > index.html

+ 2
- 2
diff/index.md View File

@ -1,5 +1,5 @@
diff, wdiff, git
----------------
4. diff, wdiff, git
===================
If you're the sort of person who took a few detours into the history of
religion in college, you might be familiar with some of the ways people used to


+ 75
- 49
index.html View File

@ -38,7 +38,7 @@ me immeasurably in my own work.</p>
<li><a href="#license">license</a></li>
</ul>
</li>
<li><a href="#the-command-line-as-a-literary-environment">the command line as a literary environment</a>
<li><a href="#the-command-line-as-a-literary-environment">1. the command line as a literary environment</a>
<ul>
<li><a href="#terms-and-definitions">terms and definitions</a></li>
@ -56,13 +56,10 @@ me immeasurably in my own work.</p>
<li><a href="#now-you-have-n-problems-regex-amp-rabbit-holes">now you have n problems: regex &amp; rabbit holes</a></li>
</ul>
</li>
<li><a href="#a-literary-problem">a literary problem</a></li>
<li><a href="#programmerthink">programmerthink</a>
<ul>
<li><a href="#diff-wdiff-git">diff, wdiff, git</a></li>
</ul>
</li>
<li><a href="#a-literary-problem">2. a literary problem</a></li>
<li><a href="#programmerthink">3. programmerthink</a></li>
<li><a href="#diff-wdiff-git">4. diff, wdiff, git</a></li>
<li><a href="#programs-amp-programmering">programs &amp; programmering</a></li>
<li><a href="#further-reading">further reading</a>
<ul>
@ -80,7 +77,7 @@ time being please feel free to use it under the terms of Creative Commons BY-SA
(Attribution / Share-Alike), whatever the latest version is. I promise I will
not license it under more restrictive terms than that.</p>
<h1><a name=the-command-line-as-a-literary-environment href=#the-command-line-as-a-literary-environment>#</a> the command line as a literary environment</h1>
<h1><a name=the-command-line-as-a-literary-environment href=#the-command-line-as-a-literary-environment>#</a> 1. the command line as a literary environment</h1>
<p>There&rsquo;re a lot of ways I could try to structure an introduction to the command
line. I&rsquo;m going to start with writing as a point of departure because, aside
@ -528,8 +525,11 @@ qsort (3) - sort an array
qsort_r (3) - sort an array
radixsort (3) - radix sort
sort (1) - sort lines of text files
sq (1) - squeeze or unsqueeze a sorted word list
sradixsort (3) - radix sort
texindex (1) - sort Texinfo index files
tsort (1) - perform topological sort
unsq (1) - squeeze or unsqueeze a sorted word list
versionsort (3) - scan a directory for matching entries
XConsortium (7) - X Consortium information
</code></pre>
@ -866,7 +866,7 @@ by <code>grep</code>, other magical things include:</p>
<tr><td><code>*</code> </td> <td>any number of the preceding thing </td></tr>
<tr><td><code>(foo|bar)</code></td> <td>"foo" or "bar"</td></tr>
<tr><td><code>(foo)?</code></td> <td>optional "foo"</td></tr>
<tr><td><code>(foo)?</code></td> <td>optional "foo"</td></tr>
</table>
@ -911,7 +911,7 @@ shell to match groups of files, but with more magic.
by `grep`, other magical things include:
use a lot of the magical characters, you have to prefix them with `\`. This is
Lines in this file matching the words "magic" or "magical":
<b>$ grep -iE 'magic(al)?' ./index.md</b>
$ grep -iE 'magic(al)?' ./index.md
</code></pre>
<p>Find some &ldquo;-agic&rdquo; words in a big list of words:</p>
@ -959,7 +959,7 @@ masquerading as wisdom.</p>
that we&rsquo;ve established, however haphazardly, some of the basics, let&rsquo;s consider
their application to a real-world task.</p>
<h1><a name=a-literary-problem href=#a-literary-problem>#</a> a literary problem</h1>
<h1><a name=a-literary-problem href=#a-literary-problem>#</a> 2. a literary problem</h1>
<p>The <a href="../literary_environment">previous chapter</a> introduced a bunch of tools
using contrived examples. Now we&rsquo;ll look at a real problem, and work through a
@ -1075,32 +1075,20 @@ called <code>possible_poems</code> in my home directory:</p>
<p>This is quite a few instances&hellip;</p>
<!-- exec -->
<pre><code><b>$ wc -l ~/possible_poems</b>
682 /home/brennen/possible_poems
679 /home/brennen/possible_poems
</code></pre>
<!-- end -->
<p>&hellip;and it&rsquo;s also not super-pretty to look at:</p>
<!-- exec -->
<pre><code><b>$ head -5 ~/possible_poems</b>
/home/brennen/p1k3/archives/2002/10/16:&lt;freeverse&gt;i don't have time to be writing this
/home/brennen/p1k3/archives/2002/10/27:&lt;freeverse&gt;tequila tastes like death
/home/brennen/p1k3/archives/2002/10/10:&lt;freeverse&gt;
/home/brennen/p1k3/archives/2002/10/shax:&lt;freeverse&gt;i'd do this in iambic pentameter
/home/brennen/p1k3/archives/2002/10/31/index:&lt;freeverse&gt;rounding out the month,
/home/brennen/p1k3/archives/2011/10/14:&lt;freeverse&gt;i've got this friend has a real knack
/home/brennen/p1k3/archives/2011/4/25:&lt;freeverse&gt;i can't claim to strive for it
/home/brennen/p1k3/archives/2011/8/10:&lt;freeverse&gt;one diminishes or becomes greater
/home/brennen/p1k3/archives/2011/8/12:&lt;freeverse&gt;
/home/brennen/p1k3/archives/2011/1/1:&lt;freeverse&gt;six years on
</code></pre>
<!-- end -->
<p>Still, it&rsquo;s a decent start. I can see paths to the files I have to check, and
usually a first line. Since I use a fancy text editor, I can just go down the
list opening each file in a new window and copying the stuff I&rsquo;m interested in
@ -1133,19 +1121,13 @@ something like:</p>
<em>different</em>, more specific command. And it appears to have worked on the
first try:</p>
<!-- exec -->
<pre><code><b>$ wc ~/possible_poems_full</b>
16190 74988 486847 /home/brennen/possible_poems_full
17628 80980 528699 /home/brennen/possible_poems_full
</code></pre>
<!-- end -->
<p>Welcome to wizard school.</p>
<h1><a name=programmerthink href=#programmerthink>#</a> programmerthink</h1>
<h1><a name=programmerthink href=#programmerthink>#</a> 3. programmerthink</h1>
<p>In the <a href="../literary_problem">preceding chapter</a>, I worked through accumulating
a big piece of text from some other, smaller texts. I started with a bunch of
@ -1271,18 +1253,18 @@ I&rsquo;ve written in blog posts so far in 2014:</p>
<pre><code><b>$ find ~/p1k3/archives/2012/ -type f | xargs perl -ne 'print "$1\n" if m{&lt;h2&gt;(.*?)&lt;/h2&gt;}'</b>
pursuit
A miracle, in fact, means work
&lt;em&gt;technical notes for late october&lt;/em&gt;, or &lt;em&gt;it gets dork out earlier these days&lt;/em&gt;
more observations on gear nerdery &amp;amp; utility fetishism
timebinding animals
fragment
this poem again
i'll do better next time
timebinding animals
more observations on gear nerdery &amp;amp; utility fetishism
pursuit
thrift
A miracle, in fact, means work
&lt;em&gt;technical notes for late october&lt;/em&gt;, or &lt;em&gt;it gets dork out earlier these days&lt;/em&gt;
radio
i'll do better next time
light enough to travel
12:06am
radio
"figures like Heinlein and Gingrich"
</code></pre>
@ -1394,7 +1376,7 @@ writing a sprawl, pages, of melancholic midlife bullshit
outside the snow gives way to broken clouds and the
clear unyielding light of the high country sun fills
<b>$ cat ~/p1k3/archives/2013/2/9/Meta</b>
$ cat ~/p1k3/archives/2013/2/9/Meta
collection: ok-poems
</code></pre>
@ -1407,7 +1389,7 @@ altogether?</p>
<pre><code><b>$ ls ~/p1k3/archives/2013/2/9</b>
index meta-ok-poem
<b>$ find ~/p1k3/archives -name 'meta-ok-poem'</b>
$ find ~/p1k3/archives -name 'meta-ok-poem'
/home/brennen/archives/2013/2/9/meta-ok-poem
</code></pre>
@ -1424,9 +1406,11 @@ overall. There&rsquo;s a cost to doing things this way. It lets me extend my
existing model of a blog entry to include arbitrary metadata, but it also adds
steps to writing or finding blog entries.</p>
<p>Abstractions usually cost you something. Is this one worth the hassle?</p>
<p>Abstractions usually cost you something. Is this one worth the hassle?
Sometimes the best way to answer that question is to start writing code that
handles a given abstraction.</p>
<h2><a name=diff-wdiff-git href=#diff-wdiff-git>#</a> diff, wdiff, git</h2>
<h1><a name=diff-wdiff-git href=#diff-wdiff-git>#</a> 4. diff, wdiff, git</h1>
<p>If you&rsquo;re the sort of person who took a few detours into the history of
religion in college, you might be familiar with some of the ways people used to
@ -1463,6 +1447,48 @@ out that these work just about as well for English text as they do for code.</p>
<p>{demo various diff tools, source control}</p>
<h1><a name=programs-amp-programmering href=#programs-amp-programmering>#</a> programs &amp; programmering</h1>
<p>A bit ago, I said that &ldquo;the way you use the computer is often just to write
little programs that invoke other programs&rdquo;. In fact, we&rsquo;ve already gone over a
bunch of these. Grepping through the text of a previous chapter should pull
up some good examples:</p>
<!-- exec -->
<pre><code><b>$ grep -E '[a-z]+.*\| ' ../literary_environment/index.md</b>
$ sort -k2 authors_* | uniq
$ sort colors | uniq -i -c
$ sort authors_* | uniq &gt; all_authors
$ find ~/p1k3/archives/2010/11 -regextype egrep -regex '.*([0-9]+|index)' -type f | xargs wc -w | grep total
$ sort authors_* | uniq | wc -l
$ dict concatenate | head -10
$ sort colors | uniq -i | tail -1
$ cut -d' ' -f1 ./authors_* | sort | uniq -ci | sort -n | tail -3
$ sort -u ./authors_* | cut -d' ' -f1 | uniq -ci | sort -n | tail -3
$ cat ./authors_* | grep 'Vanessa'
</code></pre>
<!-- end -->
<p>None of these do all that much, but they all take input of one sort or another
and transform it into something new by doing a series of things to it. They&rsquo;re
little formal sentences describing how to make one thing into another, which is
as good a definition of programming as most. (Though it&rsquo;s true that a lot of
the programs we use day-to-day are more like essays or novels or interminable
Fantasy series where every character you like dies horribly than they are like
individual sentences.)</p>
<p>This kind of thing is all well and good when you&rsquo;re staring a terminal, trying
to figure something out - but what about when you&rsquo;ve figured something out
and you want to repeat it in the future without remembering and typing a giant
string of weird characters all over again?</p>
<p>It turns out that Bash has you covered. Since shell commands are just text,
they can live in a file as easily as they can be typed.</p>
<h1><a name=further-reading href=#further-reading>#</a> further reading</h1>
<p><em>The Unix Programming Environment</em> - Brian W. Kernighan, Rob Pike</p>


+ 3
- 3
literary_environment/index.md View File

@ -1,5 +1,5 @@
the command line as a literary environment
==========================================
1. the command line as a literary environment
=============================================
There're a lot of ways I could try to structure an introduction to the command
line. I'm going to start with writing as a point of departure because, aside
@ -718,7 +718,7 @@ by `grep`, other magical things include:
<tr><td><code>*</code> </td> <td>any number of the preceding thing </td></tr>
<tr><td><code>(foo|bar)</code></td> <td>"foo" or "bar"</td></tr>
<tr><td><code>(foo)?</code></td> <td>optional "foo"</td></tr>
<tr><td><code>(foo)?</code></td> <td>optional "foo"</td></tr>
</table>
It's actually a little more complicated than that: By default, if you want to


+ 9
- 21
literary_problem/index.md View File

@ -1,5 +1,5 @@
a literary problem
==================
2. a literary problem
=====================
The [previous chapter](../literary_environment) introduced a bunch of tools
using contrived examples. Now we'll look at a real problem, and work through a
@ -103,25 +103,17 @@ called `possible_poems` in my home directory:
This is quite a few instances...
<!-- exec -->
$ wc -l ~/possible_poems
682 /home/brennen/possible_poems
<!-- end -->
679 /home/brennen/possible_poems
...and it's also not super-pretty to look at:
<!-- exec -->
$ head -5 ~/possible_poems
/home/brennen/p1k3/archives/2002/10/16:<freeverse>i don't have time to be writing this
/home/brennen/p1k3/archives/2002/10/27:<freeverse>tequila tastes like death
/home/brennen/p1k3/archives/2002/10/10:<freeverse>
/home/brennen/p1k3/archives/2002/10/shax:<freeverse>i'd do this in iambic pentameter
/home/brennen/p1k3/archives/2002/10/31/index:<freeverse>rounding out the month,
<!-- end -->
/home/brennen/p1k3/archives/2011/10/14:<freeverse>i've got this friend has a real knack
/home/brennen/p1k3/archives/2011/4/25:<freeverse>i can't claim to strive for it
/home/brennen/p1k3/archives/2011/8/10:<freeverse>one diminishes or becomes greater
/home/brennen/p1k3/archives/2011/8/12:<freeverse>
/home/brennen/p1k3/archives/2011/1/1:<freeverse>six years on
Still, it's a decent start. I can see paths to the files I have to check, and
usually a first line. Since I use a fancy text editor, I can just go down the
@ -152,11 +144,7 @@ Did you catch that? I just wrote a command that rewrote itself as a
_different_, more specific command. And it appears to have worked on the
first try:
<!-- exec -->
$ wc ~/possible_poems_full
16190 74988 486847 /home/brennen/possible_poems_full
<!-- end -->
17628 80980 528699 /home/brennen/possible_poems_full
Welcome to wizard school.

+ 4
- 2
programmerthink/index.md View File

@ -1,5 +1,5 @@
programmerthink
===============
3. programmerthink
==================
In the [preceding chapter](../literary_problem), I worked through accumulating
a big piece of text from some other, smaller texts. I started with a bunch of
@ -260,3 +260,5 @@ existing model of a blog entry to include arbitrary metadata, but it also adds
steps to writing or finding blog entries.
Abstractions usually cost you something. Is this one worth the hassle?
Sometimes the best way to answer that question is to start writing code that
handles a given abstraction.

+ 39
- 0
programs/index.md View File

@ -0,0 +1,39 @@
programs & programmering
========================
A bit ago, I said that "the way you use the computer is often just to write
little programs that invoke other programs". In fact, we've already gone over a
bunch of these. Grepping through the text of a previous chapter should pull
up some good examples:
<!-- exec -->
$ grep -E '[a-z]+.*\| ' ../literary_environment/index.md
$ sort -k2 authors_* | uniq
$ sort colors | uniq -i -c
$ sort authors_* | uniq > all_authors
$ find ~/p1k3/archives/2010/11 -regextype egrep -regex '.*([0-9]+|index)' -type f | xargs wc -w | grep total
$ sort authors_* | uniq | wc -l
$ dict concatenate | head -10
$ sort colors | uniq -i | tail -1
$ cut -d' ' -f1 ./authors_* | sort | uniq -ci | sort -n | tail -3
$ sort -u ./authors_* | cut -d' ' -f1 | uniq -ci | sort -n | tail -3
$ cat ./authors_* | grep 'Vanessa'
<!-- end -->
None of these do all that much, but they all take input of one sort or another
and transform it into something new by doing a series of things to it. They're
little formal sentences describing how to make one thing into another, which is
as good a definition of programming as most. (Though it's true that a lot of
the programs we use day-to-day are more like essays or novels or interminable
Fantasy series where every character you like dies horribly than they are like
individual sentences.)
This kind of thing is all well and good when you're staring a terminal, trying
to figure something out - but what about when you've figured something out
and you want to repeat it in the future without remembering and typing a giant
string of weird characters all over again?
It turns out that Bash has you covered. Since shell commands are just text,
they can live in a file as easily as they can be typed.

+ 1
- 1
render.pl View File

@ -59,7 +59,7 @@ sub handle_block {
sub replace_some_stuff {
my ($markup) = @_;
$markup =~ s{(\$ .*?)$}{<b>$1</b>}gm;
$markup =~ s{<code>(\$ .*?)$}{<code><b>$1</b>}gm;
my @contents;


+ 2
- 1
userland.css View File

@ -7,10 +7,10 @@ body {
margin-top: 0em;
padding-left: 1em;
padding-right: 1em;
max-width: 48em;
}
p, ul li, ol li, ul {
max-width: 48em;
}
td { vertical-align: top; }
@ -36,6 +36,7 @@ pre {
margin-left: 2em;
max-width: 56em;
padding: 1em;
white-space: pre-wrap;
}
.sidenote {


Loading…
Cancel
Save