odd bits 28 Oct 2008 07:54 pm

Need a looooong e-mail address?


Want to get an e-mail address like this one?

myname@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com

It has the following “unique” features:

  • Some Webforms do not work with your email
  • Some Email Software Cannot be configured
  • People Cannot Remember your email address
  • Companies think that your email address is fake
  • The World’s Longest Email Address

For more information visit:
http://www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com/service.php

Uncategorized 28 Oct 2008 12:46 pm

ASP.NET Error: The Controls collection cannot be modified because the control contains code blocks


I’ve noticed that if you try to add control to the page using Page.Controls.Add() method the following error may occur :

The Controls collection cannot be modified because the control
contains code blocks (i.e. <% ... %>).

Just check if following is true on the page causing this error:

  • Your page doesn’t have <head> elements with runat="server" attribute
  • Your page content is wrapped into form tag with runat="server" attribute

programming 09 Oct 2008 03:56 pm

How to test SMTP server using telnet


Sometimes you need to test whether your SMTP server is running and is able to send e-mail messages. You can to that using telnet command from command line:

>telnet www.mysmtphost.com 25
220 www.mysmtphost.com Microsoft ESMTP MAIL Service, Version: 6.0.2600.5512 ready at Thu, 9 Oct 2008 15:46:35 +1100
>helo
250 www.mysmtphost.com Hello [192.168.1.119]
>mail from:max@test.com
250 2.1.0 max@test.com….Sender OK
>rcpt to:max@test.com
250 2.1.5 max@test.com
>data
354 Start mail input; end with <CRLF>.<CRLF>
>Just a test e-mail message
>.
: type a dot on new line to finish message
250 2.6.0 <WSMT-29bUyUSxMUaoYo00000002@WSMT-29.Tickets.local> Queued mail for delivery
>quit

Now your e-mail should be sent to specified address. If you happen to use Microsoft SMTP server which comes with Windows XP, Vista and Server your default location for e-mail messages would be C:\Inetpub\mailroot\

programming 07 Oct 2008 06:16 pm

Unit testing JavaScript code with JQuery framework


JQuery framework has its own unit testing modile QUnit. You may use it to write unit tests for your JavaScript code. In order to use it you need to:

  1. Load latest version of JQuery
  2. Get QUnit source code
  3. Create a unit test HTML page which references all these files and has your unit tests

Here is an example of how you can use the QUnit:




    The unit test results will be displayed within your browser window.

    You may also try other JavaScript frameworks. They have quite similar functionality.

    programming 07 Oct 2008 11:39 am

    How to pass strings from C# into JavaScript using JSON


    Quite often you need to pass string values from your server side code into JavaScript code. The strings may include special characters, so the following code will produce JavaScript errors and has cross-site scripting vulnerability:

    var text = "<%= "This\t is a \"test\"\n string " %>";
    alert(text);

    To pass values correctly you need to encode all special characters. In .NET 3.5 a new class DataContractJsonSerializer was added to encode server objects into JSON values. The following function is using DataContractJsonSerializer to encode string value:

    public string CreateJSONString(string str)
    {
        var json = new DataContractJsonSerializer(typeof(string));
        using (var ms = new MemoryStream())
        using (var writer = JsonReaderWriterFactory.CreateJsonWriter(ms))
        {
            json.WriteObject(ms, str);
            writer.Flush();
            return Encoding.UTF8.GetString(ms.ToArray());
        }
    }

    So in your .aspx page the following would be used instead:

    var text = <% = CreateJSONString("This\t is a \"test\"\n string ") %>;
    alert(text);

    As you can see, now string value is converted correctly into JavaScript string including double quotes, tab and new line characters.

    programming 30 Sep 2008 03:00 pm

    How to get a saved password value from password field with JavaScript

    Did you ever happened to you that you registered on some website, saved your username and password into browser. After some time you forgot that is the password you used?

    You can retrieve it using JavaScript. You can execute any JavaScript statement by typing it into your browser address field with “javascript:” added in front of it. Login username and password are usually located within an HTML form tag. So all you need to know is a position of login form, where first form on the page is 0. Within this form you can specify which form element you need. You can set it either to its index (also starting with 0) or by specifying the form element name.

    So if, for example, you forgot your GMail account password you can use the following statement to display your account password:

    javascript:alert(document.forms[0].elements['Passwd'].value);
    

    programming 28 Sep 2008 12:36 am

    Using multiline strings to improve code readability

    As a person who often reads code written by someone else I’ve noticed that multiline strings are not used as frequently as they should. As a result you can often see code like this:

    1. string someHtml;
    2. someHtml += "<html>\n";
    3. someHtml += "    <body>\n";
    4. someHtml += "    </body>\n";
    5. someHtml += "</html>";

    Apart from possible performance issues this code is quite difficult to read and edit. Most languages have mutliline strings and by using them you can make a cleaner code.

    In C# you can change the code above into this by just adding a single "@" character in front of string value:

    1. string someHtml = @”
    2. <html>
    3.    <body>
    4.    …
    5.    </body>
    6. </html>
    7. ";

    JavaScript doesn’t have similar feature built in, but as suggested here you can use XML’s CDATA for large string values in JavaScript:

    1. var myString = ""+<r><![CDATA[
    2.       <div class="pmcb_top">
    3.         <div class="pmcb_tabs">
    4.           <ul>
    5.             <li>Chat</li>
    6.             <li>Monks‘n’stuff</li>­
    7.             <li>Other</li>
    8.           </ul>
    9.         </div>
    10.       </div>
    11.   ]]></r>;

    travel 18 Jul 2008 08:56 am

    Four days in Japan

    Tokyo train

    Who says that trains in Tokyo always crowded?

    097-049-1.jpg

    097-045-1.jpg

    Kiosk
    Japanese Kiosk

    "Visit California" advertising campaign in Japan
    Arnold Schwarzenegger advertising travel to California

    img_5439.jpgimg_5438.jpg

    Vending machines on streets of Tokyo

    Japanese vending machines for drinks

    travel 22 Jun 2008 02:39 am

    Trip to New Zealand. Part 2. Arthur’s Pass


    Перевал Артура находится в 150 километров от города Крайстчерч. Согласно официальным данным в поселке возле станции проживает всего-лишь 50 человек. Тем не менее в поселке мы обнаружили несколько гостиниц, кафе с небольшим магазинчиком и офис с информацией для туристов.

    Мы ночевали в этой очень уютной гостинице. В номере был душ с горячей водой, телевизор и высокоскоростной беспроводной Интернет.

    095-077.jpg

    Ирландский паб с ирландским пивом Murthy’s

    095-117.jpg095-059.jpg

    В день нашего приезда лил дождь, тем не менее мы нашли в себе силы сходить к водопаду что находился неподалеку от поселка.

    095-066.jpg

    Вечером дождь сменился снегопадом. На следующий день на дворе была самая настоящая зима. В этот день мы прошлись по тропке которая вела через лес. Несмотря на относительную близость Австралии, природа Новой Зеландии заметно отличается от Австралии. Здесь растут березы, хвойные деревья и мох.

    travel 14 Jun 2008 01:09 am

    Trip to New Zealand. Part 1. TranzApline train


    A week ago me and Vladimir Gizatulin visited New Zealand’s South Island. Three days is a very short time for this country. We arrived to Chistchurch late Friday evening. For Saturday we booked train trip from Christchurh to Arthurs pass.

    TranzAlpine train crosses South Island from eastern to western shore across Southern Alps. Trip takes four hours one way. Arthurs Pass is approximately in the middle of this route.

    Next Page »