Life of My Raspi

July 5, 2016

3 years ago, I followed the hype, and bought a Raspberry Pi model B, without really using it.
Fast forward to today, I opened my cardboard box and found it again.

Vagrant Settings for VirtualBox Networking

June 20, 2016

Bad things happened, my fiber internet disconnected for several days and I had to use tethering. Unfortunately, my vagrant's virtual box network connection became very slow.

config.vm.provider "virtualbox" do |vb|
   vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
   vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

Adding natdnshostresolver1 and natdnsproxy1 fixed the issue.

Detecting Document Width Early

June 17, 2016

I just had a situation where I need to put ad in different location for mobile view. The placement is hard to solve via CSS appproach.
So I had to do some width detection inside Google Publisher Tag (GPT) slot definition, which is executed early and async.
For some reason $(document).width() is not always evaluated.
It appears that jQuery approach is best used after document ready event, which is not suitable for my purpose.

Fortunately Modernizr's media query function works in my case

var isDesktopView ="screen and (min-width:970px)");

Using SQLite as Data Store In Unreal

May 30, 2016

We are researching for the best way to store dialogue data with Unreal.
The default approach for storing data in Unreal seems to be DataTable, which can be created by importing CSV file. However dialogue seems to be relational data, so we are wondering if the embedded databases like SQLite is a good way for storing data in Unreal.

Compiling SQLite as Static Library

As I was a desktop app developer, the first thing that comes to my mind is SQLite. The common way to include SQLite is by referencing it as static library. As there is no downloadable .lib, you will need to download the source code from

If we compile the source code directly, it will seem to work. However once we try to execute SQLIte function in our project, we get "error C4703: potentially uninitialized local pointer variable used".
Thanks to this SO post, I managed to solve the issue. Basically, we need to add the following lines in sqlite.c

#pragma warning ( disable : 4703 )   

Including SQLite in Unreal Build System

First we will need to include header and .lib file in code directory.
For the time being, we use this directory structure

Root Project
    Third Party

Unreal uses Unreal Build Tools (UBT) for managing the build process.
UBT itself is C# based, and we will need to do build config in C#.
In every module, we will find module rules files, which use ModuleName.Build.cs as file name convention. We need to inform module rule that we will need to load SQLite

public MyProjectName(TargetInfo target)

private string ModulePath
        return ModuleDirectory;

private string ThirdPartyPath
    get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }

public bool LoadSqlite(TargetInfo Target)
    bool isLibrarySupported = false;

    if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
        isLibrarySupported = true;
        string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
        string LibrariesPath = Path.Combine(ThirdPartyPath, "sqlite3", "Libs");
        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "sqlite3-"+PlatformString+".lib"));

    if (isLibrarySupported)
        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "sqlite3", "Includes"));

    return isLibrarySupported;

The above code is based on Unreal wiki, adapted to version 4.12.


One thing to note, is that database file need to be copied into package folder, and not included in PAK file. This can be done via specifying "Additional non-asset directories to copy" in packaging settings.


To be honest, we are still not 100% sure if we want to use SQLite. In our plan, we will just do read operation, so there won't be any lock issue. However SQLite is platform dependent, and we don't know if the code will be 100% compatible if we run it in other environment, like game consoles. For now, we will just refactor, so we can fallback to use DataTable if SQLite is not supported.

It's Time to Leave Boxing, Pacquiao

April 11, 2016

Last Sunday, Manny Pacquiao beat arguably the best welterweight, Timothy Bradley in their third match.
This is kind of fight which I don't like personally, I like both of them but they have fought twice before. Pacquiao has shown he was better in both occasions, though Bradley got the decision in their first fight.

This third fight was still a good fight, both of them are high quality boxer but their second fight was much better, and higher pacing. This time, Pac was slower and more inactive than before, but he is still faster than Timothy Bradley which is a fast boxer himself. Fortunately, Pac's strategy of counter punching was effective. He was able to deck Bradley twice, though the first knockdown was more of flash knockdown.

I always rate Bradley as the best welterweight outside of Mayweather and Pacquiao, and he is a top 10 pound for pound. I just think that Pacquiao's style is bad for Bradley. As good as Pacman is, he can't fight father time. He is slowing down and as someone who has other priority in life (politics), he should leave boxing for good.

There was no one like Pacquiao, an 8 divisions world champ, and it will be really hard to exceed it

My First Few Months With Unreal Programming

March 26, 2016

I am a newbie in game development world. This past few months I have been researching Unreal Engine 4 (UE4) with my friend.
We found that game development is still hard and time consuming but UE4 does help a lot !!!

C++ Programming In UE4 Is Nice

I am not an expert in C++ but doing C++ programming with Unreal is nice.
It uses macro to make C++ becomes more "modern", like marking a class to be reflectable, supporting delegates and events.

Similar to managed languages like C#, Unreal has reflection and garbage collection. So any classes derive from UObject can be garbage collected automatically.

The current Unreal version (4.10.x) needs Visual C++ 2015 so it also supports newer C++ syntax.

Blueprint Is A Good Visual Scripting Language

Blueprint is UE4's own scripting language. It is visual based and supposedly friendly for non-programmer. Obviously Blueprint runs slower, but in some cases like animation, you will need to use Blueprint to manage states.

Blueprint is a very good visual scripting system however, C++ is more friendly for programmers like myself. Doing a simple function can be much longer if we use Blueprint. Fortunately, UE4 has comment mechanism which is useful for grouping list of Blueprint nodes.

As for Blueprint usage, my current approach is try to code all classes in C++ first. If a C++ class needs to be editable in editor, then we will create Blueprint class derives from it.

Documentation is Relatively Good

There are a lot of things to learn in game development with Unreal, so a good documentation is really needed. Coming from .NET background, I find that MSDN is much more complete. There are a lot of class without explanations in UE4 doc, but overall it is acceptable.

Community Is Active

Fortunately even if documentation is not complete, the UE4 community is really active. For most cases, if I'm looking for explanation of API and I can't find it in documentation, I'll just search in Unreal forum.

Special mention should be given to Rama. I found that he created a lot of helpful articles on wiki and answered a lot of UE4 questions as well.
Although he is a contributor to UE4 code, he seems to be an outsider, and he is a spiritual healer as well !!!

Unreal Editor is Slow and Requires A Lot Of Memory

Visual Studio 2015 loads fast but it still requires a lot of memory (more than 700 MB in my case).
Unreal Editor, which is IDE for UE4, loads slower and requires much more memory.

Debugging Is Slow

For editing and designing purpose, you will use Unreal Editor directly.
However for normal debugging session, your code will launch Unreal Editor so it takes more time to test and fix code.
One more thing, testing workflow in UE4 isn't that good. It doesn't support TDD approach, and loading test cases needs to close and reopen Unreal Editor.
I commented on UE4 testing workflow here, but apparently they don't have any roadmap for this testing issue.

So far we believe that choosing UE4 as our engine is a correct move.

Integrating Gravity Form With WP Offload S3

March 20, 2016

Gravity Form is a very useful plugin for form input.
However recently we realized that it didn't handle file upload properly if we use WP Offload S3 plugin. It will still attempt to store file to local file system. This was an issue for us as we use PaaS, and server instances can be swapped anytime.

Luckily Gravity Form provides filter which we can use too hook our own function.

To use it, you just need to include the above file from theme's function.php .

The above code is adapted from Gravitate's post.

Development Environment with Docker

March 19, 2016

It is undenieable that Linux is the most popular server choice, and some software even don't run on Windows officially (Redis, HAProxy, etc).
For this past 2 years, for normal web related purpose, I have been using tools like Docker and Vagrant. Special thanks to my ex-colleague, who introduced me to this approach.

With Vagrant (and Virtual Box), you will run your code inside a headless server environment. Thanks to docker, you can separate your main processes easily, without installing the actual dependencies directly in Linux VM.
The good thing of this approach is you can try different setup (like Nginx or Apache) easier. Normally I just use Docker Compose to specify dependencies in a YAML file.

The best of all, I still code on Windows.