2010-12-31

Strange NaN

Javascript uses NaN in a not so obvious way. Any equality test involving NaN will always return false, even if you compare it to itself.

var k = parseInt("abc");
if(k != k){
   document.write("Strange comparison, k might be NaN");
}

2010-11-30

JavaScript Booklet

I have compiled a small booklet with the posts on this blog about JavaScript. In the booklet you can see also the code behind the scene that you can usually see only when you look at the source of the page where the post is viewed.

View it on box.net, here, or on scribd.com, here, or on docs.google.com, here.

2010-10-17

Just a kid

Loading...

2010-09-18

Animated Logo

See my new animated logo on YouTube:


2010-09-08

Tricksy

Question:  What does the following pascal code do?
Answer:  Absolutely nothing.

program test;
begin
{var s='test}end.';
 write(s);
}
write('ok');
end.
Why?

The first impression will be that the code will display the text ok because the rest is a pascal comment inside accolades. But the compiler, after an opening accolade, looks for the closing one, and doesn't care where it is. Therefore it doesn't matter that in this case the closing accolade is in the string literal, the comment ends there. The code is then compiled from that point on, the special keyword end is found followed by a dot, and the program ends. The compiler will then warn that there is source code that will never be reached.

The code executed is:

program test;
begin
{var s='test}
end.

2010-07-17

Child DIV with JavaScript

Below is a div with the border dashed and using javascript a new div is added as its child. Internet Explorer is a bit different from Firefox and the others when it comes to this DOM action. I took style information from here.

2010-07-01

Some English

CCD Neamt has a guy on their first page that said something about education. Unfortunately the translation from Romanian to English is excruciating. I'm not an English guru or something, but look here how bad the translation is:
You tell it's tiring to be with children. You are right. And add: because you have to descend to their level, to bend, to incline, to bow, to lessen. Here you are wrong. Not this is what makes you most tired, but that you're bound to get the height of their feelings, to lie, to lengthen, to get up the toes, to not hurt them.

From original Romanian this text should sound something like this:
You say it's exhausting to be near children. You are right. And then you add: Because you have to descend to their level, to bend, to incline, to flex, to lessen yourself. Here you are wrong. This is not what exhaust you the most, but the fact you're bound to get to the height of their feelings, to stretch, to lengthen, to get up your toes, to not hurt them.

I guess the confusion of words comes from the fact that many Romanian to English dictionaries list a whole pile of synonyms for a given word and for someone who is not familiar with the terms it's difficult to choose the right translation. When I've started to learn English this issue was one I got into myself.

Let's enjoy another beautiful translation from the aforementioned site:
Personal and professional development of teachers is the main key to make children love coming to school. It is in our power to make "capital children dance"!

Should be something like:
Personal and professional achievement of teachers is the main key to make children to love coming to school. It is in our power to make "children's potential dance"!

2010-06-28

Molehill Empire

Am găsit un joc pe internet din întâmplare. Se numeşte Molehill Empire şi trebuie să dezvolţi o grădină. Un screenshot este mai jos.

2010-06-09

The Ten Sausages

The wife of a programmer told him: Please go to the market and if you find ten eggs, buy them, otherwise buy some sausage. The programmer returned home with ten sausages.

What went wrong... You never know how a condition sounds in a programmer's head.

For the geek:
Because the quantity of the sausages is not well defined in the request, the following two algorithms solve the problem correctly, although the result is unexpected for the first one.

for i=1 to 10 do
if exist 10 eggs then buy egg
else buy sausage

if exist 10 eggs then
for i=1 to 10 do buy egg
else buy sausage

2010-06-07

Exercise

Write a program that generates a random permutation of the numbers between 1 and n, where n is given by the user.

2010-05-22

Netbeans trick

If you update the JDK version, Netbeans 6.8 start bugging about the fact it doesn't find the JDK where it used to be. Instead of uninstalling just for this minor glitch, go to C:\Program Files\NetBeans 6.8\etc\, open the file netbeans.conf, find the line containing netbeans_jdkhome= and type the correct path to the new JDK (something like netbeans_jdkhome="C:\Program Files\Java\jdk1.6.0_20"). That's it.

Free photos


A site with free photos

It is hard to find a site that offers a large collection of high definition photos for free. I have found Stock.XCHNG, a site that requires you to be registered to download the photos, but the registration is free.

2010-05-15

Cool sites

Recently I have found out a bunch of sites that seem cool enough.
First one on this list is Smart.fm a site that try to make you learn something new. I will try some Japanese there.
Second on this short list is Groove Shark, a place where anyone can listen to music, make play lists and even upload their own mp3 files.
Finally is My DataNest a site where you can upload any file and have a hot link to it. To prove this I gone wild and I've added the following Java applet in this post:
You have

2010-05-02

Pârjoale moldoveneşti

Ingrediente: 750g carne macră, 1 ceapă mijlocie, o felie de pâine, 1 morcov, 1 cartof, 1 ou (sau o lingură de făină), sare, piper, verdeaţă tocată, 2 linguri de pesmet, 100g untură.

Mod de preparare: Pârjoalele se pot prepara din carne de vacă, de porc sau de miel (sau amestec). Se toacă carnea şi ceapa şi miezul de la o felie de pâine înmuiată în lapte. În cazul în care carnea nu este grasă, se adaugă 1-2 linguri de jumări date şi ele prin maşină. Ca să fie pârjoalele mai fragede se pot adăuga un morcov şi un cartof crud, care se trec prin maşină odată cu carnea. Se adaugă un ou, sare, un praf de piper, puţin pătrunjel sau mărar tocat fin. Se amestecă cu o lingură de lemn. Separat, pe un tocător avem pregătit pesmetul. Se ia cu lingura din tocătură, se fac perişoare rotunde care se trec prin pesmet şi apoi se turtesc. Se pune untura într-o tigaie la foc şi când este bine încinsă, se prăjesc pârjoalele pe o parte şi pe alta.

2010-02-21

Spendings

Some terminology I like to use:
  1. Flow represents the equivalent value of money.
  2. Income represents a positive flow.
  3. Debt represents a negative flow.
  4. Loan represents a variance in flow.
  5. Loan In represents a positive flow variance.
  6. Loan Out represents a negative flow variance.
  7. Goal represents a boundary used for flow control.
  8. Balance represents a calculus used in flow control.
  9. Spending represents an exchange of flow for an object with the equivalent value.
  10. Saving represents a flow that was not exchanged according to schedule.
  11. Reserve represents a flow retained for a later schedule. 
Now, let's show some formulas:
  • Income Balance = add all corresponding subcategories with positive values 
  • Debt Balance = add all corresponding subcategories with positive values
  • Loan In Balance = Loan From + Return To, where
  • Loan From = add all corresponding subcategories with positive values
  • Return To = add all corresponding subcategories with negative values
  • Loan Out Balance = Return From + Loan To, where
  • Return From = add all corresponding subcategories with positive values
  • Loan To = add all corresponding subcategories with negative values 
  • Spending Balance = add all corresponding subcategories with positive values
  • Reserve Balance = add all corresponding subcategories with positive values
  • Available Flow = Income BalanceDebt BalanceLoan In Balance + Loan Out Balance – Spending Balance – Reserve Balance
  • Normal Goal = (Available Flow + Spending Balance) / Month Days, where
  • Month Days = the number of days in the corresponding month 
  • Median Goal = Spending Balance / Today, where
  • Today = the number of days since the beginning of the corresponding month including the present day 
  • Future Goal = Available Flow / (Month DaysToday
  • Today Goal = (Available Flow + Spending Balance Today) / (Month DaysToday + 1), where
  • Spending Balance Today = Spending Balance for the day that has Today value 
  • Available Today = Today GoalSpending Balance Today 
  • Savings = (Normal GoalMedian Goal) * Today; a negative value is considered overdraft. 

2010-02-03

Deezer Radio

Some of the radio available at the Deezer:

Blues
Chanson Francaise
Charts
Classic Rock
Dancefloor
Disco
Electro
Film-Tv
Funk
Hard Rock
Hits
Jazz Vocal
Metal
Nouvelle Scene
Pop
Pop Folk
Pop Inde
Punk
R&B
Rap
Rap Francais
Reggae Ska Dub
Reprises-Covers
Rock
Soul
Trip Hop
Urban Style
Variete Francaise

2010-02-01

Birthday

The birthday card from Alice. Thank you!

Jumbo Hug

2010-01-18

Exercise

I've found the following problem in the laboratory at school:

A vector X with n integer numbers is given. Write a Pascal program that computes and prints the longuest sequence X[i], X[i+1], ..., X[f] such that all the elements are mutually distinct.

2010-01-02

An scolar studenti 2009-2010

Structura anului universitar 2009-2010:

Semestrul I
28 sept 2009 Deschiderea festiva a anului universitar
28 sept 2009 - 20 dec 2009 Activitati didactice 12 saptamâni
21 dec 2009 - 03 ian 2010 Vacanta 2 saptamâni
04 ian 2010 - 17 ian 2010 Activitati didactice 2 saptamâni
18 ian 2010 - 07 feb 2010 Sesiune de examene 3 saptamâni
08 feb 2010 - 14 feb 2010 Vacanta 1 saptamâna
15 feb 2010 - 21 feb 2010 Sesiune de restante 1 saptamâna

Semestrul II
22 feb 2010 - 06 iun 2010 Activitati didactice 14 saptamâni
05-11 apr 2010 Vacanta de Pasti Toate Liniile
07 iun 2010 - 27 iun 2010 Sesiune de examene 3 saptamâni
30 aug 2010 - 05 sep 2010 Sesiune de restante 1 saptamâna

Semestrul II - Anii terminali
23 feb 2009 - 23 mai 2010 Activitati didactice 12 saptamâni
05-11 apr 2010 Vacanta de Pasti Toate Liniile
24 mai 2010 - 06 iun 2010 Sesiune de examene 2 saptamâni
07 iun 2010 - 13 iun 2010 Sesiune de restante 1 saptamâna
14 iun 2010 - 27 iun 2010 Pregatirea examenului de licenta si dizertatie 2 saptamâni
28 iun 2010 - 04 iul 2010 Examenul de licenta si dizertatie 1 saptamâna

2010-01-01

Naming conventions

When someone like me puts a lot of markup and javascript inside posts there is always a risk to create conflicting ids and names. One solution is to create a naming convention. Therefore a good idea will be to create master functions (or classes if you like) that contain all the javascript code, and the markup to be inserted using javascript also. The class function will have a name like xunClass_12345678, the instance of the class the name like xunInstance_12345678, while markup elements something like xun[Markup]_12345678_1234, where 12345678 is a unique alphanumeric id for the class and is identical for the instance and any markup, while for markup the last 1234 is a unique id in that area. See the source code for this post for an example.