A cheaper Freewrite: some linuxnoob tips

Not having the funds to buy myself a Freewrite (formerly known as HemingWrite) I blew the dust from an old, but still working netbook (Samsung N150) and followed this great tutorial “How to turn your laptop into a typewriter“.

Here’s some handy tips if you want to redo the tutorial yourself

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.

First:

sudo systemctl edit getty@tty1

Then add the following content:


[Service]

ExecStart=

ExecStart=-/sbin/agetty --autologin yourusername --noclear %I 38400 linux

Type=idle

Save and exit.

Next, you will want to change the bootloader, grub, settings:

sudo nano /etc/default/grub

and change the GRUB_CMDLINE_LINUX_DEFAULT value to text.

Next up, write the changes to grub:

sudo update-grub

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

Use upower as explained here.

Twoway databinding to a MongoDB collection in WPF

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.

Setup

I have a Listview defined in XAML with a datatemplate:

        <ListBox Name="mylistbox">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Naam, Mode=TwoWay}"></TextBox>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

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:

            foreach (var item in mylistbox.ItemsSource)
            {
                coll.Save(item);
            }

A C# Portable Class Library to talk with Smappee API

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

Smappee-with-Hand

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.

 Where is the goddamn code?

The actual code for the PCL is hosted here: https://github.com/timdams/Smappee_API_CS

Two projects are added:

  1. SmappeePrototype: A simple console-app that shows how to use the lib
  2. SmappeeAPITD: the actual PCL. I use JSON.NET for the parsing, which is the only external dependency.

To use the code, make sure you have all the credentials at hand, you can then start querying the API once you build the PCL and added it to your project:

            SmappeeAPI dll = new SmappeeAPI("yourClient_id",
               "yourClient_secret", "yourmysmappee_username","yourmysmappee_password");

            await dll.RetrieveAccessToken();

            var serv = await dll.GetServiceLocations();
            //Ask consumption of last week of first smappeedevice retrieved from ServiceLocations
            var resk =
                await
                    dll.GetConsumption(serv.serviceLocations[0].serviceLocationId,
                        DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)),
                        DateTime.Now, SmappeeAPITD.Aggregation.Hourly);

 

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. )
  • No logic is added to refresh the token once it’s expired.

My year in review: a not so good year…or just bad.

2014 was a very, very meagre year on my part concerning blogging. Did I fall asleep this year? Far from it. A lot has been going on, I just didn’t create a lot of content interesting enough to be posted here. Will it be better this year? Can’t make any promises, but it will be very hard to do worse than 2014: 2 small posts at the start of the year, and that’s that. Shame on me! At least I prepared myself for the new year: I basically deleted my Facebook account (only still alive to follow our neighbourhood group and to use as universal login), removed a lot of distracting stuff from my pc and I’m even considering putting some constraints on my Steam( damn you CS:GO) and Origin (damn you Titan) accounts. My giganto-normous pile of books on my desk is also being trimmed down…one can only read so many stuff in parallel.

Off to a new year. To keep in the spirit of 2014 however I won’t make any brash, numerical promises on what I will do the next year…Happy new year everyone!

Read on if you want a summary of my blog this year

Read more of this post

What’s on my Windows Phone – my favourite apps

I’m often get asked what apps I have installed on my phone. After explaining I have a Windows Phone 8 (Lumia 720) the question usually results in an awkward “erm..okay, nevermind”. But sometimes a fellow Microsoft enthousiast can be found. It is for these people that I have compiled a list of the apps I have on my ‘start menu’ (e.g. use-a-lot-apps) and those installed (e.g. handy-apps) So without further ado: Read more of this post

Book review: Windows Phone 8 Game Development

6807OT“Sir, I want to be a game developer, what do I do?” is a question I got asked a lot during classes. The honest answer I usually give is :”work hard, keep trying and never stop trying”. I’ll keep on answering this, but I might also recommend a new book that has recently arrived titled “Windows Phone 8 Game Development – A practical guide to creating games for the Windows Phone 8 platform” by Marcin Jamro (Packt Publishing).
Remember the big bad-ass books by Andre Lamothe on (3D) Game programming, where many aspects of game programming were discussed? This new book has the same approach: more is better, plain simple.

A first glance at the index will immediately show the author is trying to describe all aspects of game development, not only the game (engine) coding itself, including social interaction, webservices, publishing, etc. What especially triggered my attention was chapter 3 titled “Mvvm design pattern”, a pretty ballsy approach because up until now I haven’t seen a single book on game development where this pattern is even just briefly mentioned.
Throughout the hefty 394 pages, the author will show how to (re)create a full-blown 3D space , asteroid-like shooter from the ground up. This is both good and bad news: bad because it means most chapters will depend on code of the previous ones, good because it shows how interdependent a lot of aspects are when developing a game. Many books who use this approach (i.e. build an application from start to end) sometimes fails because a) some important code-parts are missing or b) the code is to complex: the reader misses the keypoints the code wants to convey and thus loses time trying to get the code to work AND understand.
I haven’t made the game itself so I can’t vouch for the fact that a workable game can be made following this text but the code itself in the text is well-documented and clear.
A nice addition is the fact that a hybrid approach is used: managed code to harbour the menu/UI-related stuff, and a native part for the game itself. The game itself is written using DirectX, whereas the main game menus are in plain XAML (hence the MVVM approach mentioned earlier).

The text itself is very detailed, every step is explained, but sometimes a bit redundant: the author even explains how to place controls from the toolbox in your designer and how to debug using locals, autos, etc. A tad overkill? On the other hand, this makes the book ideal for anyone new to c#/xaml programming. So it could actually be used as an fun, introductionary book for experienced non-C#-developers who never used Visual Studio.

And yes, a lot is tackled: even augmented reality (AR) is in it: GPS coordinates of other players nearby are used to show their actual location when watching through the camera of the phone.
So in overall: if you need a primer on 3D/3D game programming for Windows Phone 8, this book is a must-have!

Oldschool CMD: deleting all files of a type with exceptions

Just some oldschool trickery: using the command prompt in windows (even works in dos!🙂 ) it’s very easy to delete all the files of a certain type except those having a specifc name I wan’t to keep. Imagine I need to recursively delete all the jpg files in a folder and subfolders, except those named “folder.jpg”. The following command does this:

del /s dir *.jpg  /s | find /i /v "folder.jpg"

Why I put this on my blog? Because I might need it for future reference😀