Month: November 2013

For some time now I've been wanting to display the logos of those fantastic open source tools I've been using so much, giving them the deserved credit in an unobtrusive manner. Those websites that plaster logos on every page bug me, as if they are trying to prove that they are better. I chose a more appropriate manner by giving them tribute on their own dedicated spot. I couldn't have created this blog of mine without the help of the following fantastic technologies. Have a look for yourself at the powered by page and get inspired.

How far can we push things the Ruby way? Here's an elegant Ruby one-liner for the fibonacci function. I was secretly hoping that it would go on and on forever spewing out endless rows of digits until the end of time, but that was not going to happen.

kiffin@F5SL:~ $ irb
irb(main):001:0> fibonacci = Hash.new{ |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] }
=> {}

Function defined and working...

irb(main):002:0> fibonacci[10]
=> 55

Let's go deeper ...

irb(main):003:0> fibonacci[100]
=> 354224848179261915075

And deeper ...

irb(main):004:0> fibonacci[1000]
=> 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875

Even more deeper ...

irb(main):005:0> fibonacci[5000]
=> 3878968454388325633701916308325905312082127714646245106160597214895550139044037097010822916462210669479293452858882973813483102008954982940361430156911478938364216563944106910214505634133706558656238254656700712525929903854933813928836378347518908762970712033337052923107693008518093849801803847813996748881765554653788291644268912980384613778969021502293082475666346224923071883324803280375039130352903304505842701147635242270210934637699104006714174883298422891491273104054328753298044273676822977244987749874555691907703880637046832794811358973739993110106219308149018570815397854379195305617510761053075688783766033667355445258844886241619210553457493675897849027988234351023599844663934853256411952221859563060475364645470760330902420806382584929156452876291575759142343809142302917491088984155209854432486594079793571316841692868039545309545388698114665082066862897420639323438488465240988742395873801976993820317174208932265468879364002630797780058759129671389634214252579116872755600360311370547754724604639987588046985178408674382863125

Deeper still ...

irb(main):006:0> fibonacci[10000]
SystemStackError: stack level too deep
	from /home/kiffin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/workspace.rb:86
Maybe IRB bug!
irb(main):007:0> 

Oops, we went too deep.

The moral of the story is that although Ruby is an elegant and amazing programming language with endless possibilities, even it's magical powers are not limitless.

A most disturbing Vim anti-pattern is using the good old arrow keys to navigate around the page. I've been told that this is a terrible habit which makes me more inefficient. I do not like wasting time and being inefficient, so I read up a bit on the subject and decided to add the following lines to my .vimrc configuration file. Say good-bye to arrow keys my friend.

noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>

At first I felt very crippled, but after awhile believe it or not I started to get used to it. Bad habits are hard to break, but if you hang in there you can do it. j,j,l,k,k,k,h,k,j ...

Even using the default vim navigation keys h,j,k,l gets boring after awhile. This is the slow poke way to move like a snail across the editing surface. There are even speedier and thus better ways to accomplish such a feat. If you don't know what they are look it up yourself (:help word).

So in order to end the pain of all pains I extended vim nops to include the following lines as well:

noremap h <NOP>
noremap j <NOP>
noremap k <NOP>
noremap l <NOP>

Slowly but surely I'm on my way to becoming a true blue vim guru, and it feels pretty good. You're never too old to learn new tricks, and if by doing so you become more productive so much the better I'd say.

Alright then, let me help you along by giving you a slight hint. The w, b, e, ge commands allow us to move forward or backward to the start or end of a word. The W, B, E, gE commands are also something you should check into. Much quicker jumping around that's for sure.

You might also want to have a look at Habit breaking, habit making and then install the Hard Mode Vim Plugin like I did.

When I heard on the radio this morning that it has been exactly fifty years to the day that president Kennedy was shot and killed, I couldn't believe it.

Although I was only six years old that day, the memory remains quite vivid in my mind. I was in first grade sitting in class at the Redding Elementary School (California) when the intercom was turned on. In those days they had this old-fashioned intercom system, which was mainly used mornings during the pledge of allegiance or very occasionally for other minor announcements. There were two quick taps to the microphone, and then the voice of the principal announced the shocking news.

He said, "I have an important announcement to make... the president... has been shot." His voice trembled slightly and there was a pause (I could visualize him bent over the old-fashioned microphone, wiping his tears aside and trying to subdue his sobbing). He coughed to clear his throat and then continued, "Everyone is excused and can go home now." That was it, and the intercom clicked off air. We all looked at each other and had no idea what that meant and what we were expected to do. The teacher was in shock, and her face went blank, as if she had been an actual witness to the assassination.

What happened after that I no longer remember, it all seemed dark gray and depressing. The whole nation was in shock, everyone really loved this president, he had so much charisma and gave us many new hopes for the future. Not that long previously, he had even made a surprise visit to Shasta Lake, I believe my father had brought me there, but all I remember is the huge and noisy crowds. (Kennedy was also planning to end the Vietnam conflict by pulling out all of the troops)

Fast forward a couple days, and I am sitting in front of our black-and-white television in the sitting room downstairs. The funeral procession is being shown, and the coffin is draped by the American flag, being pulled by an official military wagon with big wooden wheels. Everyone is walking very slowly, and the camera zooms in on his wife Jacqueline with her black veil covering her face and the children holding hands.

In my mind, I was also part of history in the making in my own small way. The memory lives on in my head. Just think how history could have been so different.

Kennedy-funeral-procession-1963.png
How it looked on television

Now that I have a bit more time on my hands, I decided to get crazy about the ruby programming language. I've always wanted to learn more about this intriguing language as well as the ruby on rails web framework.

crazy-about-ruby.png

As if all that reading material is not enough, I've also been following a couple of online courses, namely:

I also purchased RubyMine which is an advanced IDE to make me even more productive, though it is a bit sluggish but should be alright once I buy a new laptop.

I'm never too old for learning new and interesting stuff.

golfing-thick-fog.png
Where's the green?

The thick fog makes golfing nearly impossible. At least when you tee off on a long straight par five you can kind of guess where you should hit the ball. Par threes are a bit more problematic. Where's the flag? I believe it is somewhere between that trap on the right and the edge of the water left, can you see it? Distance markers are no help either, especially for large greens when a given distance to the middle of the green could mean plus minus twenty meters. I had a terrible score and I am too embarrassed to reveal what I shot (46+47=93). Believe it or not I once had a lucky birdie on a par four dogleg to the left. Crunched my drive right down the middle of the fairway, completely guessing where the flag might be, hitting a perfect six iron low and over the water, and when I got there it was two feet short of the hole. I won't mention all the double bogies and the six balls I lost that day.

FAG-team-2013.png
Fantastic awesome golfers

| 4 Comments

As you have probably already noticed, I recently implemented a random banner to be displayed on the main page of my website. By clicking refresh a few times you can see it working. Slowly but surely I will add more banners to my collection. It's an elegant way of enabling such a feature, so I thought that it'd be nice to share it with anyone interested.

Basically I create and then keep a bunch of 905x170 pictures which I save in the images directory. These can be randomly displayed in the banner div#homepage-image which is inserted using the /cgi-bin/rand-banner.pl random banner generator script.

This is made possible by including the following lines in the css file:

/* custom.css */
...
/* Banner is randomly generated */
#homepage-image { background-image: url('/cgi-bin/rand-banner.pl'); }
...

This script is run automatically every day by including the following line in the crontab:

@daily /www/kiffingish.com/cgi-bin/rand-banner.pl crontab

For those interested, I have also included the perl script which does all of the magic. It should be pretty straight-forward what this script does, which shows you the power of perl.

#!/usr/bin/perl

use strict;
use warnings;

# rand-banner.pl [crontab] :
# If called with 'crontab' just create the file list of banners,
# otherwise return the binary contents of a random banner immage
# for displaying on a web page.

use CGI;
my $cgi = new CGI;

# Directories based from root dir.
my $root_dir = "/path/to/root/dir";
my $cgi_dir = "$root_dir/cgi-bin";
my $doc_dir = "$root_dir/docs";
my $img_dir = "$doc_dir/images";
my $banners_lst = "banners.lst";

# Coversion file ext to http img/type.
my %ext2typ = ( bmp => 'bmp',
                gif => 'gif',
                jpeg => 'jpeg',
                jpg  => 'jpeg',
                png  => 'png',
                tif  => 'tiff',
                tiff => 'tiff',
);

# Only interested in the following file types.
my $img_filter = join(',', keys %ext2typ);

# If called with 'crontab' or banners.lst does not exist, collect
# list of banners from 905x170 files in images directory.
my $crontab = (defined($ARGV[0]) && ($ARGV[0] eq 'crontab'));
if ($crontab || (! -f $banners_lst)) {
    # See: http://www.imagemagick.org/script/identify.php
    my $output = `identify $img_dir/*.{$img_filter} 2>/dev/null |grep ' 905x170 ' | sed 's/\\[.*//' | sed 's/^.*\\///'`;
    open my $fh, ">", $banners_lst or die "Cannot open file '$banners_lst' for writing ($!)";
    print $fh $output;
    close $fh;
}

# All done if called from crontab.
exit if $crontab;

# Grab the latest banner list.
open my $fh, "<", $banners_lst or die "Cannot open file '$banners_lst' for reading ($!)";
my @banners = <$fh>;
close $fh;

# Take a random item from the list.
my $banner = $banners[rand @banners];
chomp($banner);

# Define banner image filepath.
$banner =~ /^.*\.(.*)$/;
my $ext = $1;
my $img = "$img_dir/$banner";

# Get the binary contents of the image file.
open (IMAGE, $img) or die "Cannot open image file '$img' for reading ($!)";
my $size = -s $img;
my $data;
read IMAGE, $data, $size;
close (IMAGE);

# Return image data to the caller. Be sure to disable caching so
# that each new request returns a new banner image.
print "Content-type: image/$ext2typ{$ext}\n";
print "Cache-Control: max-age=0, no-cache, no-store, must-revalidate\n";
print "Pragma: no-cache\n";
print "Expires: Wed, 11 Jan 1984 05:00:00 GMT\n";
print "\n";
print $data;

This might seem like alot of work for something very simple, but the challenge was worth it for me. I kind like this little added feature to my website. Have fun using it.

They say that running is good for the body and the mind, and I can attest to such a claim that at least in my case it is very true. For me it's not only about getting outside and putting in the distance as is, but pushing myself and forcing a slightly higher tempo than a causal jog. The first half kilometer is fast, and I sprint out the last couple hundred meters so that when I make it back home I am huffing and puffing and sweating profusely. Even when the weather is cold and windy, or the rain is pouring down and I have to dash through puddles and mud, I keep up the usual pace. As in work and as in play I like the challenges, achieving goals and doing my best. Not that I have to be a perfectionist and beat some personal records, though in my younger years I tended to push myself past all limits of reasonableness. My wife is worried that if I'm not more careful I might get a heart attack. Not if I can help it. She thinks I take things way too seriously, including sports. I'm rarely satisfied with my golf scores, and I finish my runs thinking it was okay rather than it was a great time. There is an element of winning in all we do, but it is not the most important goal. Achieving the finish line no matter what, if things go well or not, that's what it's all about. Even failing completely but still finishing is a noble achievement, a much more valuable experience in the lessons of life. Nine out of ten times one is unable to achieve exactly what was planned for, and it is this single time that does that makes it worthwhile.

I never knew before what it was really like to perish this way, but now I know for sure. I'm on my hands and knees in some kind of ditch, and there are a couple other people next to me. There is this overall feeling of a pending doom, and the faces of the other people describe the fear that I am feeling inside. The ditch is maybe twenty yards long, and if we can move across the narrow ditch fast enough, we might make it in time. Suddenly, there is this rumble behind us. As the ground starts to shake more and more, we realize that some kind of giant bulldozer is approaching us quickly. Then without warning, this wave of darkness curls over me, the sky on the distant horizon gets filled in. First in my hair, then my shoulders and the rest of my body get covered, as tons of dirt fall on top of me. It's a lot heavier than what I had expected, and it is the weight of the dirt on top of my chest that prevents me from breathing, not the lack of air. When there is no longer a single ray of light, all sounds get muffled and then disappear, and I just wait while it gets colder and colder.

Random entries

Here are some random entries that you might be interested in:

Recent Assets

  • my-books-4.png
  • my-books-3.png
  • my-books-2.png
  • my-books-1.png
  • Kennedy-funeral-procession-1963.png
  • movabletype-logo.png
  • jquery-logo.png
  • perl-logo.png
  • centos-logo.png
  • mysql-logo.png
  • apache-logo.png
  • crazy-about-ruby.png

Recent Comments

  • Long time no see: I remember them, as well. I remember Donald was my ...
    - Charles
  • Bridge to the moon: Yes it was a drawing and my older brother told me ...
    - jpmcfarlane
  • Bridge to the moon: Wow, that's quite a coincidence that we both sent ...
    - Kiffin
  • Bridge to the moon: Hello I was in my teens when Gemini 4 went up that ...
    - jpmcfarlane
  • Back to work: Congratulations Kiffin, I hope it is something you ...
    - KathleenC

Golf Handicap

Information

This personal weblog was started way back on July 21, 2001 which means that it is 7-21-2001 old.

So far this blog contains no less than 2518 entries and as many as 1877 comments.

Important events

Graduated from Stanford 6-5-1979 ago.

Kiffin Rockwell was shot down and killed 9-23-1916 ago.

Believe it or not but I am 10-11-1957 young.

First met Thea in Balestrand, Norway 6-14-1980 ago.

Began well-balanced and healthy life style 1-8-2013 ago.

My father passed away 10-20-2000 ago.

My mother passed away 3-27-2018 ago.

Started Gishtech 04-25-2016 ago.