Terminally Incoherent

Utterly random, incoherent and disjointed rants and ramblings...

Sunday, April 30, 2006

Twin Sisters

Is it just me or is Haley Berry stealing Gigi Edgley's Chiana look in X3? I swear, X3 storm and Chiana look like they were separated at birth:



If they painted Haley the same grayish paint, she could play Chiana's sister :P


Can't wait for X3. So far the X-men movies have been getting better. X1 was ok, X2 was better, so if that trend continues X3 should be actually a good movie. But then again, who knows.

Saturday, April 29, 2006

Monster Mega Breackfast

Monster Mega Breackfast
Monster Mega Breackfast,
originally uploaded by maciakl.
Ark and me went to the Red Hawk Diner today. We made the mistake of ordering their Mega Meals. He ordered the Gut Buster and I got the 12" Pankakes.

To my dismay, these pankakes were called 12" because they have a 12" diameter. Duh! I did not expect them to be that big. I don't know what the hell was I thinking. They are fucking huge ass, mastodonic, garganduan pankakes!

The manager told me that if I eat them both, my meal is free :P I tried, but couldn't do it. I didn't even finish one of them. I think I need to bring Nick, our local eathing champion, with me next time :)

Needless to say, I think I'm done with pankakes for a while :P

Friday, April 28, 2006

Best Fan Film Ever!

Rayan vs Dorkman must be one of the most awesome Star Wars fan films I have ever seen. Check it out!



For more info go to rayanvsdorkman.com

LaTex Annoyances

I really like LaTex. I much prefer to typset my papers, rather than manufacture them in word. But every once in a while, I find little things that make using LaTex a PITA.

For example, in my document, I have text that often needs to be repeated. For example, I need the title on the titlepage (duh), the copyright page, the signature page and etc... Same goes for actor. I spent countless hours searching how to extract data from the built in variables initialized via the standard \author and \title calls. I even emailed my old mentor in all things LaTex and he also had no clue.

So I decided to fake it:

\newcommand{\printtitle}{Title of My Paper}

Now wherever I need to put title, I just use \printtitle and I'm done. This is not a perfect solution, but it works. At least as long as you don't start nesting functions. For example if you do:

\uppercase{\printtitle}

You get lowercase letters. Why? Latex does not have a proper stack, and so nesting functions may or may not work depending on circumstances. At least that's what I have been told.

This is annoying as shit. Anyone knows the proper way to do this? I know that the answer must be locked up somewhere deap within article.cls which includes the implementation of the \maketitle call. But for the life of me, I can't decipher how to extract title and author from there.

What is a pirate?

Abso-fucking-lutely priceless!



Every time you say "piracy" when reffering to copyright infringement, you are helping to spread the RIAA's and MPAA's evil propaganda. Think about this.


Thursday, April 27, 2006

Makes you think...

Note, this video is over an hour long, but it is worth it:



Think about this stuff when you watch United 93. Is United 93 an inspirational story, or a governmental propaganda?

Everything you know about 9/11 might be a lie. Including the story of United 93. Watch the clip I posted. It really asks allot of good questions.

Wednesday, April 26, 2006

Tape Drives for $2k?

My hardware people recomend switching to a HP LTO2 tape drive for backups. I looked at their qoute, and I nearly fell off my chair. They were asking almost $2,000 just for the drive! Holy poop on a stick!

I was so shocked I actually went to HP website to verify the pricing. And yeah, it is within the ballpark. This is crazy! Absolutely in-fucking-sane. I can get a semi-decent, brand new desktop for that price! WTF! I can't understand why would these things be so damn expensive!

Why don't I just buy 5 250GB firewire drives for half the price of that drive, and use them to image my disk every day of the week?

I just don't see my boss signing off on a $2k tape drive order...

Tuesday, April 25, 2006

Latex Conditionals

If you are a graduate student, and have some sort of assistantship position I have one advice for you. Do not tell your professors that you know/enjoy/use latex. Do not talk to them about latex. If they figure out that you do use it from the superb visual quality of your written assignments they may corner you and ask you about it directly. In that case shrug, make a dumb expression and quickly change the subject/run away.

The truth is that today, most graduate students are brain-dead MS word zombies. In fact most faculty members hate non-wysiwyg stuff with a passion. So once the they spot a latex user they are going to pounce upon him, and ride him till he drops dead, or graduates (whichever comes first).

This is, ladies and gentlemen, how I got stuck making thesis templates for Dr. Antoniou who is about ready to strange me these days. I'm officially working on the templates since... Er... Sometime last semester :P

Yes, I am the undisputed king of procrastination. I could teach you all a thing or two about procrastinating to the fullest. But not today. Come back tomorrow... Or next week maybe.

What I really wanted to talk about today are the conditional statements in Latex. I just typed all this back-story to give you some background on the problem I was facing. You see, at MSU it is only possible to submit a Masters Thesis in May, August or January. Thus, I wanted to make my template automatically select the correct month.

I decided to use ifthen package to do the conditionals. The ifthenelse statement seemed to be perfect here:

\newcommand{\shorttoday}{
   \ifthenelse{\number\month<5}
   {May, }
   {
       \ifthenelse{\number\month <8}
       {August, }
       {January, }
   }
\number\year}


Now, whenever you do \shorttoday you should get an appropriate month. For example, right now it displays May. But if I change month to say December using \month 12 I will get January :)

Now my only issue is that for January I should increment the year somehow. Any tips on how to do that? So far I haven't figured out how that could be done.

Update Thu, April 27 2006, 09:57 PM

I finally figured it out:

\newcounter{theyear}
\setcounter{theyear}{\number\year}

\newcommand{\shorttoday}{
   \ifthenelse{\number\month<5}
   {May, }
   {
       \ifthenelse{\number\month <8}
       {August, }
       {\addtocounter{theyear}{1} January, }
   }
\value{theyear}}


It works :)

Saturday, April 22, 2006

Text Dumping PDF files

The other day I got a request to convert a PDF file into a text file or something that could be imported to Excel. The was essentially some big accounting mumbo-jumbo full of numbers arranged in columns with fancy headings. There were over 200 pages of it.

Now the easiest thing to do was to use the Windows version of Adobe Acrobat and simply save the file as .txt. But of course, that knocked out all the white space. All the colums run into eachother and the file looked like crap. There is no way you could do anything useful with it.

Of course my linux PDF reader (acroread) did not have the "Save as Text" option, so the first place I turned to was the nifty linux app pdftotext.

pdftotext bigstupidfile.pdf

This gives you a quick text dump which is roughly equivalent to the buit in Acrobat save behavior. But fortunately pdftotext has all kindso of nifty features. If you want to preserve the whitespace and layout details you should do:

pdftotext -layout -eol dos bigstupidfile.pdf

The -eol dos bit is there to specify the end of line style. Remember, I'm on a unix box converting this file for a windows dude who will want to import this stuff to excel.

Needles to say, the trick worked perfectly. The columns were preserved and the file looked great. So whenever you need to convert some pdf data into text I highly recommend using -layout option.

Save the Internet

Come on people, this is serious!



Let me show you how the internet works. Right now it is set up like this:
  • You pay for your own bandwidth (up and down) to an ISP
  • Google pays for it's own bandwidth
  • NSP's like AT&T and Verizon route the traffic regardless of where it is coming from

This setup works. But if AT&T, Verizon and palls have their way it will be set up this way:
  • You pay for your bandwidth
  • Google pays for its' bandwidth
  • Google pays AT&T for it's traffic to have higher priority than yours
  • Google pays Verizon for it's traffic to have higher priority than yours
  • Google pays [insert NSP name here] for it's traffic to have higher priority than yours
  • Google pays etc..
  • If google does not pay the required price, it page will transferred so slowly most surfers will think the site is down
We need network neutrality. Tiered internet is bullshit!

Friday, April 21, 2006

Arcane Java Operators

I previously posted about the nifty ?: Java operator that I personally love, but that I never see in the code. And then I realized that there are quite a few instances of Java specific stuff that no one really knows or cares about. It seems that most Java instructors these days are C++ people who read a Java book - and thus they rely heavily on their C++ experience.

And that's fine, you can really survive in Java world with a C++ like mindset (as long as you don't try to pass integers by reference). But you miss out on all nifty little language nuggets and syntactic sugar that Java has to offer.

For example, Let's say you have an ArrayList, a Vector or another Collection class. At some point you want to extract something out of it. Since you populate your collection class you know what should be in it. But what happens if someone sticks in an Integer into a Vector that should contain only Strings?

You can always do this:

try
{
    Sting foo = (String) vector.get(i);
}
catch(ClassCastException e)
{
    // error handling
}


This is IMHO a PITA. Of course Java has a much more elegant solution to a problem like that. It is the instanceof operator:

if(vector.get(i) instanceof String)
    // do something
else
    // error handling


Java will gladly let you know, what type of object you are dealing with, as long as you ask it the right way. Granted that this example is trivial, but in the long run, instanceof can save you allot of catching and handling runtime exceptions.

Operators such as instanceof or ?: do not exist in C like languages. So most C oriented Java instructors ignore them completely.

Allot of programmers do not understand the this keyword. For example most people do this:

public class Foobar
{
    private int foo, bar;

    public Foobar(int a, int b) { foo = a; bar = b; }
    public Foobar(int a) { foo = a; bar = 0; }
    public Foobar() { foo = 0; bar = 0; }
}


This is an ok code, but imagine having 5 or 8 fields to handle. It becomes real messy, really quick. What if you have 12 constructors need to change the name of bar to something else? What if you decide to initialize values to 1 instead of 0?

What you shour really do is this:

public class Foobar
{
    private final DEFAULT =0;
    private int foo, bar;

    public Foobar(int a, int b) { foo = a; bar = b; }
    public Foobar(int a) { this(a, DEFAULT); }
    public Foobar() { this(DEFAULT); }
}


This is a good coding practice from the get-go. If you ever rename your fields, or change the default initialization value, all you need to do is to edit the top constructor. If your code is written well, you rarely need ractoring tools for minor stuff like this.

I think there is simply a fundamental issue with teaching the students to use the correct tools for the right job.

I cannot tell you how many times I have seen people implementing XOR like so:

if(foo)
    foobar();
else if(bar)
    foobar();
else
    barfoo();


But Java has a perfectly good boolean exclusive or operator:

if(foo ^ bar)
    foobar();
else
    barfoo();


There is a xor operator in C, so I just see no reason why most college level programmers only use && and ||.

This is kinda like using the break on the default case of the switch statement. Code that is not wrong, but obviously redundant, or unnecessarily convoluted annoys me.

Java ?: operator

One of the least understood, and most underestimated Java language constructs is the ?: operator. Most people never even seen it in action. And those who did, never actually used it to do anything meaningful. Imagine something like this:

public generateFoo(int threshold)
{
    if(threshold > MIN_THRESHOLD)
       return new Foo();
    else
       return null;
}


In this snippet of code we have a function which generates a new Foo object if the passed argument is greater than some minimal threshold. If it is below threshold we return null. This is not an uncommon scenario... But with the ?: operator we could accomplish all of this on a single line.

public generateFoo(in threshold)
{
    return (threshold > MIN_THRESHOLD) ? new Foo() : null;
}


If you didn't catch that let me show you something simpler:

int foo = bar ? a : b;

Java expects to a boolean or an expression evaluating to a boolean before the question mark. If that expression is true, then the whole statement evaluates to a. Else it evaluates to b.

It is elegant, produces a lean code and saves you one return statement. It is a good coding practice to have one return statement per method when possible. I think more Java programmers should embrace this little syntactic sugar. It saves you allot of typing when used appropriately.

Wednesday, April 19, 2006

Barefoot Shoemaker

The keyboard on my laptop is fucked. Up and Left arrow keys simply do not work. I figured it might have been a software glitch, but they do not work at the bootloader either. It is annoying as hell, but if I hit down at the GRUB screen, I cannot go back up at all...

My solution? I figured I xmodmap some other, rarely used keys to up and left. I use an external kyboard and monitor most of the time anyway. This is my problem - they pay me for fixing other people's computers, but my own laptop is a pile of junk.

I have a broken pointer knob that sometimes short-circuits and sends signals without being touched (causing wandering mouse movements on the screen). I have a bad display that sometimes cuts off, or blooms out into multi colored jumble. And now two dead keys... But this does not bother me that much, because I know how to route around these problems. An average technophobe on the other hand, has a shit-fit every time their screen as much as blinks the wrong way :P

I should get this fixed though. It's really annoying. I just don't have fucking time to sit on the phone with Dell for 3 hours explaining to them that I just need a new keyboard. I can't figure out why don't they sell laptop keyboards on their website. The only way you can get a new keyboard is to call their parts department. And you better have a valid part number, or an open service call...

The case of the switch

Please look at the following code snippet and tell me what is wrong with it. No it contains no errors, just something really dumb that shows that the programmer does not understand the switch construct:

switch(foo)
{
     case 1:
     // do something
     break;

     case 2:
     // do something
     break;

     default:
     // do something
     break;
}


Do you see what I'm talking about? Come on, look at it!

If you couldn't spot it, shame on you. Look at the default block. Why do we have a break there? The break statement is only there to prevent rolling down the the next case. If you are in the default case, which also happens to be the last case of the switch you are done. There is nothing below default it that can be executed. There is no need to put that break there!

And yet every book, online tutorial, and example I see put it there. Who the hell stated it? Why is everyone blindly copying this pattern? Is it for consistency?

Putting a break on a default statement is not wrong. It is syntactically correct. But that does not mean it does not look dumb as hell when you do it :P

No chanel switching during commercials.

Holy Jesus Jumping Christ! WTF is this world comming to?

Philips suggests adding flags to commercial breaks to stop a viewer from changing channels until the adverts are over. The flags could also be recognised by digital video recorders, which would then disable the fast forward control while the ads are playing. via New Scientist Tech


The day they start doing this, is the day I stop paying for cable. This is the stupidest fucking thing I have seen since the unskipable DVD previews bullshit, and the broadcast flag. WTF! What if I accidentally switch to an infomercial channel? You just going to keep me there forever?

This is not going to fly with the consumers dude. You may be able to sell the broadcast flag to retarded idiots using that "pirates steal our content" joke. And hey, average Joe will not know about the broadcast flag until he tries to tape a show, or points a camcorder at the screen. But this? Hell, you don't mess with people's TV. That's just plain stupid! If a Philips device would do that to me one day, I would fucking take a hammer to it in 5 seconds flat and then I would cancel my cable subscription.

Hell, they will have to modify the Nielsen rating system stuff to accommodate this. Cause, you know - you may really want to watch Lost or 24 but you are stuck on a channel running a 20 minute infomercial that can't be skipped. To bad...

Implementation of this would be the beginning of the end of American TV industry. People would watch less TV, and download more TV shows with commercials edited out. Less and less people would get cable legally, because the a hacked illegal cable box would probably strip the "no-commercial-skip" flags off the signal.

The only winers would probably be the paid subscription channels like HBO - because this bullshit would make them even more appealing than before. They don't have commercials AND you can flip to a different channel whenever you want :P

Tuesday, April 18, 2006

Dirty Minds

Today after Programming Languages class we established that we (tech geeks) are really a bunch of horny perverts :P Only in our field, phrases like these below are considered normal and appropriate:

A floppy is good but a hard drive is better. You may also sometimes need a USB dongle.

Your web-app should have a nice front end and a solid back end. You should also avoid being rooted.

When you log into a unix machine you can finger your friends. You can also get head, and get tail (of a file), take a dump, or mount something (a drive). You may also fsck your drive :P

And apparently on a vax machine you sometimes need to anal (analyze) the drive (thanks Brian).

:P

Bush is a thief by RIAA standards

Apparently, president Bush has illegally ripped mp3's on his ipod.

President Bush's iPod contains songs by the Beatles; since no Beatles songs have been licensed for the iTunes Music Store yet, these must have come from ripped CDs. Remember last February, when the RIAA told a federal agency that ripping CDs is illegal?


Now, if you recall your lessons of RIAA doublespeak "copyright infringement" == theft. So in other words, Bush is a no good, stinking thief. No better than all the other nasty "pirates" that were sued for file sharing.

Sigh... How can our government enforce the copyright law, if even the president can't figure it out and commits blatant infringement on a daily basis?

Google Calendar > 30boxes

Google Calendar is possible the best calendaring app online at the moment. I have been playing with 30boxes lately, but the big G is much more polished and feature-full. Hell, for what I use it for it is better than Outlook, Sunbird and KCalendar combined :P

To bad for 30boxes crew - they had a solid design, and really good app. 30boxes is like the Sega Dreamcast of online calendaring apps. When it came out first, there was allot of hype around it - but then we got PS2 and Xbox and Dreamcast died. I suspect that soon Microsoft will start providing a free Outlook whatever bullshit thing to counter Gmail+Google Calendar. And then 30boxes will be marginalized completely.

Of course, the old issue still stands - every new Google app you use, gives Google more information on you. And since Google does not seem to grasp a concept of "delete", their database is a great resource for our beloved thought police government. But then again, Google already reads my emails, and catalogs my web searches (cause I'm usually logged into gmail, and hence google as I browse). Do I really care if Google knows that I have an OWL presentation next Tuesday, or that I have finals in two weeks?

Sunday, April 16, 2006

WTF Code moments...

One of my Graduate Assistant responsibilities this semester is grading homeworks for an introductory Java class. As you can imagine, I see alot of bad code. But every once in a while, I run into something really "special".

The assignment was to write a payroll class, and one of the methods should calculate employees sick days. Every employee gets 1 sick day per 75 hours worked. This is how one of the students tackled the problem:

int totalHoursWorkedTemp = totalHoursWorked;
while(totalHoursWorkedTemp > 75)
{
   totalHoursWorkedTemp = totalHoursWorkedTemp - 75;
   sickDays++;
}

return sickDays;

I was about to mark it wrong, but then I realized that this will actually do the job. Ackward, but valid solution.

I don't know... What's wrong with sickDays = totalHoursWorked/75 (integer division)? But then again, maybe I'm being a minimalist here. I should be glad that they figured out how a loop works, eh?

Saturday, April 15, 2006

The Shell is Done

I finished the Shell assignment for my OS class. All the basic requirements are met. I'm planning to play around with it some more, to add pipes, redirection, and allow user to run native apps from within. But that's just extra stuff. The assignment is technically done.

Now I can concentrate on the OWL-Lite project (10 bonus points if you know what OWL is, and 50 bonus points if you can tell me what is it good for), and grading CMPT-183 homeworks (bleh).

Happy Easter everyone!


Achtung!

Here is a random warning message which could be found on many BBS'es back in the day:

   ACHTUNG!
--------
Das machine is nicht fur gerfingerpoken und mittengrabben.
Ist easy schnappen der Sprinngwerk, blowenfusen und
poppencorken mit spitzensparken.
Ist nicht fur gewerken by das Dummkopfen. Das rubbernecken
sightseeren keepen hands in das Pockets.
Relaxen und watch das blinkenlights...


Taken from textfiles.com.

8D

Thursday, April 13, 2006

Writing a Shell

The new project in the OS class is to write a java based shell emulation. I'm excited - this sounds like a really fun assignment. In fact, it just seems a wee bit easy. All you really need to do is to parse user input and traverse the file system.

Requirements are really easy - do include equivalents of ls, mkdir, cd and date, keep history of n most recently used commands, and m most recently visited directories. Not much else. Sounds like cake...

What I really want to explore is to mimic pipes and input/output redicection, and letting the user to execute native programs by using Javas Runtime exec method. It also doesn't seem that difficult if you think about it.

Dr. Robila reccomended that those who can't figure this assignment out can allways attempt to buy code from zewrestler who was the only person in class who managed to implement this last semester. Hehe...

Wheeeee!

Best add evar:



LOL!

Wednesday, April 12, 2006

Sociology of Pornography

I read an interesting article on pornography earlier today. In it Naomi Wolf claims that the wide availability of pornography in fact contributed to lowering of male libido in recent years.

Sigh... We should really require all these Sociology and Anthropology specialists to take a Statistics class or two at some point during their college career. If I had a penny for every time someone scores an article after making huge generalizations, based on logical fallacy I would be so rich, that I would hire Bill Gates to clean my toilet :P

You see, the name of the game here is Correlation vs Causality. Everyone who majored in science knows that Correlation ≠ Causality. To prove anything in science, you need to show the causality relationship. Correlation is absolutely meaningless.

But people in Humanities, and Business related fields usually have a shaky grasp of science. Thus if you are doing anthropology or sociology research, all you need to do is to identify a correlation. The more obvious is the correlation, the better. Once you have one, you can start making big generalizations and draw baseless conclusions.

This is also the case with this article. Did Ms. Wolf do a controlled long term study of effects of porn on relationships? Hell no, she simply assumed that since we have better access to porn these days, it must be affecting people's relationships. She based this conclusion based on conversations with college students and different couples.

There was no scientific approach, no rigorous data collection, no control group. Naomi Wolf simply talked to few people, and decided that porn makes people unhappy. She doesn't even try to hide the bias. She asked people loaded questions, which were constructed to support her conclusion irregardless of the response. Most of their conclusions are derived from her personal experiences as a middle-aged woman. Abso-fucking-lutely brilliant.

I believe that the lowering of male libido that she talks about is an illusion created by changing of sexual norms in todays society. Yes, we are much more open about sexuality now. But at the same time, we developed the notion of political correctness, tolerance and professionalism.

It is a huge oversimplification to say that pornography has any effect on relationships, male libido, or anything at all. This is the same as saying that video games cause violence. Or that alcohol causes violence and inflates that crime rate. Prohibition proved that we were wrong about that one. Why do people think that this is different in case of video games and porn???

Again, we need hard evidence supported by controlled tests, and clinical studies. We need reliable results that are possible to verify. Otherwise we are just playing the "what if" game. What if porn is bad for relationships? What if video games cause violence? And what if they do not?

I call bullshit on this article. "Men are less able to connect erotically to women" my ass lady! Show me some hard evidence for this? Selectively interviewing repressed girls who are disappointed with their sex lives, or undereducated, stoners who have no clue about life does not count as evidence. It is coincidental correlation.

Naomi Wolf likes romantic tension and mystery. An undergrad guy from Northwestern on the other hand seems to prefer close intimacy without the awkward tension, and second guessing your partner. Personal preference? Generation gap? Both? No, of course not. The fact that some random guy does not share Naomi Wolf's sexual preferences must be a proof that evil porn corrupted his mind.

Give me a fucking break!

Monday, April 10, 2006

How to pull an all-Nighter?

I was reading Lifehacker, and I found this article about pulling all-nighters. It's all nice and dandy but there is nothing in that article that wouldn't be common sense, and self explanatory.

What is the point of giving advice such as: when you are sleepy, don't like down, take a cold shower, walk around or drink coffee/tea. No shit sherlock!

The truth is - pulling an all-nighter is not difficult. Staying up should not be all difficult unless you are 5 and it's Christmas Eve :P

What is difficult is coping with prolonged sleep deprivation and sleep debt. When you pull an-all nighter, you most likely need to go to school/work the next day. Hell, you might be forced to work late night hours the very same day. Thus you may not be able to "catch up" on sleep till the weekend or something like that.

You will likely accumulate sleep debt, and you will get progressively more exhausted and fatigued every day.

It all really depends on your natural resistance, physical condition and etc. Everyone is affected differently. A stand alone all-nighter is usually harmless, especially if you are young and fit. But when it is followed by several late night coding sessions (or another all-nighter down the road), even the toughest, meanest hard core coffe chugging hacker can start to suffer from sleep deprivation symptoms.

First, and most important tip for those who pull an all-nighter is: try not to not drive the next day. Especially in the evening. Beware of the microsleep lapses. They can be extremely dangerous when you are behind the wheel. The worst part is that you can't control these - your brain simply switches off for a moment.

Most people are not even aware they fall asleep this way. You go from fully awake, to out cold to fully awake again in under a minute. To you it may seem like you "spaced out" for a second but most likely you just had a microsleep lapse. A minute is enough time to drive into a ditch, or hit a tree. So be careful.

Second, be aware of the "Undead" syndrome. This is where you turn into a living zombie and you sit at your desk staring at your monitor for a good hour or two. Your mind will wander, and generally work in low gear. Are sharp like a razor in the morning, chances are that by lunchtime you will turn into a barely coherent, spaced out lump of flesh. Your concentration will suffer, and getting into "the zone" will be twice or three times as difficult as usual. Every time you get interrupted you will be knocked out off the flow, and it will take you a while before you can resume work at your normal pace. This is normal.

Third, Caffeine rush is to be expected. See, you were up all night drinking coffee and soda. Now you are at work/school drinking more of it to keep yourself awake. You should expect to be unusually hyper. You may also be moody, fidgety, irritated or even anxious. And you will crash eventually. Caffeine crash may range from a total physical shutdown to a mild downer. It usually manifests itself as energy drain. At some point you just stop fidgeting, and you slump down into a near coma. You may experience extreme fatigue, muscle pains, dry mouth, headache and etc. The severity of the rush, and subsequent crash of course depend on the amount of caffeine you ingest. If you just drink coffee or soda you will likely experience only a mild crash.

If you are into Jolt Cola, energy drinks, caffeinated mints and Caffeinated soap - and you use them in excessively during your all-nighter and the day after... Well, you will feel like shit when you crash.

I recommend sticking to your regular amounts of caffeine. You really don't need 7 coffees, and 10 Red Bull's and a pack of coke to stay awake all night. If you don't go overboard you may avoid the caffeine rush, and the subsequent crash.

And lastly, long term abuse of your circadian rhythms will affect your sleep patterns. If you pull many all-nighters, your body will try to adapt to all this late night activity. So once you go back to normal sleeping pattern, you may find it difficult to fall asleep even when you are very tired. You may find yourself tossing and turning till 4am for few days/weeks until your cyrcadians return to normal. This is to be expected :P

Please note that IANAD - most of this is from personal experience, and stuff that I heard from others.

Sunday, April 09, 2006

The cost of elegant code...

There are essentially two ways to code:
  • Elegantly
  • Optimally

Elegant code, is usually well structured, object oriented and human readable. Blocks of code are neatly divided into meaningfully named methods. All the methods are atomic (ie. they accomplish only one clearly defined task), and encapsulation is complete. All the data is contained in meaningful data structures which have elegant accessors and mutator methods, iterators and etc... Such code is a joy to work with, and a pleasure to maintain. It also runs slow as shit flowing up the river.

Optimal code, is an ugly kludge. It is a nasty hack which lumps everything together. Method calls are computationally expensive, so the optimal code will usually consist of one method which does everything. There will be 8 different, completely unrelated things going on in a single loop (because you want to limit your iteration time). All the data is contained in arrays (preferably single dimension arrays). This code is butt ugly, but runs fast.

I am currently in the process of converting my "elegant" code to something more "optimal". The code is getting less readable and confusing by the minute. But you have to do, what you have to do.

This makes me think though - is it even possible to write "critical" code in an elegant way? We always joke about how bad coding practices introduce bugs that can be avoided. But if you are forced to optimize the shit out of your semi-elegant, program you end up shaving off allot of important stuff. Encapsulation and atomicity are the first things to go - and those are staples of OO paradigm...

Sometime bad code is necessary. This is not an excuse to write a, buggy code of course. But next time I find an ugly hackish code, I will first check if it is and optimized "speedcode" before I start complaining or refactoring.

Saturday, April 08, 2006

Bad News

This one cracks me up every time:




It might be old, I don't know - but it's funny.



Friday, April 07, 2006

Science and Religion

Can we please establish something once and for all:

Science ∩ Religion = ∅


I might be one of the very few people who think this way, but I believe this to be true. Religion and Science are mutually exclusive. One is concerned with hard logic, and furthering understanding this physical universe we inhabit. The other deals with spiritual growth, and the metaphysical.

I don't get the whole creationist and Intelligent Design movement. Can someone explain to these people that the book of Genesis is an allegory? The biblical story of creation is like a PG-13 version of the history of the universe - with all the mind boggling physics, chemistry and biology details replaced by fluff. Kinda like the "birds and the bees" story you would give to kindergarten kids if they asked.

Before I moved to US I have never encountered this kind of rabidly literal interpretation of the Bible. We already had this dispute a while ago, when Charles Darwin was proving his theory. At some point the Church backed off, and accepted evolution. We all agreed this was a moot point and that there is no need to argue about this anymore.

Somehow we all understood that in religion class (yes, in Poland there is no strong separation of Church and State so religion is part of the public school curriculum) we talk about Adam and Eve, the Garden of Eden and the Great Flood, while in a science class we talk about the Big Bang theory, dinosaurs and evolution. We allways thought about them as separate, and mutually exclusive. It would have never occurred to me that both can't coexist until I came to US.

Sigh... Don't the creationists, and intelligent design people realize they are the laughing stock of the world?

When a creationist approaches me, I usually don't even bother talking about science. Intelligent arguments do not work well against blind zealotry. So I talk about pastafarianism, which is about as scientific as the "inteligent design theory".

Lucent Sues MS over 360 patent infringment

Ha ha! Apparently Xbox 360 violates Lucent's patent on MPEG-2 encoding. They want MS to pay up or recall all the boxes from the market.

Didn't they just settle with Eolas not so long ago?

Doesn't this make Sony another logical target once PS3 boxes hit the stores?

The good thing here is that Lucent seems to be in this for money. So they probably will not go after open source projects which free media players and etc. There is simply no money there, and it's not like they are competitive in the media player market either.

Repeat after me: "software patents are bad, mmkey."

Wednesday, April 05, 2006

Convert a large Access table into Excel files

I got an unusual request today. Someone sent me an Access file, asking to convert it to Excel. Why? I don't know, I guess people are confused by the database stuff or something. I looked at the file, and figured this would be simple. There was only a single table in the DB.

I had one problem though - the table had over 400k records. An Excel worksheet can take only around 65,536 rows. It's a design choice they made - and you have to deal with it. The export feature in Access however does not take this into account. If the table has more rows than the worksheet can accept it simply discards all the remaining entries and gives you an error message.

I really don't get this. Excel and Access are both part of the same Office Suite. They were likely developed by the same team/department/group. How come no one ever caught this? What is the point of having the export feature if it doesn't work half the time?

Fortunately you can export it to other formats, for example tab delimited text file. I like text files. Text files are easy to process. Hell, text files are absolutely trivial to process - unless of course you are a windows user.

So I exported the DB into a text file, copied it over to my Kubuntu laptop and did this:

$split -l 65536 my_file.txt

Now I had 7 tab delimited text files that could be easily imported into Excel.

That was easy! Easy as π!

Coding AJAXified pages drives me nuts!

The little inconsistencies between the way IE, and Firefox handle various DOM requests will drive me mad one day. Why can't we just all code to the standard? :(

For example, I wanted to have a collapsible table which displays list of entries. You click on a 'remove' checkbox next to one entry, and it goes away as the table neatly collapses to fill in the gap. In the background you have asynchronous call to remove this row from the db. One would think that the hardest part would be the db call. But that was easy!

First you create the http request object:

request_o = new ActiveXObject("Microsoft.XMLHTTP"); // IE
request_o = new XMLHttpRequest(); // everyone else


Then I send a post request to a php script (here aptly named ajax_request_handler.php..

request_o.open('post', 'ajax_request_handler.php');
request_o.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request_o.http.send('rowid=' + rowid);


This works like an oridinary post request from a web form (ie. php can access the sent value via $_POST["rowid"]).

At this point I don't care about error handling. If there was some error then the php script will fail quietly and no harm is done.

The hard part was collapsing the table! What I initially did is I marked the tr tags with id's representing row numbers:

<tr id="row_1"> ... </tr>

Then I have onChange javascript call to handle the reformatting and AJAX call:

<input type='checkbox' name='remove' onChange='removeRow("row_1");'>

I implement this function in Javascript:

function removeRow(rowid)
{
document.getElementByID(rowid).innerHTML="";
}


So in effect the contents of the <ltr> tag are set to an empty string. Should work, eh? It did work but only on IE! FF refused to cooperate - and I'm not sure why. I know that the browser does implement the innerHTML property. I could for example grab all the code inside the <tr> tag but I could not erease it. Any clue why?

After several hours of agonizing over this, and constant browser flipping (fix some code, test in IE, test in FF, fix some code, etc...) I gave up and decided to change approach. Instead of removing the information, I would just hide it:

document.getElementByID(rowid).style.display="none";

This is not necessarily what I initially had in mind but it works in both browsers. Good enough for me. When the user refreshes the page the hidden entries will be gone anyway, because they were removed from the DB via AJAX call.

Of course, it was still far from perfect. FF and IE handle the onChange attribute differently! In FF, when I click on the checkbox the entry is removed and collapsed immediately. In IE however it sticks around. I have to click on the checkbox, and then click on something else for onChange to be registered. Gah!

I didn't know that. I don't use fucking IE! I thought that for checkboxes onChange is handled the same way as onClick - immidiately. I guess MS developers thought differently. So I changed my onChange to onClick just to be consistent.

So far everything seems to work correctly. Sigh.. Why does client side coding have to be so painful?

Tuesday, April 04, 2006

It's pronounced Au-then-ti-ca-tion

Can I ask a question? Is it really that difficult to pronounce the word authentication? Seriously! I don't know. I have a little bit of an accent going, so I do not always pronounce things the right way. For example, when I say multi-threaded it kindoff comes out sounding like the infamous "Multipas" from the Fifth Element most of the time :P

Saying "thirty three" kills me every single time. You sneaky English people with your soft r's and your "th" sounds. I get it wrong 90% of the time :P

So I usually do not make fun of people mispronouncing words (unless they happen to be the president of the united states - you have no excuse then), especially when they speak with an accent. But most people I work with are native English speakers - and yet they can never pronounce authentication.

Even if I say it first:

Me: "Now check Outgoing server requires authentication"
Luser: "server requires au... au.. authentification... ok, checked"

Really! It's pronounced au-then-ti-ca-tion! Much easier than 33 in my opinion! I mean it's not like I'm making you say for example: "w szczebrzeszynie chrząszcz brzmi w trzcinie" or "konstantynopolitaƄczykowianeczka".

Gmail Manager Firefox Extension B0rked

If you use the Gmail Manager extension for Firefox you probably have noticed that it could not log in today. It appears that Google has changed something with their protocol again.

However, the newest version 0.4.3.5 (dated for April 3rd) fixes this. I upgraded, and I'm able to receive gmail notifications again. I kinda felt disconnected without that little icon showing me how many emails I got so far.

Todd Long is the man! He fixed the extension the same day Google broke it! Wohoo!

Thank's Todd!

Monday, April 03, 2006

Inuyasha = DragonBall-Z for Girls LOL

Image: VGCats disses Inuyasha
Hehehe! It so is DragonBall-Z for girls! LOLOL!

My brother was always a big Ranma fan, so I kindoff got suckered into watching Inuyasha on the account off "hey, this was done by Rumiko Takashi". What's funny, is that when you think about it, you can do almost 1:1 mapping of Ranma characters to Inuyasha characters. Just try it:

Ranma = Inuyasha
Akane = Kogome
Ryoga = Koga
Happosai = Totosai/Myoga
and etc..

If you never saw the show, here is what you need to know: Inuyasha is a guy with a Really Big Sword™ which can deliver a single devastating super move that can kill a 100 daemons in one go. He keeps winning with daemons that are much more powerful than him simply using that one move (he gets like upgrades to the move later on, but it's still basically the same damn thing). Then there is some questing plot line (searching for sacred jewel shards), and a classic shipper bent for girls (think Inuyasha is to Kogome as Moulder is to Scully or John Crichton is to Aeryn Sun). So yes, DragonBall-Z for girls kinda sums it up pretty well :P

Strangely enough, I find it more watchable than Dragonball - perhaps because Inuyasha lacks those super powerful individuals that can destroy planets with a fart. Or perhaps because most of Inuyasha combat scenes do not streach longer than 1-2 episodes. Sooner or later every villain gets a Wind Scar (Inuyasha's main super move) in the face, and dies. Consistency, ladies and gentlemen is they key :P

Of course if you were to choose, I would say watch Fullmetal Alchemist instead of Inuyasha. Fullmetal is simply much better, and more original show. Not mentioning Evangelion - which is in a league of it's own.

Code Segments in Latex

Whenever I copy and paste some code segments into my Latex documents, the verbatim environment eats my tabs. Apparently it is a feature, so I usually make my text editor convert tabs to n spaces before I import or copy the code into Kile. But that's annoying as hell!

The other day I found a simple and elegant solution. Use moreverb package. Somewhere at the beginning of the document do:

\usepackage{moreverb}

Then, instead of using normal verbatim environment do:

\begin{verbatimtab}
% code with tabs
\end{verbatimtab}


Easy as pie! The only downside - Kile does not consider verbatimtab to be a verbatim like environment so it does not highlight the text inside a different color like it does for standard verbatim blocks. But that's a small price to pay for the added convenience.



MPAA still doesn't get it.

This is priceless. zewrestler told me about it this morning, and now I just found this on boingboing. Apparently MPAA intends to sell movie downloads for twice the price of a DVD. of course we are talking about a DRM, crippled, windows only versions.

Brilliant! Abso-fucking-lutely brilliant! This will definitely put a stop to all that illegal downloading. After all, a free, uncrippled, platform independent version can't compete with a locked down, super-expensive, windows-ony one... Er, wait...

Seriously, who does market research for these people? Do they even do market research at all? If they would offer the movies at 1/2 price of the DVD on account of the stupid DRM cripplage then maybe they would get some buyers.

Let me spell it for you: iTunes! The reason why they are so popular is because the songs seem to be cheap! They are not, but for an average Joe 99 cents for a crippled song sounds reasonable. In the same way, $5 for a crippled movie sounds semi-decent. Think about it - after you pay off costs of online distribution (which is incredibly cheap - you will usually pay a flat monthly fee for hosting and maintenance and bandwidth) it's pure profit. They already did a killing in the box office, profited from DVD sales - and etc.. Online sales are just free cash for them.

But no... Free cash is not enough. They want to sell you downloads for twice the cost of the DVD even though it costs them less than a quarter of the DVD price to host it.

Ladies and gentlemen - this is exactly how corporate greed kills business. Sigh...

Sunday, April 02, 2006

Matlab vs Java

This SUCKS balls! I was at school today, trying to run my NMF algorithm on a 4MB image file. I started running the test around 12pm - it was chugging along happily as I was working on my Programming Languages homework (which is crazy btw).

I left at 6, and my program was still running. That's 6 hours and counting. What's funny is that Dr. Robila implemented the same algo in Matlab and it processed the very same image in under 5 minutes. Aaaagh!

Of course you need to take into consideration that in Matlab matrix multiplication, or a transpose is accomplished with a single operator. This means that there are years of tweaking, and anal optimization behind each of these. I'm doing all of this using loops, and my data is stored in Java's DataBuffers. This means that every access is a function call.

I'm thinking about optimizing this using arrays. I will have to look into how much faster is it to access an element of a multidimensional array, as opposed to accessing an element of a DataBuffer. Perhaps it is not even worth bothering, as Java arrays are sort-of-objects anyway.

If that damn JDS machine freezes before finishing this 6+ hour run, I will take a fucking baseball bat to it or something :P I better see some results tomorrow!

Online Calculator Which Works

Yeah, I know that there is always google to calculate stuff online, but calcr is done with AJAX! This means no waiting for page to reload to see the result!

These guys learned their web design style from Google too - the page is minimalistic, clean and spiffy. It looks really, really simple, but there has to be allot of AJAX code underneath. I love it.

My only suggestion would be - allow the users to pick between degrees/radians for the trig functions. Other than that, it is really neat web app.

Of course I lately do most of my calculations in Octave. I'm continually amazed how much functionality does that environment have. It kicks the shit out of the good old bc :P

Time.gov fears DDOS during Daylight Savings switch?

time.gov ph34rz DDOS
I don't trust any clocks today. This is what happens when some of your clocks roll over to daylight savings automatically, and some do not. My alarm clock didn't, but my cell phone, laptop, desktop and VCR did. So today whenever check the time, I wonder if this particular clock rolls over automatically or not.

So just to be sure I popped over to time.gov, and this is what I saw (see the screenshot). Apparently, they disable the usual animated clock on the switch days fearing a massive DDOS from time confused citizenry :P This is gay. Hire a better sysadmin people - preferably one that knows a little bit about load balancing, and high traffic management. And if that's not enough, beef up your server for god's sake!

It is a damn shame to see a very popular and useful governmental site removing features during high-traffic days. It kindoff indicates a piss-poor hardware and/or maintenance. This means that theoretically time.gov could be slashdoted, farked or simply DDOS'ed by some script kiddie. And this is just ridiculous. It makes you wonder where your taxes are going...

Ghostly Farts in the Shell

I was sitting here, at my computer doing some stuff and Ghost in the Shell: Standalone Complex was playing in the background. My brother was in the same room playing some game. All of a sudden, he started asking me if I heard farting noises. I told him that he is hearing things. :P

But then I also started hearing them. We started looking around the room and we finally realized that the noises are coming from the TV. But why on earth would there be farting noises on Ghost in the Shell? I started paying attention to the show, and whenever someone bent over or made a silly face there was an audible fart effect. WTF?

For few minutes we were watching this, and we could not believe that this was going on. Then I looked at the calendar, and I realized that it was April Fools :P Way to go [adult-swim]! LOL I completely forgot about April Fools!

As a side note, if I knew what was going on, I would play along and keep telling my brother that he is hearing shit. For a minute there he was actually thinking that he was loosing his mind. hehe

This went till the end of the episode. They also kept farting throughout Fullmetal Alchemist. I found it amusing at first, then absolutely hilarious, then annoying, then hilarious again. Finally, it just got plain old boring. I think they stopped it at midnight or something...

They also aired a Chuck Norris and Mr. T cartoons. LOL