SafeBuffer and UnmanagedMemoryStream

Oct 10 2013

At work I have a situation where I have some binary data allocated in the native code. It’s pretty much a raw char*. I then would like to access that same information from the managed side. But how? Of course I can just copy the data to a byte[] but that’s just wasteful.

I did some googling around and found the obvious solution – UnmanagedMemoryStream. It can take pointers, or a SafeBuffer. The latter is basically a smart wrapper around memory handle. Take a look at the code I came up with. I hope somebody will find it useful. It’s still work in progress and can use some love, so any comments are welcome.


I needed to pass the std::unique_ptr as r-value, otherwise the linker complains (thunks for non-existent copy constructor). I still need to clean this code up to handle custom deleters. But it serves my needs for now.

No responses yet

Makes perfect sense!

Oct 08 2013

Rockets in Australia

No responses yet

HID Card and Android phone

Oct 07 2013

At my workplace we use HID ProxCard II cards to enter the building and to open individual doors. Everybody has a card with their picture printed on it. The problem is that I keep forgetting mine, plus I’ve had it for such a long time that the card started to disintegrate and it looks rather nasty.

HID card

I really wanted to just use my Android phone in lieu of the card, but it seems like HID cards are not compatible with NFC :-(
This of course wasn’t going to stop me. Somehow I wanted to “fuse” the card with my phone. If my phone had a plastic case or cover, I could just slip the card inside of it. But I own an HTC Once and since it’s made out of aluminium and gorilla glass, I don’t really need (or want) a cover for it. I decided to use a sticker to attach the card instead. I ordered a custom-fit sticker from SkinIt with a cute picture of my boys on it. Now I could finally start my project :)

Costom skin for HTC One


First I cut off a small strip of plastic along every edge of the card, starting with the top. Then I removed the front layer with the printed picture. It was clear that there were two additional layers to the card. Finally, I carefully separated the two remaining layers, exposing a copper coil and something that looked like a microchip.

Removed sticker and cut sides



Next step was to affix the layer with coil to the back of my HTC One. I chose not to remove the coil from the plastic it was glued to, and instead to attach the whole thing to the back of the phone with scotch tape. Of course I rounded it off a little bit witch scissors, just to make it look better.


Coil from HID card affixed to back of HTC One

The final step was to place the SkinIt sticker over the back of the phone. Sadly that didn’t go as smooth as I hoped. Since the coil and microchip are not perfectly flat, you can see a small bulge. It will take some time to get used to it, but ultimately it should not be a big deal. A small price to pay for the convinience.
Here is a photo of the finished product. Now I just need to remember to carry my phone around with me at all times at work :D

2013-10-07 17.56.12

No responses yet

NFC Extravaganza

Oct 06 2013

What’s cool about the new Android phones is that they support Near Field Communication (NFC) technology. This was actually one of the reasons I got my HTC One.


I can now use Google Wallet to pay with my phone, simply by tapping on NFC-enabled credit card terminal. Hopefully soon every point of sale will be accepting NFC payments, especially after Apple jumps on board and ships iPhones with NFC.

NFC payment

Tap to pay is pretty cool, but I was curious what else NFC can be used for. There is the obvious tap to share pictures, or contacts, but what else?

I did some googling and came across this website: TagStand not only sells physical NFC tags, but also provides neat Android apps for interacting with the tags. One can read and write data to NFC tags, and later use them as triggers to execute various actions. What does that mean? What can it be used for? Well, check this out.

NFC-enabled sticker

Car mode

Every time I get into my car I turn on navigation and Bluetooth, so that I can listen to music through car speakers. I also turn on the “car dock” app, so that the screen doesn’t lock while I’m driving. Of course when I leave the car I need to remember to turn all that stuff off. Pretty repetitive… NFC to the rescue!

I got myself several NFC stickers from TagStand and installed NFC Task Launcher app to my phone. I placed a circular, water-proof tag right next to the gear shifter. Now all I have to do is to tap the sticker once I get into the vehicle.

2013-10-07 15.51.27

The NFC Task Launcher app is programmed to execute these tasks when phone is near my “car mode” tag:

Car mode taskIt’s pretty awesome. I don’t need WiFi, since I’m on the road. But I want GPS, Bluetooth, car dock, loud volume. Just for fun I have the phone say “Car mode activated. Have fun but drive carefully.” The only thing to watch is space. The NFC tag I’m using has only 144 bytes ;)

I also use my car’s Bluetooth as a trigger – when the phone detects car is no longer connected, it will execute the following steps:

Out of car

I never need to worry about doing this manually again :-D  Next I need to consider buying an NFC-enabled cradle; then I think the project will be complete.

NFC cradle

Other possible uses

I can picture placing the tag at work for time-keeping reasons, or at the church entrance. First tap to activate the “church mode”, second tap to disable it (vibrate mode, Bluetooth off, GPS off, WiFi off, Bible app on). Although for these you could use a “geo-fence”, but constantly checking location brains the battery.

I promise to write more once I come up with any more clever uses for the NFC awesomeness.


Edit: I was hoping to use my phone’s NFC as smart HID card at work, but the frequencies do not match. Came up with an alternate solution.

Update: I found a good website ( which offers cheap NFC stickers, as well as high quality custom made NFC business cards. Definitely a must for high tech companies ;)

No responses yet

Hello (and goodbye) Tumblr, WordPress it is

Oct 06 2013

After years of using, I decided I’m tired of hosting my own content and dealing with the lack of themes.

There were many contenders for replacement, but ultimately I settled on Tumblr. It’s easy, let’s me use custom domain name for free and, ever since it got acquired by Yahoo, it seems fast enough.

The only downside was importing content. I was very surprised it does not support BlogML! That’s just crazy. I had to hand code a simple importer in Python. Not a big deal, but still… Unfortunately all my permalinks are gone :-(
Not the end of the world, since I don’t have that much content.

I guess we will see how it goes. I can always switch to something that gives me more flexibility.

Edit: And so it happened. I didn’t really like the way editing of posts happens on Tumblr, especially that it’s difficult to insert images into text posts. So I decided to switch to WordPress. Still didn’t bother with the permalinks (someday I will remap them), but I’m quite happy for now.

No responses yet

Async keyword alternative

Nov 03 2012

Unfortunately, both MonoTouch and Mono for Android still don’t support the async keyword. Raw TPL is rather inconvenient to use. You have to remember to catch exceptions, return faulted tasks, etc. ContinueWith can also be inefficient due to thread switching.

Today while browsing the interwebs I came across Brad Wilson’s blog post which led me to these two files. TaskHelpers are (no pun intended) very very helpful! The extension methods emulate the await goodness pretty well.

I modified them a little bit. Here is a gist.

No responses yet

Netflix Error Code N8156-6013

Aug 17 2011

My wife came across this mysterious “Netflix Error Code N8156-6013” today and let me tell you – she was not happy. Netflix player keep complaining about DRM and date (which was correct). It took me a good 20 minutes to find a solution. Credit goes to Chad (read his post here). I’m reposting to give the solution more exposure.

The fix after much research is to delete a Playready config file mspr.hds (leftover from the Silverlight 3 version) and allow the Netflix player to re-create the file using Silverlight 4.
The file to delete or rename (probably safer; in case something goes wrong just rename it back correctly)

On Windows XP:
C:Documents and SettingsAll UsersApplication DataMicrosoftPlayReadymspr.hds


On Windows 7:
C:UsersAll UsersApplication DataMicrosoftPlayReadymspr.hds

C:ProgramDataMicrosoftPlayReady (Thanks Jarin)

HD > Library > Application Support > Microsoft > PlayReady > mspr.hds

Don’t forget to restart your browsers!

Hopefully this post will save you time. Once again, credit goes to Chad.

No responses yet

Mo Calc “clone” detected

Jun 22 2011

I was checking up on Mo Calc over at Windows Phone 7 marketplace today and I came across an interesting finance app.

It’s called Loanster. Check out these screenshots below:

Loanster - cheap Mo Calc clone Loanster - cheap Mo Calc clone Loanster - cheap Mo Calc clone Loanster - cheap Mo Calc clone

Despite drawing inspiration from Mo Calc, I am assured that Loanster is a completly legit and independently written app. Its author Tony was nice enough and agreed to tweak the UI in the next version in order to differentiate Loanster from Mo Calc a bit more.

No responses yet

Entered MonoGame logo contest

May 01 2011

The weather was lousy today, so I couldn’t mow the grass. A shame, since I wanted to do something useful. I decided to get artsy while staying inside, so I entered the MonoGame logo contest.

Mono + Game = MonoGame

For the MonoGame logo I wanted to use good visual associations so that the picture adequately describes the nature of the framework. Of course everyone knows the white monkey, which is synonymous with the Mono project. But when I think of the word “game”, a single image comes to me immediately. A single image which brings back a lot of memories from the good ol’ days. The long nights spent playing… Pac-Man! (oh, yeah baby!) This is where I drew my inspiration from.

All versions of the logo feature a slightly rotated Mono monkey with its mouth wide open in the tribute to the well-known arcade character. In front of the monkey are four circles, each one containing a letter from the word “game” (Monospace typeface). The circles are meant to represent the food balls from Pac-Man. Not the small, normal ones. Oh no. These are the “power pellets” which give Pac-Man super powers!

Version 1 – Black and White

I am a fan of minimalism, so the first logo is black and white. It should nicely match the original Mono project logo.

Version 2 – Yellow Pac-Man Monkey

This version of the logo features the yellow color, which brings it closer to the popular arcade games character.

Version 3 – White Monkey, Color Pellets (my favorite)

This version of the logo is meant to express the affiliation of the MonoGame project as well as to underline the cross-platform characteristics of its framework. The Monkey is white to make strong association with the Mono project, while the pellets feature colors which are prominent in logos of popular operating systems:

  • Green – Android
  • Blue – Mac/iOS
  • Red – FreeBSD
  • Gold – Linux (Tux’s beak)
  • All colors – Windows


There are lots of other really awesome contest entries, so please keep your fingers crossed and wish me luck :)

No responses yet

Mo Calc 1.4 released

Jan 09 2011

Version 1.4 of Mo Calc is now available in the Marketplace. It’s just a minor release which improves the scrolling of amortization table. Get it while it’s hot.

No responses yet

Older »