The Pragmatic Programmer

Tulisan iseng kalo ada waktu.
See also: Other Geeks@INDC

June 2007 - Posts

Angry Function

This function is taken from jscalendar source code :) I found it while I was finding a way to prevent the calendar from showing beyond the screen boundary.

Calendar.continuation_for_the_fucking_khtml_browser = function() {

    var w = self.element.offsetWidth;
   
var h = self.element.offsetHeight;

    self.element.style.display = "none";

    var valign = opts.substr(0, 1);

    var halign = "l";

    if (opts.length > 1) {
      
halign = opts.substr(1, 1);
   
}

   // vertical alignment
  
switch (valign) {
     
case "T": p.y -= h; break;
     
case "B": p.y += el.offsetHeight; break;
     
case "C": p.y += (el.offsetHeight - h) / 2; break;
     
case "t": p.y += el.offsetHeight - h; break;
     
case "b": break; // already there
  
}

   // horizontal alignment
   switch (halign) {
     
case "L": p.x -= w; break;
     
case "R": p.x += el.offsetWidth; break;
     
case "C": p.x += (el.offsetWidth - w) / 2; break;
     
case "r": p.x += el.offsetWidth - w; break;
    
case "l": break; // already there
   }
   self.showAt(p.x, p.y);
};

Share this post: | | | |
The Lockwood Analytical Method for Prediction (LAMP)

I am a pragmatis, but don't get me wrong that I don't like theories. I like theories as long as it has practicality.

Stumbled to this blog, I wonder if the theory described here can be useful to predict the result of a software project.

What do you think?

Share this post: | | | |
A Gemini

Gemini Personality traits
 This is the chat sign. They love to talk and will even do so with strangers standing in line at the grocery store. Communication is a need for this adaptable individual. They are witty and intellectual. Some might even consider them eloquent. Able to keep up with younger people, they are seen as youthful and lively.

Gemini’s tend to know a little about everything. Their quick ability to assimilate knowledge makes them easily bored and ready to move onto another project. This sign needs spice to their life. They are very logical, rational people.

Needing lively, intellectual rapport with love partners, they look for more educated people. These partners can be educated formally or by experience. Gemini’s lover should express definite opinions. Otherwise, they can be run over by the Gemini who loves to argue and express their own opinions. Geminians have problems trusting their emotions entirely. Their logical, rational minds come into play any time they are overwhelmed by emotion.

Versatility in communicative skills should be the place a Geminian looks for work. The media, sales, department stores, advertising and commercial travelers are all good careers for the witty Geminian. If you put the Gemini personality into a job that does not challenge him in a different way each day, you have a very unhappy person indeed.

Unafraid to take advice from others who have done their jobs before, they actively seek counsel. Geminians are not overly ambitious but seem to be where money is to be made. Their imagination acts as a catalyst for whatever they want. In short, they enjoy success before it is really achieved.

A Gemini, even in retirement, is anything but retired. They want to keep busy and generally do with something to keep their interest.

This sign has loads of nervous energy and need something on which to burn it off. They are not the strongest of signs in the Zodiac but they are forever young. Gemini rules the lungs and as such should watch anything having to do with breathing such as a chest cold or bronchitis. People born under this sign should never smoke.

Gemini Keywords
Adaptable
Versatile
Communicative
Witty
Intellectual
Eloquent
Youthful
Lively
Nervous
Tense
Superficial
Inconsistent
Cunning
Inquistive

Gemini Symbol
Twins

Gemini Planet
Mercury

Gemini Part of the body it rules
The Lungs

Gemini Gemstone it rules
Agate

Flowers it rules
Lily of the Valley
Lavender
Maidenhair
Myrtle
Fern

Color it rules
Yellow

What is your zodiac?

Share this post: | | | |
What Makes a Pragmatic Programmer?

One of computer books that I really like is Andrew Hunt and Dave Thomas' book, "The Pragmatic Programmer: From Journeyman to Master." Below is the characteristic of a pragmatic programmer, excerpt from the book:

Each developer is unique, with individual strengths and weaknesses, preferences and dislikes. Over time, each will craft his or her own personal environment. That environment will reflect the programmer's individuality just as forcefully as his or her hobbies, clothing, or haircut. However, if you're a Pragmatic Programmer, you'll share many of the following characteristics:

* Early adopter/fast adapter. You have an instinct for technologies and techniques, and you love to trying things out. When given something new, you can grasp it quickly and integrate it with the rest of your knowledge. Your confidence is born of experience.

* Inquisitive. You tend to ask questions. That's neat--how did you do that? Did you have problems with that library? What's this BeOS I've heard about? How are symbolic links implemented? You are a pack rat for little facts, each of which may affect some decision years from now.

* Critical thinker. You rarely take things as given without first getting the facts. When colleagues say "because that's the way it's done," or a vendor promises the solution to all your problems, you smell a challenge.

* Realistic. You try to understand the underlying nature of each problem you face. This realism gives you a good feel for how difficult things are, and how long things will take. Understanding for yourself that a process should be difficult or will take a while to complete gives you the stamina to keep at it.

* Jack of all trades. You try hard to be familiar with a broad range of technologies and environments, and you work to abreast of new developments. Although your current job may require you to be a specialist, you will always be able to move on to new areas and new challenges.

Are you a pragmatic programmer?

Share this post: | | | |
Just a Little Puzzle

There is a company that ask their candidates to answer a puzzle before applying for their opening job. You can find the puzzle here.

Well, I just want to trying to have a nostalgia with my past time when I was in college. So, I wrote 3 type of the solutions using JavaScript, here they are:

<script class="Solution1" language="javascript">
 
var agroup = ""
  var nextCounterToPrint = 5;
  var currentCounter = 0; //just for increasing speed

  for(var i = 1; i <= 1000; i++){
    agroup += i.toString();
    currentCounter++;
    if(currentCounter == nextCounterToPrint){
      nextCounterToPrint = (nextCounterToPrint == 5) ? 3 : 5;
      currentCounter = 0;
      if(!isFirstTime(i)){
        agroup = "*" + agroup;
      }
      document.write(agroup);
      agroup = "" 
    }
  }

  function isFirstTime(i){
    return (i == 5);
  }
</script >

<script class="LineBreak" language="javascript">
  document.write("<BR>");
</script >

<script class="Solution2" language="javascript">
 
var printed = 0;
  var toggled = false;
  for(var i = 1; i <= 1000; i++){
    document.write(i);
    printed++;
    if(printed == 5 && !toggled)
    {
     
document.write("*");
      printed = 0;
      toggled = true;
    }
    else if(printed == 3 && toggled && i < 1000){
     
document.write("*");
     
printed = 0;
      toggled = false; 
    }
  }

</script >

<script class="LineBreak" language="javascript">
   document.write("<BR>");
</script >

<script class="Solution3" language="javascript">
var lists = [5,8,13,16,21,24,29,32,37,40,45,48,53,56,61,64,69,72,77,80,85,88,93,96,101,104,109,112,117,120,125,128,133,136,141,144,149,152,157,160,165,168,173,176,181,184,189,192,197,200,205,208,213,216,221,224,229,232,237,240,245,248,253,256,261,264,269,272,277,280,285,288,293,296,301,304,309,312,317,320,325,328,333,336,341,344,349,352,357,360,365,368,373,376,381,384,389,392,397,400,405,408,413,416,421,424,429,432,437,440,445,448,453,456,461,464,469,472,477,480,485,488,493,496,501,504,509,512,517,520,525,528,533,536,541,544,549,552,557,560,565,568,573,576,581,584,589,592,597,600,605,608,613,616,621,624,629,632,637,640,645,648,653,656,661,664,669,672,677,680,685,688,693,696,701,704,709,712,717,720,725,728,733,736,741,744,749,752,757,760,765,768,773,776,781,784,789,792,797,800,805,808,813,816,821,824,829,832,837,840,845,848,853,856,861,864,869,872,877,880,885,888,893,896,901,904,909,912,917,920,925,928,933,936,941,944,949,952,957,960,965,968,973,976,981,984,989,992,997];

for(var i = 1; i <= 1000; i++){
  document.write(i);
  if(i == lists[0]){
    lists.shift();
    document.write("*");
  }
}

</script >

Which one do you think is the best one? Or maybe you have another solution, please share!

Share this post: | | | |
Learning Electronics

I have been keeping my passion to know about electronics until now. Not long again, I will fullfill my dream on knowing how electronics works. I have registered to join a course for basic electronics at Hertz, a local electronic course institution located near Gajah Mada Plaza.

One of my friends does not agree with my decision to learn electronics. The reason is because it will not give value to my career as a software deveoper. Yeah, my reason is just for a hobby and curiousity. This is something that if I didn't do, I won't have peace if I am dead :)

Yesterday, should be my first theoretical lesson about electronic. But too bad I can't come because I am sick. I got cold because I took the wrong bus that head straight to Bekasi instead of takes me to Slipi. Damn, I don't know how it can be happened because I really sure that I have take the right bus to home.

I do not know after I finish my basic electronic course do I want to continue for more advanced course about appliance troubleshooting or take my own road. Does any one have an advice for me about electronics?

Share this post: | | | |
The Crims

The Cris is an addictive game jsut like the Championship Manager. In this game you can choose to play as several types of criminal like a killer, a robber, etc. The game it self is a web based game where the site act as another world, where you and every one else is a criminal. You can join a gang, act a robbery, killing other player, or anything criminals in the real life can you do in here. Quite fun! You can try it here.

Share this post: | | | |
Mind Power

Many books says about the power of positive thinking. They said that if we think about something and imagining it in our mind then one day it will become a reality. I am agree with the statement, because I've been go through it my self even though it takes quite long time before what I was thinking become a reality, usually it happens when I have forgotten it.

One of my ex-boss really fond about this mind power.

How about you?

Share this post: | | | |
Read Only Dropdown

This is just a simple trick on how to set a dropdown list to read only so the user can not change the already selected dropdown's item. Here is the code:

<select onfocus="this.oldIndex = this.selectedIndex" onkeydown="event.returnValue = false" onchange="this.selectedIndex = this.oldIndex">
    <option>Banana</option>
    <option selected>Mango</option>
    <option>Papaya</option>
</select>

I've turned off the item's selection through keyboard but I can't seem find out how to disable selection by mouse. Do you have any idea? Please share!

Share this post: | | | |
Merging columns in GridView header

Well, a Ukraine developer has wrote an article on his web site about how to merge columns in GridView based on my article that I've published to CodeProject about 3 years ago.

Share this post: | | | |
Quantum Communications Reached 144 km

Maybe this can be use to teleporting human.

Share this post: | | | |
Which Programming Language Are You?
You are Perl. People have a hard time understanding you, but you are always able to help them with almost all of their problems.
Which Programming Language are You?
Share this post: | | | |
Which OS are You?
You are Amiga OS. Ahead of your time.  You keep a lot of balls in the air.  If only your parents had given you more opportunities to suceed.
Which OS are You?
Share this post: | | | |
A Step-By-Step Guide on How to Wash Clothes

A couple of days ago, a friend of mine shared to me this important knowledge. OK, guys, if you are far away from home this is a step-by-step guide on how to wash your clothes. Its in Indonesian because its useless for people from other country.

1. Pisahkan pakaian berwarna putih dengan yang berwarna
2. Siapkan 2 ember, lalu isi dengan air secukupnya
3. Masukkan pakaian ke dalam ember dan tambahkan air sambil dikocok-kocok hingga deterjen tercampur rata dengan air dan baju terendam
4. Diamkan 15 menit
5. Sikat bagian ketiak, kerah, dan ujung lengan untuk kemeja dan bagian "burung" untuk celana
6. Setelah semua pakaian disikat, siapkan air ember yang telah diisi air bersih
7. Masukkan pakaian yang telah disikat ke dalam air bersih, gosok-gosok lalu diperas dan ulangi sampai air tidak berbusa lagi
8. Bila ingin menambahkan pewangi, siapkan satu ember air yang sudah dikasih pewangi pakaian sebanyak satu sendok teh. Rendam selama 5 menit.

Takaran:
10 buah pakaian = 3 sendok makan deterjen dan 1 sendok teh pewangi.

Happy washing!!!

Share this post: | | | |
Merge GridView Header

OK! You want to know how to merge GridView header? There are many ways to do that, you can inherit the GridView control and override its render method or you can override the render method directly without subclassing it like this one.

There is another way, the JavaScript way :). Let's say you have this grid:

You want to merge it cells into this one:

Here you goes:
1. Add a new GridView into your aspx

<asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<FooterStyle BackColor="Tan" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>

2. Bind it to a data source

protected void Page_Load(object sender, EventArgs e)
{
      if (!this.IsPostBack)
     {
         GridView1.DataSource = getDataSource();
         GridView1.DataBind();
      }
}

private object getDataSource()
{
     DataTable dt = new DataTable();
     dt.Columns.Add("NIM");
     dt.Columns.Add("First Name");
     dt.Columns.Add("Middle Name");
     dt.Columns.Add("Last Name");
     dt.Columns.Add("High School");

     DataRow dr = dt.NewRow();
     dr["NIM"] = "0331970399"
     dr["First Name"] = "Irwansyah"
     dr["Middle Name"] = ""
     dr["Last Name"] = "Irwansyah"
     dr["High School"] = "SMAN 16 Palmerah"

     dt.Rows.Add(dr);

     return dt;
}

3. And these is the trick code, make sure to put it below the GridView

<script language="javascript">
     //this pageLoad will only works if you are using ASP.Net AJAX
     //if you're not, you can use the other way.
     function pageLoad(){
          var grid = document.getElementById('<%=GridView1.ClientID %>');
          var firstRowHeaderClone = grid.tBodies[0].rows[0].cloneNode(true);
          grid.tBodies[0].insertBefore(firstRowHeaderClone, grid.tBodies[0].rows[0]);

     //get a reference to first and second row header
     var firstRowHeader = grid.tBodies[0].rows[0];
     var secondRowHeader = grid.tBodies[0].rows[1];

     //delete the NIM cell in second row header
     secondRowHeader.deleteCell(0);
     //merge the NIM cell in the first row header
     //to the cell below it
     firstRowHeader.cells[0].rowSpan = 2;


     //delete the First Name and Middle Name cell
     //in the first row header
     firstRowHeader.deleteCell(1);
     firstRowHeader.deleteCell(1);
     //merge the Last Name cell with two cells behind it
     firstRowHeader.cells[1].colSpan = 3;
     //change the new merged cell's text
     firstRowHeader.cells[1].innerText = "Name"

     //delete the High School cell from the second row header
     secondRowHeader.deleteCell(3);
     //merge the High School cell from the first row header
     //with cell underneath
     firstRowHeader.cells[2].rowSpan = 2;
}
</script>

This trick works with Firefox 2.0.2 and IE 6.0. I have tested it by myself.

OK. Its time to say thanks to JavaScript :).

Share this post: | | | |
More Posts Next page »