Thursday 21 June 2012

How to take screenshots from your Android devices

I tried instructions written here It worked for me.
All you have to do is press the Power and Volume Down buttons at the same time and hold.

Wednesday 20 June 2012

The proper way to use Syntax Highlighter with Blogger

I wanted to integrate SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter/) with my Blogger. In version 3.0 the author introduced feature autoLoader (http://alexgorbatchev.com/SyntaxHighlighter/manual/api/autoloader.html) which loads only those scripts that are actually required.

I wanted to add support for every language supported by this highlighter.

Initially this didn't work because the autoLoader script was executed prior to DOM loaded so it decided that there are no syntaxes to load. To fix that I am using jQuery.

The following instruction is mostly copy-pasted from http://www.commonitman.com/2010/09/how-to-use-syntax-highlighter-3-in.html

  1. Navigate to Dashboard > Design > Edit HTML
  2. Backup the current template by clicking on the link Download Full Template
  3. In the textarea, press CTRL+F to find the code </head>
  4. Copy the below code and paste it just above
      
      
    
      
      
    
      
    
      
      
      
    
    
  5. Preview your changes and make modifications as required
  6. Save the template

Tuesday 19 June 2012

How to check current PowerShell version...

The easiest way to determine current PowerShell version is to execute the following script:
$Host.Version

Tuesday 20 December 2011

Nullable types, lifted operators and ReSharper

Recently I investigated why ReSharper marks some pieces of my project code as invalid however compiler does not throw any errors.

Finally I narrowed down the problem.

class Program
    {
        static void Main(string[] args)
        {
            int? i = 10;

            A a = i;
        }

        class A
        {
            A(int i)
            {
                Value = i;
            }

            public int Value { get; private set; }

            public static implicit operator A(int i)
            {
                return new A(i);
            }
       }
    }

ReSharper highlights an error on line 7. However as you can imagine on a runtime corresponding implicit operator is called.
I investigated this behaviour and found that actually it is according to the C# spec

Nullable conversions and lifted conversions permit predefined and user-defin ed conversions that operate on non-nullable value types also to be used with nullable forms of those types. Likewise, lifted operators permit predefined and user-defined operators that work for non-nullable value types also to work for nullable forms of those types.
For every predefined conversion from a non-nullable value type S to a non-nullable value type T , a predefined nullable conversion automatically exists from S? to T?. This nullable conversion is a null propagating form of the underlying conversion: It converts a null source value directly to a null target value, but otherwise performs the underlying non-nullable co nversion. Nullable conversions are furthermore provided from S to T? and from S? to T , the latter as an explicit conversion that throws an exception if the source value is null.

So finally I know that it is a ReSharper bug and I will report it on their bug-tracker system.

Potentially it is a good question for juniors on interviews :)

UPD: Raised bug on ReSharper bug tracker
http://youtrack.jetbrains.net/issue/RSRP-287221?projectKey=RSRP&query=lifted

Test SyntaxHighlight

Finally made SyntaxHighliter working on the blogger.
Good instructions http://pjdurrant.blogspot.com/2011/11/blog-code-syntax-highlighting.html

public class FinallySyntaxHighlighterIsWorking
{
    public void React()
    {
        Console.WriteLine("Hoorah!!!");
    }
}