NumGuess in VB.NET and F#

Two more NumGuess versions have been added to the repository. VB.NET was strangely missed so far, should have been added when making the C# version, as it’s mostly identical apart from the syntax. The other one is written in the functional F# language (ok, it’s multi-paradigm). Enjoy the latest additions, and let us know if there is another language that you’d like to see for your favourite number guessing game.

Share Button
Tagged with:
Posted in Blog

Mangler.js documentation

It took a bit of time, but the Mangler.js documentation is finally online. As the project is still in its early stages, it could become outdated quickly and needs regular maintenance, but as of now, it is a complete API reference of all current features.

If you have any questions, post a comment below, or if you found a problem with the docs, create an issue in the GitHub repo.

Share Button
Tagged with:
Posted in Blog

Introducing Mangler.js

Mangler.js is a JavaScript object processing library that helps you transform, restructure, query, index and extract parts of your objects and JSON data. It is open source under GPLv3.

As I often work with bespoke applications where requirements change regularly, it is sometimes impossible to foresee what will need to be added in a month’s time. Due to short deadlines, there is no time to rewrite hundreds of lines of code to re-shape and re-optimise the data, just because a new JSON datasource with unexpected structure has to be integrated. This often leads to one-off conversion functions, which are a pain to write and has no use anywhere else. This library aims to help with these situations.

The project is currently in pre-alpha preview state, keep an eye on the Mangler.js project page for future updates. Documentation is being worked on, new features and breaking changes can be introduced regularly. You can download the most recent version from the Mangler.js GitHub repo.

Data extraction

So far the most useful feature of Mangler.js is the .extract() method, which creates a new slice of your data while attempting to keep object references intact. Suppose you have the following nested object:

var data = {
	mobile_os: [
		{ id: "001", name: "Android" },
		{ id: "002", name: "iOS" }
	],
	desktop_os: [
		{ id: "003", name: "Windows" },
		{ id: "004", name: "Linux", sub_os: [
			{ id: "005", name: "CentOS" },
			{ id: "006", name: "Ubuntu" }
		]}
	]
}

To extract all mobile operating systems into an array, simply include mangler.js in you code and call the .extract() method with a filter:

var os = Mangler(data).extract('mobile_os');

Simply pass the object to the Mangler() function to return a mangler object. Many mangler object methods return a reference to the mangler object itself, so you can conveniently chain methods together. The .extract() method traverses the whole object and extracts items matching the filter. To access the items in a mangler object, read its .items property. In this example, here’s what os.items looks like:

[
	{ id: "001", name: "Android" },
	{ id: "002", name: "iOS" }
]

Filters can be as vague or as specific as you want them to be and can match anything anywhere in the object, not just top-level properties:

var os;

// Extract all name properties from all levels
os = Mangler(data).extract('name');
// os.items are ["Android", "iOS", "Windows", "Linux", "CentOS", "Ubuntu"]

// Extract all mobile OS names
os = Mangler(data).extract('mobile_os[].name');
// os.items are ["Android", "iOS"]

// Extract all linux distro names
os = Mangler(data).extract('desktop_os[1].sub_os[].name');
// os.items are ["CentOS", "Ubuntu"]

Filters also support wildcard characters, use * to substitute zero or more levels of references:

// Extract all desktop OS names, including distros
os = Mangler(data).extract('desktop_os.*.name');
// os.items are ["Windows", "Linux", "CentOS", "Ubuntu"]

You can also use ? anywhere to match partial property names. The filter ?_os collects top-level objects from both the mobile_os and desktop_os arrays, yielding the following:

[
	{ id: "001", name: "Android" },
	{ id: "002", name: "iOS" },
	{ id: "003", name: "Windows" },
	{ id: "004", name: "Linux", sub_os: [
		{ id: "005", name: "CentOS" },
		{ id: "006", name: "Ubuntu" }
	]}
]

The .extract() method supports additional options as the second parameter. By default processing will stop when the filter matches and it won’t go deeper into the objects. In the example above even though sub_os would match the filter, its items are not extracted as desktop_os already matched the filter higher up in the hierarchy. To override this behaviour, use the drilldown option:

os = Mangler(data).extract('?_os', { drilldown: true });

which results in the following items array:

[
	{ id: "001", name: "Android" },
	{ id: "002", name: "iOS" },
	{ id: "003", name: "Windows" },
	{ id: "004", name: "Linux", sub_os: [
		{ id: "005", name: "CentOS" },
		{ id: "006", name: "Ubuntu" }
	]},
	{ id: "005", name: "CentOS" },
	{ id: "006", name: "Ubuntu" }
]

Indexing

I mentioned earlier that Mangler.js tries to preserve your object references. It means while the original data object is untouched, all items in the mangler object are still referencing parts of it. Changing the properties of the extracted objects WILL change the original data.

Let’s say we want to rename Linux to GNU/Linux. Items could in theory be in any order in the data, so we need to find the object we want to change by its id property. The easiest way to do it is to call the .index() method, which returns a JavaScript object keyed on the required property:

// Get a list of items in an object keyed on id
var idx = Mangler(data).extract('?_os').index('id');

// Change name
idx['004'].name = 'GNU/Linux';

Here’s how the resulting idx object looks like:

{
	"001": { id: "001", name: "Android" },
	"002": { id: "002", name: "iOS" },
	"003": { id: "003", name: "Windows" },
	"004": { id: "004", name: "GNU/Linux", sub_os: [
		{ id: "005", name: "CentOS" },
		{ id: "006", name: "Ubuntu" }
	]}
}

Because of the preserved references, you’ll see that the name didn’t just change in the mangler object, but in the original data as well, while the original data’s structure is still intact.

Wait, there’s more…

It was only a sneak peek of some of the already included features, watch out for more updates to come in the near future, as well as more posts covering extra features. I’m still working to put some documentation together, in the meantime you can have a look at the source code in the GitHub repo.

Share Button
Tagged with: , , , ,
Posted in Blog

Android 4.3 developer options missing

Last week Three UK has finally rolled out the Android 4.3 update for Samsung Galaxy S3 phones. It was a massive 450 Mb download, and the update process completed without problems.

It has been reported last year that Samsung postponed the update due to issues reported by customers. Hopefully most have been ironed out since, the only issue I noticed was the occasional split-second audio gap while playing music in the background.

Some apps also received an update, but nothing major. The one I like the least is the update to the calendar widget: I wasn’t a big fan of the light-brown theme it had before to match the organiser app, but now it’s sporting a green and white theme, which doesn’t match the look of anything at all. I’m still looking for a nice looking translucent dark 4×2 widget on the Play Store which nicely handles calendar events and tasks, but found none so far.

Developer Options

Being a developer I also noticed that the developer options are missing from the settings page. That is where you can allow programs from unknown sources, enable USB debugging, and other handy options.

Developer options are hidden on Android 4.3 by default. To enable it, you have to go to Settings / More tab / About device, scroll down to the bottom and tap on the seemingly disabled Build number 7 times. After that, it will sit in the settings menu as usual.

Enabling Android 4.3 developer options

Tap-tap-tap-tap-tap-tap-tap, and you’re set.

Now I just want to go around and randomly tap disabled menu items to see what else can be found.:)

Share Button
Tagged with: ,
Posted in Blog

Outlook 2010 manual send/receive not working

And there I was, thinking that nothing could amuse me today, but Microsoft has delivered splendidly. Normally, I wouldn’t even poke Outlook with a stick, but like many unfortunate souls, I’m forced to use it at work.

Symptoms

For some odd reason, pressing the send/receive button manually had no effect whatsoever. Emails were sent and even received normally on Outlook start and at scheduled intervals, but there was no way to manually fetch them as needed.

The cause

It turned out that the option was accidentally switched off in the send/receive group settings, and Outlook thought it’s not worth mentioning to the user.

The solution below is for Outlook 2010, but as Microsoft is not in a hurry to re-design its user-friendly settings interface (with 250 small unresizable popup windows) since the early 2000s, it might actually be like this for at least another decade.

The solution

On the Send/Receive tab of the ribbon, click on Send/Receive Groups, then select Define Send/Receive Groups to open the popup window to change send/receive settings. Alternatively you can open the same window by clicking on File/Options, then in the Advanced section click on Send/Receive.

Make sure to check the box next to Include this group in send/receive (F9) for the All Accounts group, or if you’re one of those people who created multiple groups, cherry pick them to your heart’s content.

Close the settings window, click on Send/Receive and if all goes well, you email is being checked properly again on demand.

Conclusion

Why send/receive settings are considered “advanced features” in an email client is beyond me, but here’s a protip for UI designers: if you allow the user to completely obliterate the functionality of a big fat button in the middle of your interface, you might want to let the user know why clicking it a hundred times has no effect. A simple message box will suffice, giving the user the option to open the relevant settings page is just a bonus. It’s only a suggestion tough, I’m not one of the brilliant minds in Microsoft’s UX decision making board, who have recently done a brilliant job with the Windows 8 Metro interface.

In the meantime, can anyone enlighten me what exactly does send/receive do, when Outlook is offline? Because that’s an actual option. Or is it just offline from Exchange, but still connected to the internet? Nah, that’s enough crap uncovered for me today.

Share Button
Tagged with: , ,
Posted in Blog

CodeBin goes social

Starting today, you can now reach out and follow your favourite blog on popular social networking sites. Don’t be afraid to like the CodeBin page on Facebook or follow @CodeBinBlog on Twitter if you don’t want to miss a post. For your convenience, handy links can be found on the top and bottom of every page in the header and footer sections respectively.

Sometimes I come across stuff that doesn’t worth writing a full blog post about, but it would be nice to share with like-minded people. And what better place is there for random pieces of information than social feeds?

I was also just curious about social integration and auto-posting, it was interesting to see how many steps are involved in such a simple feature, having to create apps, generate API keys and security tokens. It’s still a bit of a mistery why Twitter needs 4 long random generated strings, but it’s all in place now for your enjoyment. I wonder how long before someone actually comes along, seeing how well the Christmas puzzle played out. :P

Share Button
Tagged with:
Posted in Blog

Pixelated rendering in LibGDX

In this article I’m having a look at rendering 3D geometry and/or sprites in arbitrary low resolutions in LibGDX. I’m taking my previous article with the crate model imported from Blender and change it to render the view into a low-resolution framebuffer then display it on the screen so that it appears pixelated.

Screenshot of the ModelTutorial app with pixelated rendering.

Screenshot of the ModelTutorial app with pixelated rendering.

My previous article on using fixed screen coordinates might have been a bit misleading and according to search keywords some of my readers expected to find something else. As I mentioned in the second paragraph, it only changed the coordinate system and the aspect ratio of the viewport while keeping the rendering area high resolution. The program in this post on the other hand will give you proper pixelated retro rendering.

Rendering into a framebuffer

The method is quite simple, and it’s very easy to change the existing rendering code. Instead of directly rendering to the screen, we need to render the whole scene into a low-resolution texture using a FrameBuffer object, then display that texture stretched over the whole screen with GL_NEAREST texture filter to avoid smoothing and show sharp pixel edges.

Read more ›

Share Button
Tagged with: , , ,
Posted in Blog

Using Blender 3D models in LibGDX

This tutorial will show you how to export a simple 3D model from Blender and use it in the LibGDX Java game development framework. It is in no way a comprehensive guide on any of the subjects covered, but will give you something to get started. At the end we will have a fully working program that shows a very simple textured model. To make sure we won’t spend hours sculpting some advanced high resolution model, I’m creating a cube shaped crate, which coincidentally is the default mesh you get when you create a new file in Blender.

Screenshot of the finished application.

Screenshot of the finished application.

To complete this tutorial, you will need the following programs:

  • Blender 3D modelling program. You only need a standard installation without any additional plugins. In this tutorial, I’m using version 2.69, the latest at the time of writing.
  • Free crate texture from DeviantART, or draw your own. It is a handy 512×512 pixels image, although having a power-of-two texture size is not a requirement for OpenGL ES 2.0.
  • Fbx-conv model converter, get a pre-compiled binary from here.
  • LibGDX framework library
  • Eclipse Java development IDE with the Android SDK installed. You’re quite welcome to use any other IDE, but you’ll need to know how to import an auto-generated LibGDX Eclipse project or to create one from scratch.

Creating your model in Blender

If you know how to create and texture a model in Blender, you can safely skip this section. If you don’t, you probably won’t learn it from here, as this is not a modelling tutorial. In any case, this section is here to provide a nice self-contained example that requires no prior knowledge.

Read more ›

Share Button
Tagged with: , , , ,
Posted in Blog

Running Google’s Dart Editor on Windows

Google released version 1.1 of their Dart programming language just two months after the first stable release. They claim it’s 25% faster than the initial release, but whether this speed increase affects real-world usage or they just optimised the code for speed tests remains to be seen. I’m happy to report that the NumGuess Dart version is still working as intended, although as they’re submitting the language for standardisation I didn’t expect any feature breaking changes in such a simple program.

In the previous release the Eclipse based Dart Editor failed to run on my machine and didn’t have time to fiddle with it. With the release of the new version I was hoping that they fixed the problem, but sadly it had exactly the same issue. When I tried to run DartEditor.exe I received the following error message:

Could not create the Java virtual machine.

Then after pressing OK in the dialog box, some more useless details followed:

Java was started but returned exit code=1
C:\Windows\system32\javaw.exe
-d64
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=128m
-Xms256m
-Xmx2000m
-jar D:\Utils\dart\plugins\org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
-os win32
-ws win32
-arch x86_64
-showsplash
-launcher D:\Utils\dart\DartEditor.exe
-name DartEditor
--launcher.library
D:\Utils\dart\plugins\org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-144807\eclipse_1503.dll
-startup
D:\Utils\dart\plugins\org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.overrideVmargs
-exitdata 146c_5c
-data @user.home\DartEditor
-vm C:\Windows\system32\javaw.exe
-vmargs
-d64
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=128m
-Xms256m
-Xmx2000m
-jar D:\Utils\dart\plugins\org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar

Fixing the .ini file

I have a few different Java/JRE/JDK versions installed on my machine, it seems that by default it was trying to use the wrong one. To fix the problem, point to the right JDK installation by adding the following two lines to DartEditor.ini, right before the -vmargs line:

-vm
C:/Program Files/java/jdk1.6.0_21/jre/bin/server/jvm.dll

Your path might be different if you’re using a different version, installed it in a different folder, or using 32-bit JDK on 64-bit Windows. Another solution that worked is to simply remove the -vmargs line itself.

Once you’ve done either of these changes, Dart Editor should open properly by running the .exe file.

Share Button
Tagged with: ,
Posted in Blog

NumGuess Falcon and PowerShell

I am pleased to announce a couple of more NumGuess implementations, this time in the Falcon programming language and a script for the Windows PowerShell. These new additions to the NumGuess family raise the total number of programs to 31.

Falcon is an open-source multi-paradigm language; be it procedural, functional or object oriented programming you’re looking for, it surely has something for you. Programs get compiled for and run in a virtual machine enviroment, which can either be used as a stand-alone interpreter or can be embedded into your applications to use Falcon as a powerful scripting language. If you’re looking for an elegant implementation of a number guessing game, this is not it, I wrote this program to be as simple and as concise as possible. If you want to read more about the language, have a look at the Falcon website, or if you feel you can contribute to the project, head over to its GitHub repo.

The Windows PowerShell script is nothing special, although it’s one of the shortest programs in the collection due to the fact that it automatically outputs every line that evaluates to a string.

Enjoy the latest additions and let me know in the comments what else you’d like to see.

Share Button
Tagged with: ,
Posted in Blog

If you find something useful, please feel free to buy me a cup of coffee.