"; */ ?>

howto


31
Oct 07

Feed Opera with Firefox :)

    One of my readers wanted to sign up to my feed using his favorite Opera browser. However failed to do that since Opera does not yet understand "feed://" protocol. Hence, I decided to drop this quick note on how to make Opera delegate feeds to others until the times it’s capable ;)

    In Opera go to "Tools -> Preferences -> Advanced -> Programs", click on "Add…", and enter "feed" for Protocol and "firefox", or ANY preferred RSS reader in "Open with other application":

   

    Now click "Ok" followed by another "Ok" and enter a "feed://" address to the address bar, for example this one. Once you hit Enter, you favorite RSS Reader (Firefox in my case) will open this feed, and your Opera will feel much better, since it just delegated a heavy unit of a hard work to somebody else ;)

    Happy hacking people!


30
Oct 07

How to Build DIGG in Ruby On Rails (Free Book)

    I’ve been playing a lot lately with RoR (Ruby on Rails) and of course I love DIGG, hence I was very pleased to stumble upon a very interesting work by Patrick Lenz, which is a definitely cool and enjoyable free book (pdf) on how to build a full blown DIGG in Ruby on Rails from scratch!

    I spent a couple of hours reading and trying, and I am already (!) building the app (or should I say building the DIGG) at this point of writing this post. The book uses Web 2.0 approach which covers a lot of Web 2.0 along the way – very cool! I highly recommend it to anybody who has the same passion, since it really is an awesome read!

    Please hurry, as this book is only free (since the moment of me writing this) for "32 days, 14 hours, 21 minutes, 49 seconds" more, and I guess will blend in with many other books that we have to pay for once the time is up (currently it is $26.37 at Amazon).

    For something "not very free", but "the best" on Ruby on Rails, there is another great book "Agile Web Development with Rails, 2nd Edition" that can be obtained, well, same place all other "not very free" books are obtained :) here.

    It is not in any way an intentional advertisement for any of the links above, I am just so exited reading it, that I could not stop my self from sharing with the rest of the universe! ;)


19
Oct 07

Help Google to Generate Only Relevant Ads!

google money    I recently decided to participate in Google Adsense program where Google shows its ads on my blog, and I get paid when somebody clicks the ad. This tool from Google is far from being fresh and new, but I think it has a very cool idea behind it:
        – ad owner wins, because people go to her/his website,
        – Google wins, because ad owner pays Google for a click (through Google Adwords)
        – I win, because I keep writing stuff on my blog and get paid by Google for a click.

   One of the main challenges and the main thing about any kind of ads from any place is their relevance. Will you buy milk on a porno site? Or do you need a pack of Marlboro Lights, when searching for a Whitening Toothpaste? Probably not really…

    So you see the logic, the more relevant the ad is, the more chances people are going to pay their attention to it and, in the case of Adsense, "click it".

    Relevance is mostly achieved by the Google algorithm that analyzes your page (the page where ads are going to be displayed) by reading its content and "data mining" it. Then it makes a decision on what exactly "this" page is about, and what ads Google has on that topic. Once all is figured out, Google places the resulting ads on the page.

    But there are ways we can help Google not to "offer milk on the porno site" (although Google does not do porno sites – just a colorful example here :) ), but instead target its ads right to the point. One of such ways is "Section Targeting".

    how Google explains it:

    Section targeting allows you to suggest sections of your text and HTML content that you’d like us to emphasize or downplay when matching ads to your site’s content. By providing us with your suggestions, you can assist us in improving your ad targeting.

    You can read their short tutorial here. The idea is simple: your html page has a lot of text, including links, other advertisement, people comments, etc. but what you really want Google to focus on is your content ( in my case it is my blog post ). So you can use three HTML tags that will focus Google Adsense engine on your content. These tags are:

               Section start tag:               <!– google_ad_section_start –>

               Section end tag:                <!– google_ad_section_end –>

               Ignore section start tag:      <!– google_ad_section_start(weight=ignore) –>

    Sample from Google:

<html><head><title>Section targeting</title></head>
<body>
 
<!-- google_ad_section_start -->
 
This is the text of your webpage. Most of your content resides here.
 
<!-- google_ad_section_end -->
 
</body>
</html>

    From the sample above you can see how (start, end) tags can be used to focus Google only on the  main content. In order to ignore the content, wrap it with (ignore, end) tags as follows:

<html><head><title>Section targeting</title></head>
<body>
 
<!-- google_ad_section_start(weight=ignore) -->
 
This is the text of your webpage. Most of your content resides here.
 
<!-- google_ad_section_end -->
 
</body>
</html>

    But there is something interesting, that is not included in Google’s tutorial, that you can do with tags – you can nest them, as well as focus them on multiple sections! I have spoken to the Google Adsense representative, gave him a couple of examples I would liked to use the tags, and he confirmed that it works.

    So here is very cool and efficient things that you can do with adsense tags in addition to the usual stuff…

    nest those tags:

<!-- google_ad_section_start -->
 
     my content I want to focus on
     .....
 
     <!-- google_ad_section_start(weight=ignore) -->
 
          content I would like to ignore
 
     <!-- google_ad_section_end(weight=ignore) -->
 
     my content I want to focus on
     .....
 
<!-- google_ad_section_end -->

    so, in the above example we ignored a part of the section (content) we actually want Google to focus on – cool, right? :)

    That is not all, you can also focus on multiple sections, like this:

<!-- google_ad_section_start -->
 
     my content A I want to focus on
     .....
 
<!-- google_ad_section_end -->
 
     some other irrelevant content
     .....
 
<!-- google_ad_section_start -->
 
     my content B I want to focus on
     .....
 
<!-- google_ad_section_end -->

    This really opens the doors to finetune the relavence of your ads, which, who knows, maybe someday will make you a millionaire! ;)


10
Sep 07

Avant Window Navigator – Dual Monitor Hack

avant window navigator  Ok, so you have successfully configured dual monitor for you (Gnome/KDE) desktop, and now you have decided to take it even further and install and configure Avant Window Navigator – way to go!

    Although most of your installation/configuration will succeed by following one of the tutorials, in case if you have dual monitors, and/or you use Option  "MergedFB"  in "xorg.conf" to merge two monitors into a one screen, standard tutorials will not work. This will require additional hacking to get AWN to work right, and here is where this article comes in :)

    PROBLEM:    One of the problems that AWN has with multiple screens/monitors is to identify the position of where it needs to put its task bar. In case of two monitors merged into one big screen, it does not adjust to this new slightly larger "coordinate system", and fails to place its task bar to the right place on a screen (usually at the bottom of the bottom screen). This can be solved, of course ;)

    SOLUTION:   AWN stores monitor resolution info in a file called "%gconf.xml" which is located here:

          user@host:~/.gconf/apps/avant-window-navigator$ ll
          total 32
          drwx------ 2 user user 4096 2007-07-18 11:41 app
          drwx------ 4 user user 4096 2007-06-26 23:47 applets
          drwx------ 2 user user 4096 2007-08-06 21:52 bar
          -rw------- 1 user user 776 2007-09-10 09:52 %gconf.xml
          -rw------- 1 user user 776 2007-06-27 22:57 %gconf.xml.dual
          -rw------- 1 user user 776 2007-06-27 10:41 %gconf.xml.single
          drwx------ 2 user user 4096 2007-06-27 17:59 title
          drwx------ 2 user user 4096 2007-06-30 14:16 window_manager
          user@host:~/.gconf/apps/avant-window-navigator$

    "%gconf.xml" is an XML file that has several elements called "entry". The ones we are interested in would be:

 
        <entry name="monitor_height" mtime="1179886419" type="int" value="1024">
        </entry>
        <entry name="monitor_width" mtime="1179886419" type="int" value="1280">
        </entry>

    These values would work fine if we had a single 1280×1024 monitor, but if we have our (e.g.) bottom monitor as 1280×800, in order for AWN to display its task bar in a correct spot (the bottom of the bottom monitor), values have to change to:

 
        <entry name="monitor_height" mtime="1179886419" type="int" value="1824">
        </entry>
        <entry name="monitor_width" mtime="1179886419" type="int" value="1280">
        </entry>

    So what we did, we summed up Y-Positions of both monitors together: 1024 + 800 = 1824. Now when AWN is calculating its task bar’s Y-Pos offset, it will take 1824, as the Y-Pos max range, and will do the right thing!


9
Jun 07

Convert Date to String in Java


Just an example on how “java.text.SimpleDateFormat” can be used to convert a java date object (java.util.Date) to a string (String, StringBuffer, StringBuilder, etc..).
The whole magic is done by SimpleDateFormat, the child of “java.text.DateFormat”, which, as its name suggests, formats the date by a provided template.

This template is very flexible and provided to the formatter as a string. Here are the values which are used by SimpleDateFormat’s template:

Letter

Date or Time Component

Presentation

Examples

G

Era designator

Text

AD

y

Year

Year

1996; 96

M

Month in year

Month

July; Jul; 07

w

Week in year

Number

27

W

Week in month

Number

2

D

Day in year

Number

189

d

Day in month

Number

10

F

Day of week in month

Number

2

E

Day in week

Text

Tuesday; Tue

a

Am/pm marker

Text

PM

H

Hour in day (0-23)

Number

0

k

Hour in day (1-24)

Number

24

K

Hour in am/pm (0-11)

Number

0

h

Hour in am/pm (1-12)

Number

12

m

Minute in hour

Number

30

s

Second in minute

Number

55

S

Millisecond

Number

978

z

Time zone

General time zone

Pacific Standard Time; PST; GMT-08:00

Z

Time zone

RFC 822 time zone

-0800

Below, I wrote an example on how to implement the conversion. Here I used two different templates: “yyyyMMdd” and “MMddyyyy” to show that several letters from the table above can be used in different sequence for the desired format:

import java.util.Date;
import java.text.SimpleDateFormat;
... ... ... ...
 
    public void testConvertDateToString()    {
 
        //   Allocates a Date object and initializes it so that it represents the time
        // at which it was allocated, measured to the nearest millisecond.
        Date dateNow = new Date ();
 
        SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MMddyyyy");
 
        StringBuilder nowYYYYMMDD = new StringBuilder( dateformatYYYYMMDD.format( dateNow ) );
        StringBuilder nowMMDDYYYY = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );
 
        System.out.println( "DEBUG: Today in YYYYMMDD: '" + nowYYYYMMDD + "'");
        System.out.println( "DEBUG: Today in MMDDYYYY: '" + nowMMDDYYYY + "'");
 
    }

Results:

DEBUG: Today in YYYYMMDD: ‘20070609’
DEBUG: Today in MMDDYYYY: ‘06092007’

You may also notice that in the example I used StringBuilder, and not String or StringBuffer. The reason is simple – “best practice – use the right tool for the right task”.

“String” is immutable, meaning it cannot be changed, every time you try to change it, new String object is created and the old one is released for garbage collection, therefore String can be perfect for something like constants e.g. { private static final String FORTY_TWO = “42”; }.

StringBuilder and StringBuffer can be changed (modified), and, in fact, they have exactly the same functionality with one distinct difference – StringBuffer is synchronized and StringBuilder is not. Therefore if the segment of code we are working on is not designed to be multi threaded (used by different threads in a same time), it is better to use StringBuilder, since it will work faster.

StringBuilder is available in Java 1.5.0 (Java 2 SE 5.0) and up.

KISS – Keep It Simple Stupid ;)