“Operation could destabilize the runtime” caused by dynamic invoke.

Dynamically invoking code can sometimes mask errors that actually are pretty simple to fix. If you come across problems like this, it’s probably a good idea to try to reproduce the problem as close to the calling code as possible, in order to see the actual error message, instead of something generic like the title of this post.

Continue reading

MasterCard’s new biometric security

I came across this announcement today. Apparently Master Card is applying biometrics in an attempt to make online shopping faster and safer. My impression of the current state of biometrics is that it is not great. Some technology may be considered reliable (a relative term in any case), but it is generally expensive, and typically consists of invasive things like retina scanning, which requires a person to physically lean close or right up to a specialized piece of equipment. General consumer technology like the fingerprint scanners on phones and the like are easily fooled, and may give a false sense of security.

So what is Master Card using? Well according to articles from biometricupdate.com and mobileworldlive, they’re experimenting with fingerprint scans and short video shots of faces (facial recognition) as replacements for passwords when authenticating payments. CNN Money has this video demonstrating the facial recognition solution.

The motivation behind this is to make security less of a hassle for customers, to keep them from abandoning purchases at the final step. I think this  is an interesting and admirable effort, and the solutions seem pretty cool. A number of questions come to mind though:

Continue reading

How to get up and running with Python in Emacs

I did some programming in Python many years ago (around 2001), but haven’t touched it since, though I always thought I would come back to it at some point. Today, I finally got around to installing and testing it a little.

The python installation on Windows 10 was impressively easy (get it at python.org). I had it up an running in the REPL (or the IDLE, as it is called in the case of Python) almost immediately. Writing a new script is as easy as opening a new file using the standard top menu, and pressing F5 to run it in the REPL. Wonderful. Now to get it working in Emacs.

A little bit of searching indicates there is lots of relatively advanced information available, but all I wanted at this point was a quick and simple way to get a REPL with python running in Emacs. How to do this was not obvious, but in the end this too turned out to be easy.

Running python:

  • Open a Python shell in Emacs: C-c C-z
    Note: When I installed Python, I made sure to add python to the environment variables. I’m assuming this is why this worked so easily. Apparently, support for python mode (python.el) is included from emacs24 and onwards, and once pythons was installed on my system, nothing more was needed for Emacs to find and run it.

  • Run a Python script: C-c C-c
  • This assumes the file is open in Emacs, and that a python shell is running.

  • Run a selected region of a loaded script: C-c C-r

    …And that’s basically it. You should now be able to open a file. write Python code in it, and compile it in the REPL, as well as enter Python commands directly in the REPL.

How to switch desktops when Hyper V steals your focus

I currently run Windows 10 as my main OS, yet I often run Windows 8.1 in a virtual machine under Hyper V to work on a project no longer supported in Windows 10. This is quite practical now that multiple desktops are supported out of the box: I typically run Windows 8.1 in full screen on a separate desktop, so it does not interfere with my other desktop(s).

Tip: In Windows 10, press the Windows key + Ctrl + D to create and switch to a new desktop. Hold down Ctrl and the Windows button while pressing the right or left arrow to switch between desktops. You can also use win + Tab, and click the desktop-icons at the bottom of the screen to switch between them.

One thing I found annoying was the difficulty of switching away from Hyper V and Windows 8.1, since the virtual machine will typically steal the focus. I’ve found a relatively simple solution now though: When the focus is in Hyper V, Ctrl + Alt + Left arrow will move it out and into the outer context – in my case away from my virtual Windows 8.1 machine, and back out to Windows 10. This shortcut is probably not new, but I was unaware of it until recently.

In short:

  • To move from a regular Windows 10 desktop and right into a full screen windows 8.1 desktop, I’ll use: Ctrl + Windows + arrow key.
  • To move back out from Windows 8.1, I’ll first press Ctrl + Alt + left arrow, followed by Ctrl + Windows + arrow key.

This may sound a little awkward, but I’ve found it surprisingly easy to get used to, and as far as I can tell, this appears to be the easiest way to escape from a VM.

Replace a string with newline in emacs

I sometimes find myself wanting to replace certain strings in a text file with a new-line character. Not with “\n” or “\r\n” mind you, but an actual break to make the text more readable in the editor. Take for example a random stack trace from Visual Studio. I sometimes copy these out to another simpler text editor to examine them closer. The problem is that when pasted, they will appear as a single line with “\r\n” instead of actual line breaks:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)\r\n at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)\r\n at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)\r\n at System.Windows.Forms.AxHost.CreateInstance at System.Windows.Forms.AxHost.GetOcxCreate()\r\n at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)\r\n at System.Windows.Forms.AxHost.CreateHandle()\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.AxHost.EndInit()\r\n at MyApplication.frmPrint.InitializeComponent() in (...)

If your text editor breaks lines at the edge of the window, it might look more like this:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& 
clsid, Object punkOuter, Int32 context, Guid& iid)\r\n at 
System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid 
clsid)\r\n at System.Windows.Forms.AxHost.CreateInstanceCore(Guid 
clsid)\r\n atSystem.Windows.Forms.AxHost.CreateInstance at 
System.Windows.Forms.AxHost.GetOcxCreate()\r\n at 
System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)\r\n at 
System.Windows.Forms.AxHost.CreateHandle()\r\n at 
System.Windows.Forms.Control.CreateControl(Boolean 
fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl(Boolean 
fIgnoreVisible)\r\n at System.Windows.Forms.AxHost.EndInit()\r\n at 
MyApplication.frmPrint.InitializeComponent() in (...)

..which may be better, but still not very readable.

Most text-editors have some form of replace-all utility built in, but it’s not always easy to replace “\r\n” with an actual line shift (try it!). In Emacs, there is a nice way to handle this:

Use M-x Replace-String to prompt for the string to replace. Enter “\r\n” in the mini-buffer. Press enter, and it will prompt for the string to replace it with. At this point, use C-q C-j to input a new-line (C-j) as quoted text (C-q), and press enter again.

The result will be a much more readable stack trace:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at MyApplication.frmPrint.InitializeComponent() in (...)