Monthly Archives: September 2013

My blog is number one in Google!

Finally, when I google myself the first result is my blog.

Google Jakub Jedryszek

It is a little bit worse, when I google with Bing. The blog is on 4th position. Microsoft! Do your homework!

Bing Jakub Jedryszek

Interesting thing is that Google return 16 700 results, while Bing only 45. Is Bing producing better quality?

Of course it doesn’t mean that it will be 1st (in Google) and 4th (in Bing) when you are googling. The reason of that is well known. Google and Bing adjust search results for you. Some friends of mine got my blog on 4th place, some on 1st. It’s probably dependent on who likes me more 🙂

There is one search engine, which returns the same results for everyone: DuckDuckGo. Bad news is, that it doesn’t return my blog at all.


Polish Coffee Hour

Yesterday (September 20, 2013) I had presentation about Poland at Kansas State University. It was part of “Coffee Hour” program (student’s presentations about their home countries). Thank you for everybody who helped me to prepare this presentation and food (placki ziemniaczane, pierogi, bigos). I hope that everyone who came enjoyed it 🙂

I recorded the presentation:

Slides are available online: Poland-CoffeHour4x3.pptx (~600MB).

It’s big (over 600MB) because it contains background music and movies. I spent a lot of time preparing it (collecting materials, making it short and rich in the same time, and appropriate for international audience). I share it with you, because maybe some day you will need to prepare something similar. Then feel free to use mine:)

EDIT: There are wrong dates of 1st World War. It supposed to be 1914-1918 (instead of 1814-1818). It’s already corrected in the Power Point presentation (but not in the video).


OWIN and Katana – what’s the big deal?

OWIN stands for The Open Web Interface for .NET. It is a standard for communication between .NET web servers and web applications. It defines required elements for HTTP request (details). It is inspired by Rack from Ruby on Rails World. Katana is implementation of this standard. We can say that it is a lightweight web server for .NET. In fact, it is more than that (more info here).

Demo

First, we need to create application project. Let’s create ‘Empty Web Application’ (it might be also Console App).

OWIN - empty Project

Next, we will install two NuGet packages (using Package Manager Console):

Install-Package Microsoft.Owin.Host.SystemWeb

Install-Package Owin.Extensions

Then, we need to create ‘Startup class’.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Owin;

namespace OwinDemo
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseHandlerAsync((req, res) =>
            {
                res.ContentType = "text/plain";
                return res.WriteAsync("Hello Katana!");
            });
        }
    }
}

Now we are ready to run our web server, but you may get following error:

OWIN - error

Fortunately there is easy fix for that. You need to modify Web.config file, adding following code in configuration section:

<appSettings>
    <add key="owin:HandleAllRequests" value="true"/>
</appSettings>

Then you can run server (CTRL+F5) and you should see:

OWIN - Hello Katana

Summary

So, what is big deal? We have web server in 7 lines of code! We do not need IIS as only one, right choice.

Of course we can do much more sophisticated things. Such as routing, WebAPI or even SignalR. You can also debug it easily.

More info about OWIN and Katana on ASP.NET website: An Overview of Project Katana
There is also screencast on Channel9: The Katana Project – OWIN for ASP.NET (it shows e.g. how to use WebAPI from 35:40).
Here is very nice article how to use SignalR with Katana.

Katana is Open Source and available on CodePlex.


scriptcs – C# in console

It was always bothering me, when I wanted to run one simple command, and I needed to create new C# console project in Visual Studio to do that. With scriptcs I can finally do that in console. Project scriptcs allows you to run single commands and also C# script files.

Installation

The easiest way to install scriptcs is Chocolatey (‘apt-get’ for windows). If you didn’t hear about it, you should definitely try it out. To install Chocolatey run the following command in console:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Once you have Chocolatey installed, you can install scriptcs:

cinst scriptcs

Chocolatey will install scriptcs to %APPDATA%\scriptcs\. You need to update your PATH accordingly, to easily run it from command line.

Getting started

Once scriptcs is installed and added to your PATH, you can run it with scriptcs command:

C:\> scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, world!";
> Console.WriteLine(message);
Hello, world!
>

C:\>

You can also create a script hello.csx:

var message = "Hello, world!";
Console.WriteLine(message);

And run it from command line:

C:\>scriptcs hello.csx
Hello, world!

You can find more about scriptcs on scriptcs.net.

EDIT: You don’t even need Console.WriteLine to print variables (thanks Filip W.):

C:\>scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, scriptcs!";
> message
Hello, scriptcs!
> int four = 2 + 2;
> four
4
>


A book that every programmer should read: The Elements of Computing Systems

I would like to say thank you to Scott Hanselman, who tweeted about this book. When I saw the content, I knew I will love it. And I was right.

The Elements of Computing Systems cover

The Elements of Computing Systems: Building a Modern Computer from First Principles is written by Noam Nisan and Shimon Schocken, who are University Professors. They created course based on this book (or wrote this book based on their course :)). The first 6 (out of 12) chapters are available for free at course website.

Why every programmer should read this book? Because it allows you to understand how computer works. It is going from logic gates, through machine code, intermediate code, compilers etc., to high level programming language. At the end of each chapter, there are exercises in which you are ‘building’ parts of the computer.

This book has only 344 pages and of course it doesn’t cover all details. Each chapter is kind of basic overview, however it is sufficient to get the idea and basic understanding before you go more deeply (e.g. into Computer Architecture or Compilers).

I really enjoyed reading this book. It is amazing how all those things we are doing everyday on our machines are done just by adding, subtracting, comparing and copying sequences of zeros and ones.

The book is available at amazon. There is also a website with more information about it (e.g. 10 minutes overview video), and software created for exercises (which you can find at the end of each chapter).