...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, November 15, 2013

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 (...) {
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() ? ...


 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:

Mime type:

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);

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

Tuesday, October 8, 2013

MVC - How to get ModelState collection in the View

ValidationSummary is nice way of displaying errors on the Model.
Sometimes it's useful to query ModelState collection itself, to see it's content.
This code will display all errors that are in collection.
Note: This is for Errors only, Exceptions are in different collection - item.Value.Exceptions...

  <tr><td>Model State</td></tr>
    @foreach (var item in ViewContext.ViewData.ModelState)
        if (item.Value.Errors.Any())
                <td>@((item.Value == null || item.Value.Value == null) ? "<null>" : item.Value.Value.RawValue)</td>
                <td>Error: @(string.Join("; ", item.Value.Errors.Select(x => x.ErrorMessage)))</td>

Wednesday, August 14, 2013

Hyperloop is revealed

 Elon Musk finally published details about "Hyperloop" - way to travel from San Francisco to Los Angeles at the fraction of the cost of the system California is building now. In essence, this will be elevated tube, sending aluminum pods through.

Details here:


and here:


Thursday, July 11, 2013

Engineers and TODO lists :)


 I don't dabble much in image formats, except for having appreciation for SmushIT! :) but this sounds like a neat trick - using CSS to reduce png size:


Wednesday, June 5, 2013

Anti forgery token

 Premise is simple - you need token to verify that this is you who is posting to the page and not somebody else posting for you.

 Token is written to the form and to the cookie using HtmlHelper.AntiForgeryToken() helper, and when form is posted, controller will validate the token for the post action that has token validation attribute enabled:
[ValidateAntiForgeryToken(Salt = Constants.AntiForgeryTokenSalt)]

 There is a great article by Scott Gu about it:


Thursday, May 16, 2013

Star trek t shirt

 This from the Star Trek store:

10 reasons by Picard is better than Kirk:

10. Picard is a man of culture.
9. Kirk was scared of a little tribble.
8. Kirk wouldn’t go anywhere alone.
7. Picard looks fantastic in spandex.
6. Picard lasted more seasons than Kirk.
5. Picard doesn’t need hair to feel like a man.
4. Picard’s ship logs contain more syllables per word than Kirk’s.
3. Picard hasn’t contributed to the population explosion.
2. Kirk only worries about his own butt.
1. The Borg only assimilated intelligent life.

I love #1 and #8 :)

Friday, April 26, 2013

Facebook feed dialog cutting description text passed using CSS

If you use Feed Dialog to post to the wall, Facebook will cut off your description.

Looks like this is "by design" :( Dirty word, isn't it?

 You can pass text in a description as much as you want, but Facebook has CSS that squeeze your text into box 72px tall... without "See more..." or anything like that.

 I can understand the box part, but no "See more"? Why not??? It's already there, and I, as a user, want to see the rest... Doesn't make sense.

And here's the bug report:


Friday, April 19, 2013

Responsive design catching on

 Article abotu 10 commercial websites that uses Responsive design:


Again, responsive design is not for everyone, but if you are trying to reach widest audience possible, that's something that should be incorporated early on into site (re)design. It does pay off when people are using different devices to come to the site.

Friday, April 12, 2013

Monday, April 1, 2013

Entity Framework 5 and LocalDb in Visual Studio 2012

 Visual Studio 2012 introduced LocalDb - special edition of SQL Express for developers.

 Problem that I run into when trying to create database was that by default, web.config had SQLExpress datasource specified, not LocalDb.

 After searching and finding a great blog - OdeToCode, turned out that I had to change this section:

      <parameter value="v11.0" />

I did change defaultConnectionFactory, but it didn't work, giving me error about not recognizing LocalDbConnectionFactory etc.

Additional parameter has to be added and to be v11.0 for this to work.

Wednesday, March 20, 2013

Voyager 1 left Solar system for good...

 Looks like it's official now - Voyager 1 crossed the edge of Solar system! For somebody who still remembers Carl Sagan's "Cosmos" that's exciting news. I wonder how long it will keep sending...
Go Voyager Go!

Wednesday, March 6, 2013

This and that in JavaScript

 This and that in JavaScript - or self as I've seen it, is just a workaround for the fact that in JavaScript, inner function "this" is not behaving like "this" from the outer function, it points to the window object.. Yes, it's a bug, and it will be fixed in ECMA5.

To preserve outer function "this", putting "this" into local variable ("that" or "self") will allow transfer of variable from outer function to be used, by using closures.

Closure mechanism - an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.

Something like this:

<!DOCTYPE html><html lang="en">
 var myObject = 
  myProperty:'Some text here'
   var that = this; //reference to myObject in myMethod scope 
   var innerFunction function() { // inner one
           console.log(that.myProperty); //logs 'Some text here'
           console.log(this); // logs window object to show what will happen if we don't store this into that
myObject.myMethod(); // invoke myMethod


Debugging client side script

I was trying to debug client side code and was getting those "Breakpoint will not be hit" messages. Turn out that to allow debugging of the client side script, you need to Attach debugger to the process but before you actually do that,  click Select button on the top of the list of processes. If it on automatic, change it to Script.
 That functionality goes back to Visual Studio 2008 and it's still there in VS 2012.
 There are other ways too - debugger; in javascript code, or using Client debugging in IE or Firefox (or Chrome), but it's nice not to have to do anything extra but use VS when you want to attach to the process anyways.

Friday, February 8, 2013

ViewState and debuger

ViewState object is not great for debugging. Expanding it's properties at the run time will yield nothing useful unless you know what are you looking for.
Add this to Watches to get insight into collection of values stored in internal dictionary:

new System.Collections.Hashtable(ViewState)

Thursday, January 24, 2013

Hyphens, dash - dash, hyphens!

As a non native English speaker, I am happy when I am able to unravel another mystery from the language :) In this case, 3 different "dash" signs in the written English :)

-            hyphen
–           n-dash
 (also known as ndash or en-dash)
—         m-dash
 (also known as mdash or em-dash)

Hyphen is what we are using when words wrap at the end of a line. Other use is for the phone numbers, things that are grouped together, but not by range.

n-dash is used for ranges, either words or numbers.

m-dash is used when the sentence is going into another direction and other part of the sentence is radially different. Also, it can be used when dialog is being interrupted.

 How I got here? Html entities and correct display of those on the web page...

Here they are:


 0. The soft hyphen (&#173; a.k.a. “discretionary hyphen” and “optional hyphen”) is to be used for one purpose only—to indicate where a word may be broken at the end of a line.
 1. The non-breaking hyphen (&#8209; not in HTML) does just what its name implies.
 2. The hyphen character (&#8208; not in HTML) is meant to be used in place of the hyphen-minus when a hyphen is exactly the desired character.
 3. The hyphenation point (&#8231; not in HTML) is that bullet-like character you find in some dictionaries to separate syllables.

The en dash:  (&#8211;)

The em dash: (&#8212;)

Monday, January 14, 2013

Datasets and timeouts

When using tableadapter to retrieve the data from database, Microsoft did not provide property to set command timeout anywhere, unless you go to generated file directly.
 Once in XDataSet.Designer.cs file, there are 2 places that Command Timeout can be set:
1) On SelectCommand of Adapter itself  - if this is for data retrieval calls, GetData method:
this.Adapter.SelectCommand.CommandTimeout = 60;
2) On initialization of command collection - each stored procedure call can have it's own command timeout.
 this._commandCollection[0].CommandTimeout = 60;

 By default, no timeout is set, and default is 30 seconds.