Saturday, July 10, 2010

Facebook Badges Bug!!

Facebook profile Badges doesn't seems to be updating the badge's current city information available in my facebook profile database. If the current city info cant be retrieved from the DB to badge then why give user the option. Bug!! Bug!! Bug!!

Is it because of facebook's privacy setting?? Grr.. I donno.. The point is, facebook badges gave me the option to display the current city on the badge, But it dint retrieve this info from its DB.

This is my facebook profile page which lists my Current City to be: Gurgaon..


Now this is the my Profiles badge page which lists my Current City to be None!!!



The above images aren't clear. Link to clearer images: http://bit.ly/bFrZwA

Sunday, July 4, 2010

Batch file miseries Part 1 !!

Batch files are useful:
  1. Coz you know if its some reasonably contemporary Windows it would work. Obviously the batch file must have been written correctly..
  2. Running of the bat files wouldn't require any separate tool installation etc. Until and unless you've got a messed up windows sytem which has the cmd.exe replaced or the PATH variable messed or many others ;)
  3. The for loops, if conditionals, variable assignments etc. to script are already there.
  4. Using Bat files is a much faster way to browse and work with your machine instead of using the mouse.
But.. The no. of dangerous buts which come up when it comes to batch file scripting are..

Batch file scripting sucks big time
e.g. Simple bat file.. Arrg.. Not that simple coz u'll come up with lot of "was unexpected at this time." and all other kinds of errors.

@echo off

set TESTVARIABLE=init

if "%TESTVARIABLE%"=="init" (

set TESTVARIABLE=used

if "%TESTVARIABLE%"=="used" (

echo This was logical
) else (
echo Bat files suck big time..
)

)


Guess what the output would be?
Bat files suck big time :D

The good thing is that this above problem has a solution even though its rather dirty considering its such an elementary problem if someone wants to script batch files.

Solution:
  1. check the registry key "HKLM\Software\Microsoft\Command Processor\DelayedExpansion"
  2. If it does'nt exist then add the registry key by using regedit or by using this command: reg add "HKLM\Software\Microsoft\Command Processor" /v DelayedExpansion /t REG_DWORD /d 1
  3. Just in case u think that the above script should be working logically when u want it to is to invoke cmd.exe with the flag /v:ON i.e. cmd.exe /v:ON .. On all the other times the default Windows behavior of sucking with bat files would continue :P
  4. To enable the logical behavior only for a particular scope in a batch file we can use setlocal ENABLEDELAYEDEXPANSION. This way logical behavior would be reflected until the bat file execution is over.
The Hkey_Current_User hive can also be changed instead of HKLM if your machine is a multi user machine and u dont want this change to affect other users.

There's one more gotcha:

Once the Delayed Expansion behavior is enabled by using the above methods. To refer to the variables in a different scope we use retrieve the value of the variable by enclosing it with ! instead of %

So the batfile also needs to be changed and it becomes this:

@echo off

setlocal ENABLEDELAYEDEXPANSION
set TESTVARIABLE=init

if "%TESTVARIABLE%"=="init" (

set TESTVARIABLE=used

if "!TESTVARIABLE!"=="used" (

echo This was logical
) else (
echo Bat files suck big time..
)




So that was one of the hopeless default setting of Windows XP. There are many other hopeless ways in which Windows bat file interpreter makes life bad for people scripting in Bat files.. Hence Python and other scripting languages are a requirement..