General Ideas

I have some general ideas about useful hobby-type applications of computers; in this case FreeBSD, but they could be applied to any system.

Bookbinding; texlive, mupdf, perl/python/shell scripts, etc can be used to automate book signatures from archive.org, books.google.com pdf books. These can be used with cotton-rag paper to assemble handmade books.

Inkjet printers can be used to print out giclee paintings/photographs on canvas, etc. They also can print on wax paper, which is then used to create painted style signs on wood, metal, etc [with a heatgun/hair-dryer].

Make a script that reads through a folder tree and prints out the contents of text files to the terminal.
Now login to the system from an ssh app on a tablet in the kitchen. Recipes on demand.

{I just learned perl, pardon me if it looks rather amature}
Perl:
#!/usr/local/bin/perl -w
#Uses the Switch module [switch statements are not built into perl before v6 (v6 also uses different syntax)]
#Uses the Scalar::Util module.

use Switch;
use Scalar::Util qw(looks_like_number);

$DIR_var = "/home/myname/Documents/Recipes/";
$Acrobat = "okular"; #Uses the okular pdf viewer, change if need be.

@list_array = &list_dir($DIR_var,$arraySize);

print "Directory Number ('q' to exit,'r' to relist): ";
$key = <STDIN>;
chomp $key;

if (looks_like_number($key)){
    if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; }
}elsif(($key eq 'r') != 1){exit();}

$depth = 0;

#If $key is a number greater than 0 OR If $key is not a number and is either 'r' or 'u' keep looping.
while(looks_like_number($key) ? $key>0:($key eq 'r' || $key eq 'u')){
    switch($depth){
        case 0    {
                if($key eq 'r'){#relisting the top directory

                    undef @list_array;
                    @list_array = &list_dir($DIR_var,$arraySize);

                    print "Directory Number ('q' to exit,'r' to relist): ";
                    $key = <STDIN>;
                    chomp $key;
                    if (looks_like_number($key)){
                        if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; }
                    }elsif($key eq 'u'){exit();} #We only want it to loop with an 'r' if not a number here.
                }else{#changes into sub directory
                    $NewDir = $list_array[$key];

                    undef @list_array;
                    @list_array = &list_dir("$DIR_var$NewDir/",$arraySize);

                    $depth++;
                    print "Recipe Number ('q' to exit,'r' to relist,'u' to go up one directory): ";
                    $key = <STDIN>;
                    chomp $key;
                    if (looks_like_number($key)){
                        if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; }
                    }                              
                }
            }

        case 1    {
                if($key eq 'r'){#relisting sub directory

                    undef @list_array;
                    @list_array = &list_dir("$DIR_var$NewDir/",$arraySize);

                    print "Recipe Number ('q' to exit,'r' to relist,'u' to go up one directory): ";
                    $key = <STDIN>;
                    chomp $key;
                    if (looks_like_number($key)){
                        if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; }
                    }
                }elsif($key eq 'u'){#changes into the top directory

                    undef @list_array;
                    @list_array = &list_dir($DIR_var,$arraySize);

                    $depth--;
                    print "Directory Number ('q' to exit,'r' to relist): ";
                    $key = <STDIN>;
                    chomp $key;
                    if (looks_like_number($key)){
                        if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; $depth++; }
                    }elsif($key eq 'u'){exit();}#We only want it to loop with an 'r' if not a number here.
                }elsif (looks_like_number($key)){#print contents of the file
                    print "==============================================\n";
                    print " $list_array[$key]\n";
                    print "==============================================\n";
                    if(index ($list_array[$key], '.pdf') != -1){
                        system("\"$Acrobat\" \"$list_array[$key]\"");
                    }else{
                        system("cat \"$list_array[$key]\"");
                        print "==============================================\n";          
                    }
                    print "Recipe Number ('q' to exit,'r' to relist,'u' to go up one directory): ";
                    $key = <STDIN>;
                    chomp $key;
                    if (looks_like_number($key)){
                        if ($key >= $arraySize){ print "Index Out of Bounds\n-------------------\n"; $key = 'r'; }
                    }
                }
               
        }
    }
}

sub list_dir{#Takes in the directory path and arraySize, prints the directory, returns an array of strings of the contents of the directory.
#returns the arraySize by reference
    chdir( $_[0] ) or die "Couldn't go inside $_[0] directory, $!";
    opendir (DIR, '.') or die "Couldn't open directory, $!";
    $_[1] = 1;
   
    my @files = sort { lc($a) cmp lc ($b) } readdir(DIR); #Sort alpha order [conv to lc first].
    while ( my $file = shift @files) { #cycle through the array
       if(index ($file, '.') == -1 || index ($file, '.pdf') != -1){#There is no period in the filename [no file extension] or the filename includes a .pdf
           if ($_[1] < 10){
               print "   $_[1] $file\n";
           }elsif($_[1] < 100){
            print "  $_[1] $file\n";
           }elsif($_[1] < 1000){
            print " $_[1] $file\n";
           }else{
            print "$_[1] $file\n";
              }
        $array[$_[1]] = $file;
           $_[1]++;
       }
    }
    closedir DIR;
    return @array;
}
 
This is why it feels a bit sad when you meet people who don't want to learn any programming.

It feels like they are missing out on so much.

But guess that's true of makers, handy-men, or car fixers, etc. about people (like me!) who can't really fix or build anything "useful" or "real" but can knock up a script or system.
 
I always liked unix-like systems, but then I learned perl and the entire Unix-world became way more satisfying. I feel far more liberated, useful, etc [you can also gather weather data / stock info / etc with it]. Knowing some basic compiled language like c/c++ makes it much easier to learn scripting languages.
 
This is why it feels a bit sad when you meet people who don't want to learn any programming.

It feels like they are missing out on so much.

But guess that's true of makers, handy-men, or car fixers, etc. about people (like me!) who can't really fix or build anything "useful" or "real" but can knock up a script or system.
Exactly. There are things all of us can do to make things or make a million dollars but there are things we just don't want to do cause we have no interest or aptitude for it. This whole push one reads about on the internet about teaching kids to program (or anyone for that matter) as a matter of course is no different than if you were to insist that everyone take a course on mechanical engineering or HVAC systems.
 
You can make a royal mess of the syntax with Perl
The 3rd Annual Obfuscated Perl Contest

Winning entry from a previous contest:
Perl:
package S2z8N3;{
    $zyp=S2z8N3;use Socket;
        (S2z8N3+w1HC$zyp)&
    open SZzBN3,"<$0"
  ;while(<SZzBN3>){/\s\((.*p\))&/
    &&(@S2zBN3=unpack$age,$1)}foreach
   $zyp(@S2zBN3)
  while($S2z8M3++!=$zyp-
  30){$_=<SZz8N3>}/^(.)/|print $1
      ;$S2z8M3=0}s/.*//|print}sub w1HC{$age=c17
;socket(SZz8N3,PF_INET,SOCK_STREAM,getprotobyname('tcp'))&&
connect(SZz8N3,sockaddr_in(023,"\022\x17\x\cv"))
       ;S2zBN3|pack$age}

Or the "curses-based real-time skiing game":
Perl:
undef $/;open(_,$0);/ \dx([\dA-F]*)/while(<_>);@&=split(//,$1);@/=@&;
$".=chr(hex(join("",splice(@&,0,2))))while(@&); eval$”;

($C,$_,@\)=(($a=$/[1]*4)*5+1, q| |x(0x20).q|\||.chr(32)x(0x10).q$*$.
chr(0x20)x(0x10).(pack("CC",124,10)), sub{s/.\|(\s*?)(\S)./\|$1 $2/},
sub{s/\|(\s*?).(\S)/ \|$1$2 /}, sub{$2.$1.$3},sub{$tt=(3*$tt+7)%$C},
sub{$1.$3.$2});
while ($_) {
    select $/, undef, $/, $C/1E3;
    (sysread(STDIN, $k, 1),s/(.)(\*)(.)/(&{$\[(ord($k)-44&2)+2]})/e)
    if (select($a=chr(1),$/,$/,0));
    
print 0x75736520504F5349583B2024743D6E657720504F5349583A3A5465726D696F73
3B24742D3E676574617474722828303D3E2A5F3D5C2423292F32293B2024742D3E
365746C666C61672824742D3E6765746C666C6167267E284543484F7C4543484F4
7C4943414E4F4E29293B2024742D3E7365746363285654494D452C31293B24742D
E7365746174747228302C544353414E4F57293B24643D224352415348215C6E223B0A;

  ($p?(/.{70}\|$/):(/^\|/))||(&{$\[3]}<$/[0])?($p=!$p):&{$\[$p]}||die("$d");
  (&{$\[3]}<$/[1])&&(s/ \|$/\|/);
  (/\|.*\*.*\|$/)||die("$d");
}
 
OT: perl 7 is coming. Technically, it's perl 5++ & !=6. If you like perl, support it by writing script, porting perl-written software to the tree, and making tutorials (video/blog).
 
Back
Top