Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Friday, January 10, 2014

Javascript - Empty space in numeric field

 I run into the issue when isNaN was returning false for empty string.
 Turned out this is by design, because isNan is comparing coerced values - coercing empty string into 0, and of course, not having issue with 0 not being a number.
 To make sure that user has to enter 0, I added this to the check:

 isNan(parseInt(field))

Of course, this is not comprehensive solution, Douglas Crockford has more to say on this topic, especially on recognizing the numbers, but it worked for simple validation I was aiming for.

Friday, November 15, 2013

How to force dropdown to open in javascript / jquery

     Force dropdown to open
      
     $("#selSizes").attr("size", "5")


Monday, November 4, 2013

Difference between call and apply in JavaScript

 Here's the main difference - do you know the number of arguments beforehand?

1) Use apply if you don't know the number of arguments you will be passing, (or if they are already in an array or array-like object).

2) Use call otherwise, since there's no need to wrap the arguments in an array.

f.call(thisObject, a, b, c); // Fixed number of arguments

f.apply(thisObject, arguments); // Forward arguments

var args = [];
while (...) {
    args.push(some_value());
}
f.apply(thisObject, args); // Unknown number of arguments

Thursday, October 31, 2013

Knockout and ()

  I have to put post-it note somewhere:

  PUT ( ) on every binding that's part of the expression!

 It's so misleading - if you have regular  data binding to the something like this:

<div data-bind="text: customer.name"></div>

 that works without parenthesis.

 If you have expression, don't forget your ()!


'class': $root.currentColor().name() === $data.name() ? ...

Bootstrap

 Looks like there was an error in bootstrap 3.0 that lead to font not being displayed in certain browsers. Version 3.01 fixed that, but to get Chrome to display .woff font, I had to add Mime type to the IIS:

File name extension:
.woff

Mime type:
application/x-woff

IIS 7.5 and mapped share

Virtual directory on IIS 7.5 pointing to shared folder on the network, containing pictures...  and strange error message about my config file being corrupt.

Google-fu for:

500.19 IIS 7.5 0x80070003

yielded finally proper solution - you can't use network mapped drive when you define virtual directory for IIS; you have to use \\SERVER\Share type of syntax.

Nothing to do with config files!

To get proper 500 error resolution, look for the code like 0x80070003 on the page, not just 500.19... there are many many codes related to that error.

Tuesday, October 29, 2013

JavaScript error handling

 JavaScript does have try catch but it has something even handier for error catching - window.onerror.

 It used not to work on Chrome (yes, really!) and since now it works in pretty much all browsers, it's very convinient for error handling.

 Basically, it will redirect all console errors to your function.

 To get it to work, it has to be in its own script block (or it's own include file, the first one to be included).

<script type="text/javascript">
  window.onerror = function(msg, url, linenumber) {
        alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
}
</script>

Parameter (in order) Description
Error Message Contains a message explaining why the error occurred.
Error URL Contains the url of the page with the error script
Error Line Number Contains the line number where the error occurred