## Posts

Showing posts from May, 2009

### Chopping a long string into smaller ones toy

I made a great tool I can't do without from now on! ;-D Update#1: added null string checking, renamed "i" to "s". Update#2: upgraded output format, added BASH version! Here's the Haskell source code: import System.Environment(getArgs) import Data.List(unfoldr,intersperse) chop k | k>0 = unfoldr f where  f [] = Nothing  f s  = Just $splitAt k s main = do [k,s@(_:_)] <- getArgs let out = show . concat . intersperse " " res = chop (read k) s putStrLn$ "filter(/=' ')" ++ out res Typing: ./chop.hs 27 http://bkil.blogspot.com/2009/05/chopping-long-string-into-smaller-ones.html Gives: filter(/=' ')"http://bkil.blogspot.com/20 09/05/chopping-long-string- into-smaller-ones.html" Or if you prefer, you could alternatively opt for the following BASH routine: main(){  printf 'echo "'  printf "$2"|sed -r "s~.{$1}~& ~g"  echo '"|sed "s~ ~~g"'

### Substituting power plant fired switchgrass for ethanol

Edit: fixed dead link http://money.cnn.com/news/newsfeeds/articles/reuters/MTFH68994_2009-05-07_19-55-00_N07396064.htm Just as I've been telling everybody for many years now: the internal combustion engine is unsustainable. Note that a possibly even better alternative would be some strain of algae. Also note that I am nevertheless still advocating commuting to work by electric motorcycle or bicycle for most people! UK (REUTERS): Researchers eye better use for biomass than ethanol

### Quine in Erlang

How could I have forgotten about the friend of mine who's fond of Erlang? :-D -module(q). -export([s/0]). s()->io:format("~s~p.\n",[p(),p()]). p()->"-module(q).\n-export([s/0]).\n\ns()->io:format(\"~s~p.\\n\",[p(),p()]).\n\np()->". Here's another one for the Eshell REPL: fun(P)->io:format("~s\n~p).\n",[P,P])end( "fun(P)->io:format(\"~s\\n~p).\\n\",[P,P])end("). And as I know he's also in love with LISP, here's a Haskell variant rewritten in that spirit: (\ (x)-> ((++) x (show x)))"(\\ (x)-> ((++) x (show x)))"

### Fixing grey background (default bgcolor) in graphic links2

#Installing dependencies if you can become root is easy (Debian names shown): apt-get install pkg-config libpng12-dev libjpeg62-dev xorg-dev # libssl-dev libgpm-dev libbz2-dev #Fetch the web browser source: mkdir mylinks && cd mylinks && apt-get source links2 #Here's the magic, changing the default graphics mode background color from grey to white: patch -p 0 <<END diff -u links2-2.1pre37.old/default.c links2-2.1pre37/default.c --- links2-2.1pre37.old/default.c 2008-06-21 18:05:53.000000000 +0200 +++ links2-2.1pre37/default.c 2009-05-09 22:10:48.000000000 +0200 @@ -1453,7 +1453,7 @@ struct rgb default_vlink = { 255, 255, 0, 0 }; struct rgb default_fg_g = { 0, 0, 0, 0 }; -struct rgb default_bg_g = { 192, 192, 192, 0 }; +struct rgb default_bg_g = { 255, 255, 255, 0 }; struct rgb default_link_g = { 0, 0, 255, 0 }; struct rgb default_vlink_g = { 0, 0, 128, 0 }; END #Now we can compile the software: cd links2-* && ./configure --with-x --

### Quine in Haskell

I've constructed a neat little quine in Haskell, the popular research language we all adore. ;-) It's so short, I could have pasted it right into the title! :-D putStr(p++show p)where p="putStr(p++show p)where p=" That's what I like about Haskell: the solutions you write in it are usually elegant, conscious and close to the problem space in representation. You read the above source as follows: print out the program accompanied by a quoted (shown) version of the same, where the program is just what I said. Can you put it any simpler than that?! I've first started on a traditional route by introducing constants for backslash, quotation mark and all that, until I've realized how foolish I was. As you may have already known, Haskell has a handy function called 'show' that does all quoting for you. I've been using that all over the place if you have read any of my sources, so I'm not sure why it slipped my mind. Sometimes we overlook the mo

### A little background information about this blog

I write almost all articles and text on my Ericsson MC218 when I'm traveling and have nothing better to do. Note that I can touch type almost as fast on my mini-Dvorak as on my full-sized one, so this is by no means a limitation (>55WPM)! :-) When I get home, I upload them to my PC, covert them with a simple script of mine, proof-read them and run a second pass of spell checking. I then put them in a waiting queue based on completion ratio and importance, sometimes doing a bit splitting at the same time. Once in a while, I take one from the top of the stack and publish it. Hence for me, there's no such thing as lack of time or inspiration! :-D

### POLL: How do you use this site; posts you check

Note that checking multiple options is allowed in both polls. I forgot to post an entry about it, but one of my most die-hard readers has already noticed! Actually, I think the majority of my readers have already voted... XD The low readership is expected because of many issues with the articles, like the abstract, specialized, mostly time-invariant knowledge and language. I believe that to reach as far as possible, especially of such narrow-scope material, you need to write in a suitable language. Toki Pona and Lojban would have been my second choice... ;-D

### Ergonomics of the computer mouse and keyboard from a hardware perspective

It's a pretty interesting fact that we still use the not so ergonomic kludges of many decades ago for our daily work. Let's just skip keyboard layouts altogether, as we all know the truth about them! ;-) You see, for technical reasons, ergonomics wasn't considered for these input devices by the original designers. They simply tried to solve the engineering problems of the day - and they have succeeded! They always have two driving forces: one, how similar problems have been solved in the past and two, how to construct a device as simple as possible (i.e., to invent as few things as possible at once). They are initially dominated by the limitations of technology of the day, while later on, they must keep in mind to provide an easy migration path for earlier users of the same or a similar invention ( Wikipedia: Path dependence ). For example, the typewriter has influenced the computer keyboard in all practically possible ways - i.e., they tried to mimic as closely as possi