Well, that’s the most uninspirational title ever. Especially because this is the first blogpost in ages on here. Anyhow….

The problem:

So a colleague of mine wrote a very hefty 300 pages tome on electric fundamentals. It is written in Microsoft Word but, being the 21th century and all, we really would love to have this syllabus also as an online gitbook.com-site. However, it contains 700+ equations that just won’t get converted.

When we used gitbook-convert on the docx the output it generated was okay-ish (though the image uris needed some manual labor afterwards). However, no equations to be found whatsoever, it simply skipped those like a lazy student.

The solution:

After dicking around with several “solutions” from stackoverflow we finally managed to get the solution ourself. As a fair warning: I suck/can’t use regex so you will see some cringy stuff down here…but hey, it works and that’s what count!

How we solved it:

Saved the .docx document as an open office document (ODT) from within Microsoft Word.

Send the odt through my epic code (seen below) which does:

Unpack the odt file (it’s just a zip with lots of xml-files)

Identify the equations in the document

Transforms the equations to Mathjax compatible versions

Insert transformed equations into odt

Repack everything to an odt file

Send the odt through gitbook-convert

Profit!

Gimme epic code!

Ok, so step 2 was ofcourse the main problem. Here’s “a solution”, but as warned it’s just a quick’n dirty fix.

Step 1: Unpack the odt file

System.IO.Compression.ZipFile.ExtractToDirectory(source, tempfolder);

Easy huh 😀

Step 2: Identify the equations in the document
Using a very science-y way we discoverd that all equations are conveniently inside subfolders called “Object x” (x being a number) in which the actual equations is described in a separate content.xml document using mathml, the openoffice way of describing equations.

So we used a simple loop over all extracted folders to identify the xml-files we needed.

Step 3: Replace the equations in the document with Mathjax compatible version
This is the meaty part of the solution.
There’s several XSL-files to be found online that transform MathML to MathJax/Tex format. So we used one such as this one.

So first we iterate over all the found xml-files from the previous step and transform them using the xsl-files:

foreach (var item in files)
{
var myXslTrans = new XslCompiledTransform();
myXslTrans.Load(@"mmltotex\mmltex.xsl");
using (StringWriter sw = new StringWriter())
using (XmlWriter xwo = XmlWriter.Create(sw, myXslTrans.OutputSettings)) // use OutputSettings of xsl, so it can be output as HTML
{
myXslTrans.Transform(item, xwo);

Next we need to safe this transformed equation so we can later on inject it inside the actual odt-document.

Before saving the transformation I also cleaned it up a bit so that gitbook won’t start crying like a little baby (It’s not very happy with two opening curly braces next to each other and with multiline equations). After cleanup I save each equation in a dictionary with the foldername being the key since this is the same id the main odt-document (content.xml in the root of the odt/zip) used to pinpoint to the xml files in the Object-folder (long sentence, too tired to write out :p) .

And finally I add the much needed extra dollar signs since my xsl only adds one and we definitely need two at the start and end:(

In this short guide I will demonstrate how to create a simply outlook-plugin (VSTO add-in), consisting of a button that can be clicked in the Ribbon-bar and that will result in some custom action (in this case saving all attachments to your computer).

The reason I wrote this guide is because the standard documentation didn’t really go all-the-way and/or went too deep too fast while creating a plugin I needed (a “Send All Attachments to Calibre” add-in, more info here).

To business: I recently bought two 8bitdo Nintendo Controllers (8Bitdo Crissaegrim NES30 PRO) to use with RetroPi (works like a charm by the way).

However, to get them to work on my computer was something else.

The controllers don’t talk very nicely with your PC, so Steam and Monogame basically say ‘$$$$ you’ when you try to use the controller. However, the solution came in the form of this nifty tool: x360ce.

Ok, now what? Play steam games?!

The thing to know with x360ce is that you need to place the executable in each folder of the game(s) you’d like to play with your computer.

Paste the exe there, launch it, let it create the necessary files, test the controller and presto: you can now launch the game (from within steam if you also want your steam controllers to work) and the games will now detect your controller as if it were an Xbox 360 controller. (protip: this also works if you’re using the controller wireless, even with two of them connected without wires)

Pressing lots of stuff on the controller and simultaneous trying to take a screenshot…not easy, try it yourself!

Monogame as well?

Yup, the same trick here. Simply put the x360ce exe in your debug/bin folder, launch it, and suddenly you can type fancy code such as (source) :

if (capabilities.IsConnected)
{
// Get the current state of Controller1
GamePadState state = GamePad.GetState(PlayerIndex.One);
// You can also check the controllers "type"
if (capabilities.GamePadType == GamePadType.GamePad)
{
if (state.IsButtonDown(Buttons.A))
Exit();

Hooray for this. On to toying around with this sweet nostalgic controller

After install black screen

Apparently the Ubuntu Server is very barebones and on my netbooks it simply boots to a blank screen with a blinking cursor. Nothing more. To get started, you need to openup a terminal using ctrl+alt+F1. Yeah, I’m a linux noob.

Only boots using usb stick 😦

I followed the tutorial as is and discovered that my fresh Ubuntu wouldn’t boot unless I inserted the original USB-stick from which I had installed Ubuntu in the first place. The problem? The Ubuntu installer installed Grub on the stick instead of on the master harddisk.
This can be remedied simply by using the command:

sudo grub-install /dev/sda

Autologin and boot to terminal

The part about configuring tty1 to automatic login doens’t work anymore in more recent Ubuntu Server version. What you will need to do is oveeride the getty.service, as explained here.

Connecting to wifi is real hard

Most modern wifi networks have WPA or WPA2 security, which is a bit of a pain in the a$$ to get connected to using a terminal-only shell.
Luckily a nifty tool called “nmtui” exist which is basically a text-based UI network configurator.It can be installed using:

sudo apt-get install network-manager

and can then be started by typing:

nmtui

Getting battery status

I’ll show how to have a two-way databinding between a templated listbox and a MongoDB collection.
I’m finally got around toying with MongoDb.What I’ll show next might not be the most correct way, but it works for me.

I created an Entity class (can be a composite if you wish) which is is simple POCO with INotifyPropertyChanged implented. This Entity class well be serialized to my MongoDB collection as-is. Explained here, for example:

public class Entity
{
public string Naam { get; set; }
}

Retrieve the data and databind

Next up, we need to retrieve the data using a query (coll being my collection a retrieved earlier on (not shown)):

var query = coll.AsQueryable<Entity>().ToList();

The ToList part is important.This will ensure that we get a simple list of Entity objects as our ItemSource and not an IQueryable, otherwise the next part won’t work.

Write changes to database

You can now edit your data in your listbox and once you are ready, you can update all the changes to your MongoDB collection:

I wrote a small C# portable class library (.NET4.5/WP8.1/Win8) that allow users to talk with the Smappee API.

Intro

I recently bought a Smappee and I really love the device. It enables me to track the power usage of all my devices throughout the house and I even found some nasty buggers who consume way more than they should. Currently only Android and IPhone users can really benefit from this device (the my.smappee.com webapp is too lightweight to really utilize the full power of the device).

I’m planning on writing a simple Windows Phone 8 app (and perhaps Windows 8) to have some basic information Smappee data on my phone. Unfortunately the API is pretty meagre (you can’t access everything needed), so I won’t be able to recreate the existing Android app. The full API documentation can be found here.

Getting started

Before you can use the public API, you will first need to request the credentials (client_id and cleint_secret) from Smappee, explained here. Once that is done, you’ll also need to have an active my.smappee.com account, which you can create using the Iphone or Android app (you can’t do this through the website unfortunately). These 4 credentials will be needed to access the API.

What’s missing

This code was build a few minutes ago and a lot is missing. Specifically:

No exception handling whatsoever

The Actuator duration can’t be set, because the API has a strange way of doing this (you can give only the value 300,900,1800 or 3600 , specifying the time in seconds the actuator
should be turned on. Any other value results in turning on for an undetermined period of time. )