Debug EF migration

Add the following lines in the migration code:

if (!System.Diagnostics.Debugger.IsAttached)

This launches and instance where you can debug inside an Entity Framework migration method.

I found another regular expressions tester at http://regexstorm.net. It’s great, it even shows group hits!

This is my first python program ever, so bare with me if it’s not perfect.
This allows you to execute commands to mirobo so you can interact with the Xiaomi vacuum robot.

I use this small program to start/stop the robot, get status from it, etc from my (old) wall mounted tablet that runs Imperihome.

Here is the code:

# app.py file:

from flask import Flask, request
import subprocess
import logging

app = Flask (__name__)

log = logging.getLogger(‘werkzeug’)

def status():
command = “status”
return executeMiroboCommand(command)

def consumables():
command = “consumables”
return executeMiroboCommand(command)

def start():
command = “start”
return executeMiroboCommand(command)

def stop():
command = “stop”
return executeMiroboCommand(command)

def spot():
command = “spot”
return executeMiroboCommand(command)

def find():
command = “find”
return executeMiroboCommand(command)

def home():
command = “home”
return executeMiroboCommand(command)

# 38 quiet, 60 balanced , 77 turbo , 90 max. Different value than app may cause app button to stop working
def fanspeed(speed):
command = “fanspeed %s” % speed
return executeMiroboCommand(command)

def cleaning_history():
command = “cleaning_history”
return executeMiroboCommand(command)

# todo dnd, volume?


def executeMiroboCommand(command):
result_success = subprocess.check_output(“mirobo ” + command, shell=True)

except subprocess.CalledProcessError as e:
return “An error occurred”
#Read more at https://www.pluralsight.com/guides/python/running-shell-commands-with-flask#iaQlrC0rPigBRpcK.99

decodedResult = result_success.decode().replace(‘\n’, ‘<br>’)
return decodedResult
if __name__ == ‘__main__’:
app.run(debug=True, host=’′)


How to use
Start it by running python3 app.py

then connect to it by using the different commands like
http://<ip adress>:5000/mirobo/<command name>

<command name> could be any in the last part routes above, for instance status.

For example:



Well, I finally got it working! Do as follows to install Swedish language on you Xiaomi Vaccum Robot v1 (does not work on v2).

  • Get hold of the secret key for communicating with the robot, this can be obtained by installing an old version of the Xiaomi app (newer ones has fixed this obvious bug) on you Android phone and then run the program MiToolKit on a pc to extract the database from the app.
    After that you need a browser for SQLite and open the miio2.db database file. Look for the column token, which holds the secret key in the devicerecord table. You can also see the ip adress of the robot in this table, which you need later.
  • Download dustclouds package and install that on a Linux enviroment (instructions can be found on the supplied link). By using the token and the ip of the robot you now can control is using the mirobo commands.
  • Go into the folder sound_generator/languages and copy one of the existing files which contains the texts that generator will use. Open you’re copied file and translate the texts to Swedish.
  • Run the sound_generator in python by using the command ‘py sound_generator.py’, select the language for Swedish and the selected tts engine.
  • Go into the newly created folder for the laguage, and run the command “md5sum sv.pkg”, this will give you the md5 the mirobo uses to install the sound.
  • Run the mirobo install_sound, with the created sv.pkg and the md5 value you got from the md5sum command. The sid can be any number >0, for instance 666. I have troubles running the command as a self containing server, so I had to put the sv.pkg up on a webserver and run the install against that server.
var myString = Regex.Replace(myString, @"\s+", " ");

I had problems adding a input field dynamically to the JQuery client side validation. This is how I solved the problem:

In javascript, I added the following, when checking a checkbox:

$("#idOfMyInputField").attr("data-val", true);
$("#idOfMyInputField").attr("data-val-required", "Custom error message");

I also needed to re-initialize the validation of the form (this does the trick to the validator to find the new validation):

var formSelector = "#idOfMyForm";

When, un-checking the  checkbox, I simply removed the data-val attributes with:


And then, re-run the re-initialize code once again (like above) so the validation is removed for the input field.

I also tried using the rules add method directly on the input field i JQuery, but somehow I didn’t get it to work (maybe the version of JQuery we use is too old for this, I know there are some bugs at least for the messages part that is fixed).

If you want to use another remote together with Nvidia Shield TV, it can be done with the Flirc dongle. I successfully used this together with an Apple TV remote (I already has the Shield remote, but it often runs out of power, so it’s nice to have another remote as backup when charging the Shield remote). You can basicly use any IR-remote of your choice with Flirc.

Do like this, if you want to map keys for the Shield:
– Connect your Flirc dongle to your computer and use the Flirc GUI to start mapping keys.
– Use the full keyboard as controller (Flirc has the Nvidia Shield TV as a controller, but I didn’t get it to work with my apple remote).
– Map Up, Down, Right and Left to your remote.
– Map Enter (not Enter/Return) to Select on your remote.
– Map Backspace to Back on your remote.
– Map Windows key + Enter to Home on your remote.
– Connect the Flirc dongle to the Shield and start using the remote 🙂

I’m working with a DevExpress report for the first time, and tried to set a class i created as data source.
My class had nested classes inside, like this:

public class InvoiceReportModel {

public class Data {
public string Title { get; set; }



And guess what? DevExpress could not handle this.
DevExpress didn’t show any data fields for my data source in Visual Studio. By removing the inner class and moving all properties to the top class all my fields where shown.

Today (on my 40th birthday of all days) I got the error “Git error Unlink of file failed”, when trying to do a fetch from origin in git.

First I tried to restart the computer (since it might be an indication of some file is locked by another program), but that didn’t help.

The resolution to this error is quite simple, I just ran the command “git gc” (which cleans up the repository).

There are several ways to remove unwanted characters from a string, here is one quite nice…

char[] unAllowedCharacters = “/\\.,;:+*’§½\”<>|!?$&=@#%{}^~[]`´¨¤”.ToCharArray();

text = String.Join(“”, text.Split(unAllowedCharacters));