Wednesday, December 22, 2010

Back To The Future (Why logins might fail on Google and others)

A few days ago I got a call from someone that asked for my help.

He said that he can not login into the management section of some site that he is using,
he said that he talked to the technical personal on that site and they said that the problem is not on their side and he also said that he can use his user name and password to login to that site from another machine.

The symptoms on his machine where such that after he entered his username and password he would be sent back to the login page. so I played with it for some time.
I looked for browser hijacking and odd network activity and found none. Eventually I found that if he does not check the "remember me" option he can login and there is no problem.
So I left him sort of happy that he can now use the said system.

The day after I got another call from him saying that now he can not login even to his Google account. I looked at the problem and the browser (IE) was saying that there was a network problem. ping to google works and telnet to port 80 also gave the expected results... Switched over to Google chrome and got a better error message: Redirect loop...

hmmm.... google to the rescue.

It turns out that the date on this machine was set to about 3 months in the future, causing any cookie that was set to a future time (based on the server time of course) to expire immediately.

I reset his machine's date and voila, everything was working.

so next time google does not work for you, make a note of the date and time.


Thursday, December 09, 2010

Avoiding timeout during installation of magento

To avoid "Fatal error: Maximum execution time of" just set "max_input_time" in your php.ini,

personally I changed it from 60 (which caused a timeout) to 240 (which worked great).

Sunday, November 14, 2010

How to get a domain authorization code from

A few months ago I decided that I am gradually going to move away all my registered domains from to

Now each time I transfer a domain I am faced with the question of where the hell did they place the authorization code.

so as a service to myself and anyone who might be looking for the same:

1. Log in
2. On the main(gray) toolbar near the top, hover over "Domains" and in the sub menu that opens click "My Domains".
3. Click the name of the domain that you are transferring.
4. The third Setting is "Authorization Info / EPP Key" click the link next to it that says "Email Auth Code to Registrant" and it should reach you inbox.

good luck.

Wednesday, July 28, 2010

empty strings are (not) different then false

Did you know that if you are testing if a value does not equal an empty string in javascript:


might return somewhat unexpected results if v is false

var v=false;

will alert false and not true as you might expect.
At first glance I said, well o.k. this does make sense because v is a boolean so the empty string is being cast to a boolean for the comparison yielding false.

so I tried

var v=false;

I expected that now the false value of v will be cast to the 'false' string which obviously is not an empty string and that the alert will now show true.

but that does not work either.


var v=false;

does work as expected and results in true being returned.

I wander if this is also the case in ActionScript ...

Monday, July 12, 2010

Beware of javascript String.replace

Here is a problem I encountered a few days ago:

What would you expect the result of the following expression be:


Well its easy to guess that it will be the string 'asomeUserInputb', and indeed it will.

however what would happen if instead 'someUserInput' we realy had some some user input?

you would expect it to return the actual user input with 'a' prefixing it and 'c' as its suffix.

I Also guess some of you knew that if instead of 'b' you used a regular expression then some tokens in the replacement string will have a special meaning as in the following table:

Characters  Replacement text
$$ $
$& The matched substring.
$‘The portion of string that precedes the matched substring.
$’The portion of string that follows the matched substring.
$nThe nth capture, where n is a single digit in the range 1 to 9 and $n is not followed by a decimal digit. If n≤m and the nth capture is undefined, use the empty String instead. If n>m, the result is implementation-defined.
$nnThe nnth capture, where nn is a two-digit decimal number in the range 01 to 99. If nn≤m and the nnth capture is undefined, use the empty String instead. If nn>m, theresult is implementation-defined.

What I did not know / expect is for this behavior to occur even when I was using a plain sting as the search value.

In my case I had to do some length based truncation of a user input string, append an ellipsis to it and inject it into a string instead of some place holder.

Template string: '<div>$userInputAfterElipsis</div>'
Original User input: 'some long string that said something and a price like 1M$ isideIt'

"luckly" for me, it turned out that the truncation logic truncated the user's input string right after the $ sign and so when I appended an &hellip; (…) to it I ended up with 'some long string that said something and a price like 1M$&helli;' as the new value for the string replacement.

'<div>$userInputAfterElipsis</div>'.replace('$userInputAfterElipsis','some long string that said something and a price like 1M$&helli;')

which returns:
'<div>some long string that said something and a price like 1M$userInputAfterElipsishelli;</div>
having replaced the $& in the new value with $userInputAfterElipsis.

so that was the problem. but how should this be resolved? and why should you care?

I will start with the second Q:
You should care because if you use JavaScript you probably also use String.replace and if you do then it might fail to do what you expect in those scenarios where the replacement string is not a fixed string that you know.

As for what can/should be done, well the first thing that comes to mind is that you need to escape those $'s
so how about:
This will not work for two reasons, the first on is that the $ replacement will only replace the first occurrence of a $ sign in the replacement string and the second is that here also the $$ will be interpreted as a single $ so what we do need is actually:
now this will work BUT, IMHO, performance-wise it is not such a great solution.

what I ended up doing was using the following:
this is o.k. as long as you want all the occurrences of original to be replace with replacement. If you want to replace only the first one you should use:

As always I hope this will help some one out there in the sea of bits and bytes...

Monday, June 07, 2010

Solution to: Powershell never exists when executed from a batch file / fdbuild

The short story: use <NUL

More details:

I have been using Powershell as part of a build script for a
FlashDevelop project.

The problem was that the Powershell process did not terminate
and so fdbuild.exe did not continue to run.

I searched the web quite a lot until I found the following

They deals with a similar problem that happens when executing
Powershell from WScript.

The explanation given that was that Powershell is waiting for
its STDIN stream to close before it exists and a workaround is
suggested there that fits WScript.

This got me to the following solution for running Powershell
from Flashdevelop/fdbuild/batch:

since IMHO Powershell in those cases does not need any input
from STDIN I assigned NUL as its input stream.

-Noninteractive -Command "& {$postbuild = (get-item ((get-item
%1).parent.parent.Fullname + '/postbuild.ps1')); & $postbuild
-outputDir %1 -outputName %2; exit $lastexitcode}" <NUL

I use this in a batch file that is called from the post-build
event using the following command line

$(ProjectDir)\..\postbuild.bat $(OutputDir)

I guess I could call Powershell directly from the post-build
command line but this will have to wait.

As far as I know I am the first to suggest this workaround,
please add a link to this post if youare quoting it. Thanks.

Sunday, June 06, 2010

"Exception: Unknown project extension: Library" error when running fdbuild (flashDevelop) from the command line

This happens to me each time I install a fresh copy of flashDevelop.

Each time It takes me some time to figure out why this happens.

next time I will have my blog to remind it happens because:
Because the location of the FLEX SDK is not set in the flash develop setting dialog.

Thursday, May 27, 2010

Hell is other people's CSS rules

A significant part of the JavaScript code I wrote in the last few years is intended to run as part of HTML pages developed by other people.

Now consider the following:

Lets say your JavaScript has a function called "AddButton" that takes a background color, a text color, some text for the button itself and a callback function to call when the button is pressed. and it renders the HTML and CSS that will show this button on the client's page. (Of course in real life this is much more complicated bu this should do to make the point).

You create perfect code, test it on FF,Chrome,IE,Safari,iPhone,iPad and what not, and it looks perfect and works great.

Now your customers/clients start to use your wonderful code and it turns out that one of them has a CSS rule that says "DIV {left-margin:5px}" which causes the texts on your perfect button not to be centered on his site.

So you go and change you code to rended style tags on all your divs saying that their left-margin (and right and top and bottom) are 0px, so your good now.

But then it turns out that another client has "Div {border:1px solid white}" ....
and so on (and of course this is not limited to divs...

How "defensive" should you be "against" the CSS ruls of the hosting page? and what can you do assuming that you don't want to start adding all the possible CSS attributes to every tag you render ?

How would you go about handling this?

Oh... and IFRAMEs are not a valid solution. Well, actually some times they are but lets assume this is not one of those times - why ?

1) Performance
2) Your generated html is required "flow" as part of the hosing page.

Any JavaScript / HTML /CSS lover out there would care to share his thoughts on this ?


Sunday, January 03, 2010

Using PSCX from multiple users on same machine

I was having a problem with an automation script I was working on,
It used PowerShell and PowerShell community extensions (PSCX) and it worked fine of for me, but when other people used the same machine - it did not work.

after some looking around - the problem was that PSCX was installed from my user so it was automatically loaded on from my profile.

The resolution:

$pscxInstalled = $false;
$pscxLoaded = $false;
$registeredPSSnapins = Get-PSSnapin -registered
foreach ($registeredPSSnapin in $registeredPSSnapins) {
if ($registeredPSSnapin.Name -eq 'Pscx') {
write-host "PowerShell Community Extensions Found on system" -ForegroundColor green -BackgroundColor black
$loadedPSSnapins = Get-PSSnapin
foreach ($loadedPSSnapin in $loadedPSSnapins) {
if ($loadedPSSnapin.Name -eq 'Pscx') {
write-host "PowerShell Community Extensions are loaded" -ForegroundColor green -BackgroundColor black
if (-not $pscxLoaded) {
write-host "Loading PowerShell Community Extensions from registered PSSnapin" -ForegroundColor green -BackgroundColor black
Add-PSSnapin Pscx


Clicky Web Analytics