just started playing with my new motorola milestone with android 2.1. 
I had no idea how much fun it is to write perl-programs for this nice little device. I use the ASE (android scripting environment) which also supports python, lua, ruby …
You can get it on their website.
I guess I will write some programs soon to see what’s possible. The only thing that sucks on the milestone is, that the dollar sign is only available via touchpad. That’s REALLY annoying. :/
I can’t tell you how often I see scripts and programs which contain a huge amount of echo, print or whatever calls to produce output. It is ok if there are one or two lines to print out, but it becomes inefficient when used explicitly. In shell-scripts and Perl for example you could use so-called Here-Documents. Never heard of them? Well, here some examples:
example: bash
#!/bin/bash
# usage text
usage() {
echo ""
echo "This is the usage of blabla"
echo "Parameters:"
echo " -f ... Parameter 1 blabla"
echo " -g ... Parameter 2 blablubb"
echo ""
}
Well, here you can see that there are a lot of echo-calls (often there are MUCH more … :-/). Now, we learn about an exciting new way to shorten this. We use “cat”:
example: bash better
#!/bin/bash
# usage text
usage() {
cat << EOUSAGE
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
}
So, instead of using tons of calls, just do it with one “cat”. Maybe it seems a bit pedantic of me, but this example makes more sense if you encounter more text (like HTML-output) which is printed out to a document with thousands of “echo”-s.
You can do this in Perl similarly:
#!/usr/bin/perl
# usage text
sub usage() {
print <<"EOUSAGE";
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
}
or in Ruby:
#!/usr/bin/ruby
# usage text
def usage
print <<EOUSAGE
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
end
I guess you can do something like that or similarly in nearly every language. So PLEASE, if you have much text to display in your scripts, use Here-Documents.
I’m currently thinking about writing my own blog-software. Yes, I know that there are hundreds of projects out there and some of them (like wordpress, which I currently use) are really good and have huge communities. But that’s not the point.
The reason why I’d like to do that is that wordpress is too feature-rich, too bloated for me. I don’t need 90 % of the functions it has to offer. All I want and need is a simple listing of stuff I’m currently thinking about or working at. Of course, there should be a nice interface for me to insert new articles, but I actually don’t need the ‘comment’-function. If someone wants to tell me something, he could drop me a line via e-mail too …
So, that’s why I’m thinking about creating my own blogware. It would be a nice exercise anyway. If I really complete this project I guess I’ll publish it under an open source license for anyone who wants to use or modify it for his/her needs.
Posted by ap0calypse on 10. September 2008 – 09:36
… of code quality:

I laughed very, very loud
I was just surfing around in my script-directory and found another gem I scripted back in February. The main purpose was to decrypt a ciphered sentence. Although it would have only taken me a couple of seconds to decrypt it, I decided that it would be even more fun to script it
.
This is the result: shift-cipher
There is also a version available in Ruby: shift-cipher-ruby
This script should work (as usual) on any current GNU/Linux Distribution or *BSD where Perl or Ruby is installed. It deals with one line of standard input, which means that you can simply pipe the output of a command-line tool into it. An example:
ap0calypse@shu:/home/ap0calypse/scripts> echo "x adkt hwxuixcv" | shift-cipher
shift by: 1 : y belu ixyvjydw
shift by: 2 : z cfmv jyzwkzex
shift by: 3 : a dgnw kzaxlafy
shift by: 4 : b ehox labymbgz
shift by: 5 : c fipy mbczncha
shift by: 6 : d gjqz ncdaodib
shift by: 7 : e hkra odebpejc
shift by: 8 : f ilsb pefcqfkd
shift by: 9 : g jmtc qfgdrgle
shift by: 10 : h knud rgheshmf
shift by: 11 : i love shifting
shift by: 12 : j mpwf tijgujoh
shift by: 13 : k nqxg ujkhvkpi
shift by: 14 : l oryh vkliwlqj
shift by: 15 : m pszi wlmjxmrk
shift by: 16 : n qtaj xmnkynsl
shift by: 17 : o rubk ynolzotm
shift by: 18 : p svcl zopmapun
shift by: 19 : q twdm apqnbqvo
shift by: 20 : r uxen bqrocrwp
shift by: 21 : s vyfo crspdsxq
shift by: 22 : t wzgp dstqetyr
shift by: 23 : u xahq eturfuzs
shift by: 24 : v ybir fuvsgvat
shift by: 25 : w zcjs gvwthwbu
As you can see, shifting this sentence by a value of 11 really starts making sense. This is a REALLY bad way to encrypt, but hey, it is still better than nothing.
NOTE: special characters (äöüß) are NOT supported. It works with a-z.