Monday, January 26, 2015

Generating standalone binaries for Mono project (like a boss)

I see a lot of distrust in msbuild and especially xbuild scripts. Many developers prefer writing bash or worse, batch scripts which build the project. But why to add complexity if you have necessary tools at your disposal?

If you're writing some app that you want to distribute, you really need a standalone binary. For Mono, it can be easily generated by mkbundle utility. You really want to automate this stuff. So, what is the easiest way to do it? Make a new step in build scripts.

In xbuild scripts, just as in msbuild, there is an Exec task, which allows you to run an arbitrary application. So, in Mono it would look something like this:
  <Target Name='AfterBuild'>
  <Exec Command="mkbundle bin/$(Configuration)/PowerCertmgr.exe -o power-certmgr" 
        Condition="'$(OS)' == 'Unix'" />
  </Target>

We want to run this script only if OS is Unix-like. Why? Well, I'm working in Linux and I don't really care about Windows :) One should check if it runs on non-Unix systems, and in case of problems provide alternative implementations.

Even though xbuild scripts are underdeveloped compared to msbuild scripts, they can easily handle work like that. I really hope this approach will be more popular.

Saturday, January 17, 2015

Rewriting Mono's certmgr

While trying to run ASP.NET 5 on Mono, I was using certmgr from Mono security tools to import some certificates for NuGet. I was dissatisfied with this tool due to the following reasons:

  • I was unable to list existing certificates, as you need to supply the store name. You have to specify one of the 5 possible store names (My, AddressBook, CA, Trust, Disallowed). Do I need to say there's NO MENTION of these names in certmgr documentation? I was unable to find that list somewhere in the web either. The most reliable way is to get it from the code.
  • It crashes almost every time when incorrect parameters are supplied. Not that it's fatal; it's just aesthetically unpleasant for me to see something like
    Unhandled Exception:
    System.IndexOutOfRangeException: Array index is out of range.
      at Mono.Tools.CertificateManager.Main (System.String[] args) [0x00000] in :0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Array index is out of range.
      at Mono.Tools.CertificateManager.Main (System.String[] args) [0x00000] in :0
    
    
  • Code is rather sloppy, with suboptimal variable naming, unused variables, etc. My favorite part is extremely strict certificate validation:
    static bool CertificateValidation (SSCX.X509Certificate certificate, int[] certificateErrors)
    {
        // the main reason to download it is that it's not trusted
        return true;
        // OTOH we ask user confirmation before adding certificates into the stores
    }
    
I think that's enough reasons to fork it. Why not send a pull request? First of all, I think it's wrong to bundle the tool with Mono. It's an independent tool, it should be possible to update it without touching the Mono core.

So my plan is as follows:

  • Refactor certmgr to run standalone (done)
  • Set up continuous integration (done)
  • Fix existing bugs (in progress)
  • Write unit/integration tests
  • Make tool more user-friendly (e.g. display certificates from all stores by default?)
  • Implement some new features?

That's where could use some input from other people. If you have some ideas or want to contribute code - please open issues/requests on project's page on GitHub.

Wednesday, January 7, 2015

Challenge

At the start of the new year, I decided to take a challenge of building some relatively complex open-source project - a forum engine. My primary goal is to expand my knowledge, but I really hope that the said engine will be useful to somebody.
I don't anticipate any big interest, as there's nothing really sexy about this project - no node.js, Ruby or whatever is considered sexy now. There is also no high demand for forum engines, as far as I see. However I want this project to embody things that matter to me, like a good coding standard (I like the one of .NET Core), simple self-documented code and really simple architecture. As of now, project is in 'early alpha', I'm still developing the core and shaping the architecture of the project. But, if you happen to have some nice idea, or maybe you've spotted a bug in the code - you're really welcome to contribute by creating issue or pull request.

Sunday, August 3, 2014

Web Workers in practice - Integration (HTML5)

Intro

Couple of years ago, web workers (along with other HTML5 stuff) suddenly became popular. On the  spike of their popularity, many tutorials were written. However, the moment of popularity was very brief, mainly because, well, you don't need this in your regular JS application. The common use case - blocked UI because of long-running script - is rather rare if you use modern browser with fast JS engine.
Have you really seen something like that recently?
In lots of tutorials all the workers did was passing messages to main script, where it was printed to console or put in some DOM element, which doesn't give you any feeling of concurrency at all.
More advanced ones included prime number sequence generation, which was more like it, as this is a really long operation, especially when you generate a long sequence :)
In this tutorial I'll try to show another example how web workers could be useful in practice - in other math problem.


Saturday, July 26, 2014

About Windows Phone 8.1 usability

This is interesting. While it's obvious that WP UI was designed with attention to details, some of the user experience is not pleasant at all. For example:

1. When you start using your phone, you can't update or install any app, unless you set the correct date. Technically, it fails when you try to create Outlook account (or "live id", whatever), which will be bound to the phone. Problem is that error message is extremely cryptic, stating only that update/install failed and providing error number. Googling up the error number revealed no specific details (at least to me). So I had to google once more, why the phone update could fail which gave me the page with possible problems, mentioning the need for correct time. My guess is that it reaches out to MS server to "activate" the phone. Anyway, it was quite unpleasant.

 2. Windows store app. I think it's not obvious that app updates are in downloads section. It took some time for me to figure it out.

3. Setting time by scrolling the rectangles with numbers is a bad idea IMO :) It may seem good to designers, but I'd prefer to type the numbers.

4. No changelogs in most of app updates. I mean those pre-installed apps like "News", "Weather" and Nokia stuff.

But all in all I can't say that I'm too disappointed. It runs rather smooth, and rectangle UI, while new to me, is an interesting concept.

Thursday, April 10, 2014

Programming Pocketbook - jumpstart script

As you may know, it's possible to build apps for some older Pocketbook models, that run Linux. There are 2 SDKs for that, that I'm aware of - official and unofficial one, the latter being much more popular. Unfortunately that SDK comes with no templates. So to start development from scratch, you have to manually create a bunch of file yourself, like the makefile and the source code file, which is not fine in the XXI century. To automate the process, I created this small shell script, which creates them for you, using a name you specify:
#!/bin/bash

echo "Input project name:"

read proj_name

mkdir $proj_name
mk_file_name=$proj_name".mk"
c_file_name=$proj_name".c"
master_makefile_name="Makefile"

cd $proj_name
echo "SOURCES += "$proj_name".c" > $mk_file_name

echo "OUT = "$proj_name > $master_makefile_name
echo "include /usr/local/pocketbook/common.mk" >> $master_makefile_name

echo -e "#include \"inkview.h\"\n\nint main(int argc, char **argv)\n{\nreturn 0;\n}" > $c_file_name
Hope it hepls you too.

Saturday, March 8, 2014

Running old ASP app on Windows 7 - 401.3 unauthorized problem

There's a great article here about how to run and debug that 'classic' ASP site of yours, if you happen to have one. However, if you make just the steps from article, you'll probably end up with "HTTP Error 401.3 - Unauthorized" error. The solution is simple and found on serverfault - you just have to grant the IUSR user at least a Read&Execute access to your website's folder. Just like that:
Hope I saved you some googling.