elblogg

blah, blah, blag, blog

Archive for the ‘english’ Category

Moving… internet

Monday, November 17th, 2008

So, we bought a new apartment. Before we bought it I checked that CanalDigital could offer both TV and Internet to the new apartment. And, according to them, then, they could.

Today however, after making three attempts to get through to them I was told that they now could only offer TV. That means I have to go back to the stoneage-performing ADSL technology. Sigh!

To top this, CanalDigital requires a two month notice on terminating a broadband subscription, and three months to terminate a TV subscription. And, even further, if you move your tv subscription they are counting that as a new subscription, which mean you’ll have to pay for two tv subscriptions for three months.

And, moving to another ISP has some costs in itself. Since there are no operational telephone in the apartment, Nextgentel charges NOK 499,- to enable the telephone line, and additionaly NOK 60,- each month to keep it open. Nextgentel is cheaper on the monthly subscription charge, so the monthly NOK 60,- doesn’t matter that much. But the reduction of 2Mbits of outbound speed matters. And, ADSL has generally a lower quality of service than cable…

Did I mention that CanalDigital probably charges for enabling TV in the new apartment as well? Sigh!

Static typing VS. Unit tests

Sunday, November 16th, 2008

Okay. It’s kind of stupid to put static typing up against Unit tests. Even so, lots of people does so a lot of times in the discussion between dynamic and static programming languages.

Static typing provides you with a security net when it comes to typos. Alhough, it doesn’t give you any security against logical errors.

(more…)

Blog meme: Phrase From Nearest Book

Friday, November 14th, 2008

I spotted this meme on Steve Holden’s blog.

  • Grab the nearest book.
  • Open it to page 56.
  • Find the fifth sentence.
  • Post the text of the sentence in your journal along with these instructions.
  • Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

So. In my case, the closest book to me when writing this post was Python phrasebook by Brad Dayley.

The fifth sentence on page 56 is as follows:

Defining a list in Python is a simple matter of assigning a number of Python objects to a variable name using the = operator.

So now you know.

Sounds familiar….

Thursday, November 13th, 2008

So familiar its (almost) not even funny…
Dilbert.com

ref last weeks post (2)

the right tool for the job

Wednesday, November 12th, 2008

So, you’re going to parse a webpage, to extract some information. For instance if you want to get the tracking information for your last online order, and you want to display the tracking information changes using growl, dbus notifications or xosd.
You know regular expressions, so you go to the job with your long range missiles ready. But wait a minute, you’ll probably solve the problem but is regular expressions really the right tool?
The pro for regular expressions is that you can use the same tool you always use for parsing jobs, but then again you doesn’t learn anything new out of this. You might fortify your position as regex wizard even more, but how about something completely different?

Now. Most webpages is written in HTML, and some even in XHTML, for HTML documents languages like Python has a built-in parser, after the model of the SAX-parser. (It’s probably the other way around, the SAX parser is built on the base of the HTML parser…) Most programming languages has good support for XML, so for XHTML documents, you can use the HTML-parser, a SAX-parser or even the XML-DOM parsers.

The benefit of doing it this way is that your parser will probably be more robust to minor changes in the webpage. You don’t reinvent the wheel (The best way I’ve found to parse HTML documents using regular expressions is to make a specialized SAX-like parser anyway). Your code will probably be readable in a year, and others might even be able to understand your code. And finally, you learn something new, which might give you a fresh view on a lot of problems.

Now back to the original issue, to make a parser for the parcel tracking of your postal service. Here’s an example parsing the shipment tracking page of posten, the norwegian postal service.

(more…)

Unit tests saves the day

Monday, November 10th, 2008

Currently I’m developing a webservice interface for queue handling in Asterisk towards another company, that is developing a CRM solution which will utilize my webservice for Computer Telephony Integration (CTI).

So, today the developer in the other company got such an understanding of the service that he started suggesting changes. A lot of changes in the DTD etc. These changes would imply some changes in the architecture downwards in the system. It is quite scary to start tearing things apart, when you already got something working. That is, if you don’t have a large amount of unittests.

Luckily I had good unittest coverage. So changing stuff was really just a matter of changing the tests, do fit the proposed changes. Test to see where I needed to change something. Do the changes and run the tests again.

It feels very good to have proper knowledge that everything actually works properly after a refactoring like this.

Unit testing is like love. It’ll keep you going when everything else fails. (citation)

So, what’s wrong, really…

Friday, November 7th, 2008

As you can see I ran memtest86+ yesterday, and it gave me lots of errors. However something wasn’t smelling right, so I thought I’d run the same test on two other macbooks and one PC. The PC was clean, but both the macbooks apparently had exactly the same bugs as mine. So, it seems memtest86+ isn’t really macbook compatible. Memtest86 wouldn’t even boot. It might maybe be better if memtest86+ also wouldn’t boot instead of giving me false errors.

However. There’s something wrong with the machine, it’s slow, it crashes, it has sudden reboots. It even has strange graphical artifacts on the screen and the operating temperature is about 85 degrees celsius.

Should have guessed it

Wednesday, November 5th, 2008

I have sort of a love/hate relationship with Python, the programming language. Coming from PHP and Java which both have excellent documentation, while lots can be said about the solutions. With Python 2.6 the documentation really has improved, but its still not really there, while the solutions are so elegant that the only reason you don’t guess how to do stuff is that it feels too simple.

Today I had one of these realizations, while reading Wayne’s snippet of the day.

Python has a really nice list-generation scheme, so you can generate lists of the content you want from another list of object with only one line of code.

Example:

  1. >>> from math import floor
  2. >>> a = [1.5, 1.9, 2.5, 3.1, 5.7]
  3. >>> b = [floor(i) for i in a]
  4. >>> print b
  5. [1.0, 1.0, 2.0, 3.0, 5.0]

Here I generated a list of whole numbers from a list of non-whole numbers.

Now We’ll take this further.
Lets say we want to filter the list, so we’ll only get the numbers that satisfy 1<=x<2.

We could do this using filter() and lambda functions. Which is totally OK. It’ll make Python newbies totally confused (which it did with me until recently, when I realized what lambda functions really are (I’ll get back to this)), but it’ll work nicely.

But wouldn’t it be nice if we could use the same list generation scheme for this as well?
Guess what. You can!

  1. >>> a = [1.5, 1.9, 2.5, 3.1, 5.7]
  2. >>> b = [i for i in a if 1<=i and i<2]
  3. >>> print b
  4. [1.5, 1.9]

Doing the same using filter and a lambda function will look like this

  1. >>> a = [1.5, 1.9, 2.5, 3.1, 5.7]
  2. >>> b = filter(lambda x: 1<=x and x<2, a)
  3. >>> print b
  4. [1.5, 1.9]

and without using a lambda function:

  1. >>> def myfilter(x):
  2. >>>     return x: 1<=x and x<2
  3. >>> a = [1.5, 1.9, 2.5, 3.1, 5.7]
  4. >>> b = filter(myfilter, a)
  5. >>> print b
  6. [1.5, 1.9]

All of these will work equally fine, and none of them is very hard to understand, as long as you keep in mind that lambda functions just are like anonymous functions/classes.

But there is something very facinating with the elegance and simplicity in the syntax of the list generator snippet.

Nigeria spam

Thursday, October 30th, 2008

I has it.

Got this in my mail today:

Good day my friend,

I have a proposal for you - this however is not mandatory nor will I in any manner compel you to honor against your will. I am 50, and work with a bank (one of the African leading banks in the West Coast). Here in this bank existed a dormant account for the past 8 years which belong to a American national who is now late Mr. Raymond Beck Mrs. Dorene Beck who died on Egypt Air Flight 990
http://news.bbc.co.uk/1/hi/world/americas/502503.stm

When I discovered that there had been no deposits or withdrawals from this account for this long period, I decided to carry out a system investigation and discovered that, none of the family member nor any relation of the late person is aware of this account. This is the story in a nutshell. Now I want an account overseas where the bank will transfer these funds.

Thereafter, I had planned to destroy all related documents for this account. It is a careful network and for the past eleven months, I have worked out everything to ensure a hitch-free operation.

The amount is not so much at the moment and plus all the accumulated
Interest the balance in this account stands at-(US$ 9.5 million US dollars).

Now our questions are-

1. Can you handle this project?
2. Can I give you this trust?
3. What will be your commission?

If you can sponsor this transfer, consider this and get back to me as soon as possible.

Finally, it is my humble prayer that the information as contained herein be accorded the necessary attention, urgency as well as the secrecy it deserves. I Expect your urgent response if you can handle this project. Call me at this direct line +XXX-XXXXXX-XXXXXX after sending a mail for confirmation.

Respectfully yours,

Mr. Moses Dante.

And ofcourse this was sent from an Yahoo Email account

Understanding CSS positioning

Monday, May 26th, 2008

I just discovered this fine article series on CSS positioning via del.icio.us. It should be a good read for everyone interested in the subject, from total CSS newbies to people that has a great understanding of CSS already.

  • Part 1 - Covers “display” and “position”
  • Part 2 - Covers more “display”, “overflow” and “float/clear”
  • Part 3 - some CSS3 stuff…