Pike code samples by rjb
Not much here yet -- hopefully it will grow with time.
These are just silly scripts which may or may not be useful as illustration
of Pike coding, but not much use for anything else. If and when I start
to believe this has changed, I'll be sure to mention it right here ;-)
Pike 7.2 is required to run these scripts.
You are of course free to try
to tweak them for older versions if you wish, it shouldn't be hard.
Some may even work without any tweaking (not tested). Pike 7.3
should be OK too, but currently can be had only from RIS
Update: Pike 7.4 has now been released
for a while, and there's a new official home for
the Pike language. I will be updating this stuff for Pike 7.4 shortly.
Currently all the scripts work with Pike 7.4 anyway, with barely a few
compile warnings between all of them, but do not demonstrate the newer features.
All this stuff is in the public domain unless boldly
stated otherwise in the individual descriptions. No warranty, etc.
a script to hunt down dangling
symlinks in a directory tree. Stolen from a sample in the Python
now, this is silly, it goes through
passwd records on your Unix box (by calling
getpwent()) and computes statistics of your users' first names.
A legit first name is defined as a leading piece of the gecos field
(before the first space) that begins with a capital letter (
Otherwise, no serious attempt is made to filter out system accounts ;-)
uses GTK to put a stopwatch on your desktop.
Basically the simplest Pike-GTK thingy I could think of that actually does
something (marginally) useful. Has only one-second resolution (because
that's what the GTK Clock widget supports), but I'll improve on that when
I feel inspired.
a sample usage of Pike's
CommonLog module. Does nothing too smart other than
outputting a crude table of the frequencies of HTTP reply codes from
your access logfile, which must be in the "common log" format (as
used by default by Apache, Roxen, etc.).
prints a summary of the stuff in your local unix mailbox
(assuming standard mbox format), or optionally, in a file
of the same format given as a command-line argument, or even from
standard input. Output is a list of "From:" addresses and
subjects, with each item truncated to fit within the width of your
current terminal. Note that it should adapt correctly to whatever
width you currently have.
Mbox_iterator class that is designed for
reuse in more sophisticated settings (though it's not really
Could perhaps use some more error checking.
the script that generates the syntax-colorized versions of these
sample programs, i.e. those behind the html links in this
list. Could also be used to colorize C source. A nice demo of the
tokenization capabilities of Pike's
fetches and writes a "cookie" (as in fortune-cookie, not HTTP-cookie) that
with every response as the content of a X-Fry: (or X-Bender:, etc.) custom
HTTP header, by making a HEAD request for the site's top page.
a near-clone of the unix
cal(1) command, and an attempt to
utilize the strong type-checking implemented in newer versions of Pike
(works with 7.2, but it's quite a chore to suppress all type-related
warnings from the 7.4 compiler).
Does not make use of Pike's sophisticated
module, which takes a while to load and thus does not perform very well
for a quick one-shot command. Therefore, it's quite simple-minded: no
support for B.C. years, locale, or the Julian/Gregorian transition.
the classic recursive computation of the n'th Fibonacci number, with caching
("memoizing") of intermediate results. On my vintage 350 MHz Pentium II workstation,
the 10451 decimal digits for n=50000 are computed and displayed in slightly
over 4 seconds of wall-clock time. The caching is implemented by creating an
object that sort of simulates a closure -- which isn't really needed or useful here,
but hey, it's a demo.
The kludge involving the variable
steps is a workaround for a
C-stack overflow due to excessive recursion depth. Works For Me (TM), but YMMV.
The memoizing speeds up the computation by a factor of about 100 (!) compared
with a naive version of the same algorithm, of course at the expense of some memory use.
Accessed: by since .
Robert J. Budzynski