SharePoint + Twitter Bootstrap = Less Hack

Developing for SharePoint 2010 is unhealthy. You cannot use last .NET features, you cannot use last JavaScript stuff and at the end you cannot use last CSS goodies. Of course, I want all this stuff. This post is about small hack that will give you Bootstrap styles in your SharePoint pages.

What the problem?

Well, if you just reference Bootstrap it will conflict with SharePoint styles. Results are quite ugly.


Solution that looks best for me is just to use less to add “namespace” to CSS files.

  1. Get Less support for Visual Studio – Web Essentials.
  2. Create less file in your Layouts folder
  3. Add something like this
  4. .my {
      // Put content of Twitter Bootstrap  files you need
      // For example I added this

2. Wrap part of the page you need with div with class my:

<div class="my">
    <!-- your html -->




Apache Thrift journey on .NET

I needed fast protocol for cross-process communication. There are many options, and Apache Thrift one of them. So I decided to give it a try. This is quote from project site:

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

How to start

First thing to know is that Thrift has simple DSL to define contracts and called the Thrift interface description language (IDL). DSL is quite powerful and self explanatory. Most easy way to get familiar with syntax is to read tutorial.thift. Another place to learn it IDL page. For playing purposes you may end with something like this (default file extension is .thrift):

namespace csharp PlayWithThrift.Contracts

struct Work {
  1: i32 num1 = 0
  2: i32 num2
  3: optional string comment

service Calculator {   
   i32 add(1:Work work)   

Save this to something like test.thrift. IDL file can also have service(RPC) definitions, enums, namespaces and constants. You can use inheritance and include other thrift files.

Second is how to turn IDL file to something that can work. Thrift uses code generation to produce DTOs, serializers for them, client and server classes. To generate code Apache Thrift compiler is necessary. You can download one from downloads page. Or if you have Chocolatey installed, just use:

cinst thrift

This will add thrift to your PATH, so you can just use thrift executable form anywhere. So to compile our test.thrift execute:

thrift --gen csharp test.thrift

Result will be in gen_csharp folder. I should say result is ugly, but a bit later on this.

Now, third. Now when we have code in place, lets make it dance.  First of all you need implementation of the server side. It uses ugly named interfaces, but let us pretend that all is good. We have only one method defined and so has implementation:

public class CalculatorHandler : Calculator.Iface
    public int add(Work work)
        Console.WriteLine("add({0},{1}) // {2}", 
            work.Num1, work.Num2, work.Comment);
        return work.Num1 + work.Num2;

Now it is time to start serving stuff to the wire!

    var handler = new CalculatorHandler();
    var processor = new Calculator.Processor(handler);
    var serverTransport = new TServerSocket(9090);
    var server = new TSimpleServer(processor, serverTransport);

    // Use this for a multithreaded server
    // server = new TThreadPoolServer(processor, serverTransport);

catch (Exception ex)

And finally client part:

using (var transport = new TSocket("localhost", 9090))
    var protocol = new TBinaryProtocol(transport);
    var client = new Calculator.Client(protocol);


    var sum = client.add(new Work
        Num1 = 12,
        Num2 = 13
    Console.WriteLine("12+13={0}", sum);    



When run compiler, you might get error:

[ERROR:C:/Users/Mike/Projects/PlayWithThrift/PlayWithThrift/ContractMsg.thrift:1] (last token was ‘∩’)

Unexpected token in input: "∩"

It looks like this means that you have unsupported encoding for thrift file. Change it to something without signature fixes the problem.

Main problems

  1. Generated code is awful, strange naming conventions, strange base classes. Lack of correct capitalization. And T prefix – it probably means Thrift, but for me it reminds Delphi. Async code is generated only under SILVERLIGT symbol.
  2. Lack of UTF-8 support for .thrift files
  3. Looks like implementation is blocking


There is no love at first sight. Usability is quite good, but implementation kills the whole idea. I will try to find better implementations for my needs. Next is probably protobuf.

Please note, Apache Thrift project permanently moves all things around. So many links to tutorials, readmes repositories may not be available at the time of reading. Ping me with any problem, I will update post.


PsGet News #2: new modules

I LOVE PSGET. There reason is simple, it works even if I do not have time maintain it Smile Anyway we have some new modules I want to highlight.


posh-npm  – Integration of the Node.js to PowerShell console. Adds tab completion and other goodies.

PSBabushka – A configuration management framework built in PowerShell to help automate Windows environments.

PsWatch – Monitoring a directory for changes and send changes to Growl

Send-Growl – And Growl integration for powershell

PoSHServer – PowerShell Web Server – Secure, flexible and lightweight web server to meet your requirements.


Now you have Chocolatey installed, you can go deeper and install PsGet with it (thanks Mark Johnson):

cinst psget


Please note,  Chocolatey package will install PsGet globally for all users.


There is an idea for PsGet to install modules to profile by default. Let me know your thoughts

Tagged , , , , , , ,

Google Reader replacements

Most recent version of the list in this gist.


  • Requires Google Chrome or Firefox on Desctop
  • Has iPad and Android apps, does not have WindowsRT app
  • Syncs read items with Google Reader
  • Guys does not like Windows

The Old Reader

  • Works in any browser
  • Looks very fammilar to Google Reader
  • Does not sync read items withh Google Reader
  • Import from Google Reader through OPML


  • Easy import feeds form Google Reader
  • Open blogposts in IFRAME


  • Easy import feeds form Google Reader
  • I do not understand how it works


  • I am in queue free accounts on NewsBlur

Digg Reader

  • Not done yet


  • Open-source project
  • Easy import from Google Reader
  • Has plugins for Google Chrome, Firefox and Opera


  • Nice looking
  • Import from Google Reader is easy

Windows VMs

From time to time you need VM to play and forget. It would be cool to have something like Vagrant, але маємо те, що маємо. So here few links when you can get preinstalled virtual machines with Windows.

Modern.IE site

One of the best sources of virtual machines up to date is Modern.IE site. Technically this VMs are intended to test Internet Explorer, but I hope you will be able to accept and live with this. Virtual Machines are packed for almost any virtualization platform such VirtualBox, VMWare and Hyper-V. You can find all desktop versions: Windows XP, Windows Vista, Windows 7 and of course Windows 8. All VMs are trial for 30 days and you can reset this 2 times, so 90 days of usage.

Trial versions

For Windows Server 2012 go to trial page and download Evaluation VHD. This is 180 days trial. Obviously works in Hyper-V but also works well with Virtual Box (ensure that you have last Virtual Box, there were bug with VHD based images).

Windows Server 2008 R2 trial VHD – could be downloaded here. Should also work in Virtual Box.

Tagged , , , , ,

Fact: You can run multiline command in MsBuild Exec Task in simple way

This might look obvious, but I spent some time to try some complicated ways (like declaring variable) and some incorrect ways (like declaring Command element) and ended with this..:

Eye opener, I can put multiline script just to Command attribute and it even works.

Introducing TPL Async Generator

I am playing with Azure last months. I love Azure. Really breath of fresh air last days… But there is small funny issue… Client libraries are async. But async is implement with old IAsyncResult model. Uuuu. Ugly. Let’s fix this.

I implemented small T4 template that actually

  1. looks for all methods with Begin
  2. and generate extension methods with TPL async implementation

Usage is simple,

  1. Install from nuget
  2. Modify example template
  3. Press save
  4. Enjoy!


For example QueueClient, it have methods like:

public IAsyncResult BeginReceive(
	TimeSpan serverWaitTime,
	AsyncCallback callback,
	Object state

AsyncGenerator will generate:

public static Task&lt;BrokeredMessage&gt; ReceiveAsync(this MessageReceiver @this
                                            ,TimeSpan serverWaitTime)
      if (@this == null) throw new ArgumentNullException(&quot;this&quot;);
      return Task&lt;BrokeredMessage&gt;.Factory.FromAsync(
                @this.BeginReceive, @this.EndReceive,
                serverWaitTime, null);

Now you can use azure in normal C# 5.0 way:

var message = await queue.ReceiveAsync();
if (message != null)
     await message.CompleteAsync();



Tagged , , , , ,

SharePoint + TypeScript = Love

Few months ago I became SherePoint developer, and this is like developing in damn stone age. No async, no SignalR, no .. , actually there almost nothing from last years. Mad. If you need something post 2008, you are out of lack. But this is like 8-bit game. You know this feeling of playing games on ZX-Spectrum? So let’s play.

  • Obviously, you need install TypeScript. It will ask restart everything, I also restarted few servers, just in case.
  • Create new TS file (for example in Layouts folder), you need to use Add New Item dialog, because otherwise VisualStudio will not assign (and will not allow you)  TypeScriptCompile to Build Action property of the file. image
  • Try to compile. File.js under File.ts should be JavaScript compiled from TypeScript. For me it does not work however. Fix is here.  You just need to add BeforeBuild target to call compiler. Make sure that path to compiler is correct.
  • Try compile another time. This time it should work.
  • After I got this working, level of impression raised exponentially. Writing JavaScriptTypeScript became much more pleasant.

    Some missing points:

    1. Somehow I need remove TS files from result WSP file.
    2. I need better way to manage TypeScript definition files in solution, but this is general problem of how integrate NuGet content packages to SharePoint project.

    Overall impression is 4.5 from 5

    Unit testing, you are not doing it right

    Almost all developers do mistakes listed bellow and I cannot blame them, everybody should learn new stuff.

    1. You should test DateTime.UtcNow to return current UTC date and time. This is quite important. Do not forget to test DateTime.Now too. You can use standard atomic clocks to automate testing
    2. Guid.NewGuid() potentially can return duplicates, this should be one of your first tests, remember that even if you do not use Guid.NewGuid(), frameworks you use, probably use it. Problem is worse than it looks in the first place, for example SQL Server uses it’s own Guid generator. You should test SQL Server NEWID() either
    3. Integers are even more evil than Guids. You must always check if values are natural numbers
    4. File.Exists is also good candidate for testing. Many developers underestimate potential bugs this method could introduce. Once I have a bug with 9 zeros in it. Good that it was issue number, not profit loses
    5. Random.Next.. oh my. Most of the real word apps have problems with security because of this method
    6. Always test that today is no leap day if you do not want something like this
    7. When you are doing UI coding, always check that your windows are rectangular, even 1° can be fatal
    8. For desktop applications always test that application runs on correct on 59bit CPUs. In some case stuff like Int64 just does not fit to CPU registers. You can safely ignore this if you write code in VB.NET
    9. Do not forget test async code that it really runs async. This is too easy make this mistake
    10. Always test spelling of class names, recommended is NUnitSpell but any other extension you your test framework are OK


    Copyright © 31337 – 2012


    Mission: Zip with MsBuild 4.0 with no binaries in source control

    I need to package results of the build to the ZIP file. Options:

    1. Zip task from MSBuild Community Tasks Project
    2. 7z.exe or something else in source control
    3. Custom task
    4. Code task

    And considerations:

    1. The MSBuild Community Tasks Zip task requires tasks lib to be included before build. This actually means that you cannot download it from build script. They have Nuget Package, but if you use package restore you are out of lack.

    2. Second option is to use one of the zip compression tools. Main problem that you need this exe. So if you do not want it in your source control, you need to download it. You can try chocolatey, but I decided that this is too complicated for me.

    3. Custom task. I think this is joke.

    4. Code task. With UsingTask element you can just code your task with C# directly in MsBuild file. In most case this sounds like an overkill, but anyway I will go with this option.

    Zip Task Implementation

    You need something to make a zip. You can actually use any library , but I will use one that is shipped with .NET 4.5.

    Important, you should have .NET 4.5 installed to make this work.

    The following gist is actual implementation.

    And it works Smile. Mission complete.

    Tagged , ,