Cross-platform Games
So you want to create a cross-platform game that works on all the major operating systems and mobile as well? Here are some of your options:
2D Canvas
2D Canvas has broad support both for desktop and mobile. It has it’s limitations though, the biggest one being that you are bound to the CPU as most implementations can’t harness the power of the GPU. You might also need to use a library (or two) to get the input and sound working cross-platform. If you are trying to create a very simple game this might be a good option for you.
WebGL
WebGL solves the biggest issue with 2D Canvas - it gives you direct access to the graphics card (via the OpenGL ES 2.0 API), but it does so with a cost. It looses the cross-platform compatibility of 2D Canvas. Not even all the browsers on the desktop support the API (I am mostly looking at you IE). Android does have some support for WebGL (in Chrome beta via a special flag and in the webkit browser as well), while iOS seems to have support but is currently disabled. There is even an enabler app that you can buy, but I have no idea if it actually works. Hopefully support will improve in time and WebGL will become a viable option for developing cross platform games.
LycheeJS
LeechyJS is a library written in Javascript. It also provides a cool tool called Lychee-ADK, which allows cross-compiling apps to different platforms. It’s using the V8 JIT runtime with OpenGL, GLU and GLUT integration. It’s still under heavy development, but it promises to have support for Windows, Windows Metro, Linux, Android 2.3, Android 4.x, iOS 5.0+ and even Mac OSX once finished. In the meantime feel free to contribute to the project on github!
libgdx
LibGDX is a game framework written in Java. It allows you to write your game from the comfort of your desktop and it even has code hot swapping support. Supported platforms are: Windows, Linux, Mac OS X, Android (1.5+), iOS (requires a MonoTouch license, 79$ for students, 399$ otherwise), Javascript/WebGL (GWT).
MonoGame
Monogame is an opensource implementation of the XNA Framework. It’s goal is to allow developers to port their games to all the major operating systems including Linux, iOS and Android. Only 2D games are supported on iOS and Android at the moment though and you need a xamarin license if you want to sell your games.
Unity
Unity is a development environment, which currently works on Windows and Mac OSX, but it allows you to export your games to Linux as well. It also supports iOS and Andoroid, but it comes with a cost ($400 or $1500 for the pro license). It also has a web viewer but it doesn’t work on Linux yet.
C++
From what I can tell all the main mobile OSes support C++ in some way or another. Android has it’s NDK, ObjectiveC on iOS can also import C++ files and Microsoft added C++ support in Windows Phone 8. The only problem is that I failed to find a framework/library that would make it easier to write cross-platform games in C++.
Fin
Have I missed anything? Let me know in the comments!
Google Analytics should use log scale
Google Analytics is an awesome tool. I have the utmost respect for the googlers working on it every day.
There is a problem though. The graphs look okay if you have regular traffic throughout the month, but if you are a blogger that probably won’t be the case. You will most likely have little to no traffic between blogs and then a huge surge of traffic when you write a new post. Especially if the social web gets a hold of it.
This is exactly what happend to me with my The Chrome Javascript editor can do hot swapping blog post, and this is the resulting graph:
As you can see, pretty much the only thing visible on this graph is the huge spike on the day I published the blog. Traffic on all the other days seems to be zero, with a small exception round 21 Jan when I published another blog. There is no way for me to tell how much traffic the other blog has gotten - somewhere below 2k would be my best guess from glancig at the graph.
The solution to this problem is amazingly simple. You use a logarithmic scale for the vertical axis:
Now I can see everything - even the drop from 20 page views per day to 10. I can now tell exactly how much traffic the second blog post has gotten and the huge 12k spike still seems huge.
The funny thing is that all the chart/graph libraries have the option to use log scale - d3, pylab and even google charts all have it built in. It’s weird that Google Analytics doesn’t provide the option.
Am I the only one who prefers the second graph? Let me know what you think!
The Chrome Javascript editor can do hot swapping
Hot swapping is the process of replacing code while the application is running. It allows a developer to see changes immediately - no recompiling, no waiting on page reloads, and no clicking to get to the application state where the code was changed. Just save the file and you’ll see the changes.
I would say hot swapping is a must for making applications with an always active update loop (games) and this guy would probably agree.
The Chrome editor
As you can see from the picture above, the Chrome editor has everything you need.
There is a built in tree list view of all scripts used by the application. The editor supports tabs which are remembered when you close the browser window. You have access to the debugger and all the tools that come with it and the all powerful console is right where you need it.
You can even have the editor side by side with the web page:
Most importantly it supports hot swapping out of the box. When you press control+s Chrome will start using the updated file immediately. The need for refreshing the page will greatly decrease.
Saving files locally
By default changes made will be lost when you refresh the page. But with right clicking the source file you can choose the Save As... option. Now just point the dialogue box to your local version of the site and now all the changes you make will get written to you hard drive. Awesome!
The only problem is that you will need to go through the Save As... step for every file in your application. It would be nice to just specify your localhost directory and then let Chrome figure out what goes where. Maybe in the next update?
Not just Javascript
All of the awesome things I mentioned work for editing css files as well. Designers rejoice!
Now we just need a better interface for saving files locally, an easy way of running unit tests, a vim mode and we will have the perfect editor!
Useful GNU/Linux tools
GNU/Linux is awesome because it gives you a whole lot of simple but useful tools that you can play with. Utilities like dd, sed, grep, rm, find, ssh and many others all have a small sea of parameters that make them do exactly what you want.
Unfortunately I am very bad at remembering different parameter names and whether or not they should be written in lowercase or uppercase. Thankfully it is very easy to create aliases or even your very own executables. Following is a brief description of some utilities I have made to make my life a bit easier. I’ve put them all in a github repository so feel free to fork and/or send pull requests with suggestions!
grepr
export GREP_OPTIONS='--color=auto'
grep -rnC ${2:-3} "$1" *
It’s a simple grep wrapper that forces the grep utility to become recursive by default. The first parameter to grepr is the phrase you’re searching for, while the optional second parameter specifies the number of lines above and below the search term to be shown.
rmr
find . -name $1 | xargs rm
rmr is similar to grepr. It makes the rm utility recursive. It’s useful when you have a bunch of files that end up with .orig in multiple subfolders. You would just write rmr *.orig to delete them all.
sedre
sed -i "s/$1/$2/g" $3
Sedre replaces all of the occurances of the first paramtere with the second parameter in the file specified by the third parameter.
seddl
sed -i "$1d" $2
Seddl removes a line from a file. You would write sed 4 myfile to remove the fourth line from myfile.
screenshots
while true; do scrot "%Y-%m-%d_%H-%M_$2.png" & sleep $1; done
Screenshots is a utility I intend to use when I’ll be doing my next game jam. It’s basically an endless loop that makes screenshots. The first parameter is the number of seconds between screenshots, while the second parameter is a name for the generated pics.
Game Jams: The most fun you can have while programming
Programming is a lot of fun. It’s an awesome feeling when your code compiles without errors, the app passes all the tests, and runs without any (noticeable) bugs. It’s an awesome feeling even if you are working on a boring enterprise app. You made the primitive machine under your keyboard do something. If that isn’t amazing I don’t know what is.
Now take the satisfaction you get when you produce working code and multiply it by 100. This is how awesome it feels when you are making a game.
Making a game
Making games is fun. I would argue it’s even more fun than playing them. It might have something to do with the fact that games are made to be fun. Business apps are not made to be fun. They are made to be useful (or not, if you’re oracle). If you are making a business app to be fun, chances are you are making a game (in which case, good for you! We need more useful game type apps.).
The problem is that making games is hard. Really really hard. If you try to think about how much time and money it takes to do a good AAA game, your brain will start to hurt.
But you don’t have to sell your soul to a big publisher just to make a game. You can be an indie developer! This usually means that you will be doing all the hard work yourself, and you probably won’t get payed. Of course this option is not for everyone.
The 3rd option
But thankfully we have a 3rd option. Game Jams!
Game jam is a gathering of developers, artists, and other creatives over a short time during which a collective effort is made to make one or more games.
The key point in this definition from wikipedia is a short time. You don’t have to invest a ton of time and money to do a game jam. You can even keep your day job! All you need is to grab your laptop, go to a friends place, and do some coding. After a day or two you should have a game. It’s not going to be the best game ever, but it’s going to have a player, a goal and maybe even some levels. Even though it’s probably going to be buggy and unfinished you will be able to play it. And it will make you proud.
Our Indie Speed Run
A few of my friends and I did the Indie Speed Run a week before new year’s (you can actually play our game here). We were coding almost nonstop for 48 hours and we had fun all the way to the last second. At one point I couldn’t stop laughing. I was doing the jump animation for the icecube and I messed up a value by a factor of 100. It made the cube taller than the height of the level for a few seconds and then small again. It was hilarious.
I don’t even care if we win a prize (we probably won’t, our game sucks, haha), we had fun and we learned a lot of cool new things (webgl with three.js!).
Go do it!
If you are a programmer, try doing a game jam at least once in your career. You just missed the Indie Speed Run, but there are countless more to choose from. Hint: Global Game Jam is coming up later this month! Join the fun.
Worst python code I've ever written
I was doing my homework for the bioinformatics class when I started experimenting with scope in Python. The first thing I noticed was that Python list comprehensions don’t create a closure. This means that variables defined in the list comprehension bleed out into the current scope:
>>> [i for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> i
9
>>>
I’ve combined this with the fact that functions have access to variables from the same scope, and come up with this example:
def dpt(s,t):
def cost():
gap = -5
M[i,j] = max(
M[i-1,j]+gap,
M[i,j-1]+gap,
M[i-1,j-1] + blosum(si, tj)
)
M = defaultdict(int)
[cost() for i,si in enumerate(s) for j,tj in enumerate(t)]
return M[len(s)-1, len(t)-1]
At first glance it doesn’t seem like there is something horrbly wrong. But when you try to figure out what the dpt function actually does, you immediatly find something peculiar. There is function call in the list comprehension that takes no arguments. So why am I defining all those variables (i, si, j and tj) which aren’t being used? I don’t even need the enumerate calls, right? Wrong! All those variables are being put to good use inside the cost() function! Yes, the cost function has access to all those variables and hence doesn’t need any paramters at all.
When I showed this peace of code to my friends they all thought I was insane. We ended up agreing that code should not be written like this as it makes your program very difficult to understand.
Just for kicks I included these two lines in the homework report as well:
# Two horrible lines that turn the above string into a dict. I am sorry.
arr = [j.split(' ') for j in [i.strip().replace(' ', ' ') for i in b50]]
return reduce(lambda a,b: dict(a.items() + b.items()), [{(arr[0][j],arr[i][0]): int(arr[i][j]) for j in xrange(1, len(arr[i]))} for i in xrange(1,len(arr))])
I am a horrible person.
By the way, the homework assignment was to compare COX3 mitochondrial gene between multiple species and build an evolutionary tree. Here is the resulting dendrogram with avrage linkage:
I’ll probably post the full source code once all the assignments get graded.
My Github Game Off Submission
I’ve started working on a simple webgl game, and after just 4 days of development it’s already sort of playable. You can go ahead and try it out right now.
Here is a screenshot:
There is still a lot on my TODO list though
The game is playable but it is far from finished. There are some bugs and graphical glitches here and there and the block generator isn’t perfect yet. After a while, as the blocks start to speed up, the amount of them on screen decreases, which is quite the opposite of what I want. I didn’t want to waste too much time fine tuning it just yet, because I will be adding some more powerups that are going to affect the flow.
I’ll need to add a couple of screens as well, to explain the controls (by the way, you move with left, right and restart with space) and to make it a bit more apparent when you die. Adding high scores is on the TODO as well.
Once all of this is done, I’ll try to include as much fun stuff as possible, maybe even a secret cow level!
Working with webgl
I’ve done some webgl work in the past (a school project, be warned it’s horrible. It’s a steep learning curve in the beginning, but once you get accustomed to vertex/fragment shaders it gets easier and, I dare say, fun! The only thing I really missed is the lack of hot swapping support. I’ve tried a few chrome extension, but none of them worked well enough. The most promising was tincr but it didn’t work reliably enough to actually be useful.
Suggestions?
This is actually my first game, so any tips and suggestions will be greatly appreciated!
PS
I hope the good guys and gals at github won’t mind me borrowing their graphical assets. I’ve tried creating my own textures, but they all look horrible. I am totally useless when it comes down to drawing stuff.
Nginx and VirtualBox shared folders
I found something really peculiar. If you are trying to serve static files with Nginx from a Virtualbox Shared folder, you are going to have a bad time. I agree, you shouldn’t be doing this in the first place, but this issue is so weird I really had to write a blog post about it.
Let me explain
I have a folder with static files on my local machine (Ubuntu) and I have a Debian virtual machine running nginx. I have added a shared folder that allows the Debian server to access files on my local machine. Here is the /etc/fstab file that mounts the shared folder on the server:
shared /home/smotko/shared vboxsf fmode=770,dmode=770,uid=smotko,gid=www-data 0 0
And this is in my Nginx config:
location /static/ {
alias /home/smotko/shared/static/;
}
Now if I try to load the site.css file from http://site/static/site.css. Everything works as expected, but if I make a small change to the file from my local machine, I get this:
It’s a bit of the old file and some weird characters. Restarting nginx doesn’t help, setting flags such as expires sendfile and autoindex doesn’t do anything. If I mv site.css to site2.css it displays the changes, but if I then mv it back to site.css I get the old file and the weird characters again. touching the file doesn’t help, but if I open it up in vim and just do a :wq nginx starts serving the updated version of the file.
Why is this happening?
I don’t really care about the solution, I will never be serving static files from a shared folder. But I would like to know why this is happening. From what I can tell, the file edited on my local machine is identical in every way to the file edited on the server and yet Nginx does not agree. Is this a bug in nginx? Is this a bug in vboxfs? Am I doing something wrong? What is going on here?
Update:
Thanks to a comment on reddit I have solved the issue. I needed to set the sendfile off flag in the nginx config.
Why don't we have code hot swapping on mobile?
Code hot swapping is one of the most useful features a language can offer. It allows the developer to see changes as soon as he saves the source code. No restarting needed, your changes just pop up on the screen and your application state is preserved. Hot swapping magically updates method runtimes and gives you immediate feedback. This is invaluable and double so for developing graphical applications such as games. You don’t believe me, checkout this talk.
A quick example
In Java hot swapping is supported out of the box. You fire up eclipse, write a simple application like this:
public class HotSwap {
public static void main(String[] args) throws InterruptedException {
while(true){
swap();
Thread.sleep(2000L);
}
}
public static void swap(){
System.out.println(":(");
}
}
and press F11 or select run/debug from the menu. Your application will start printing out a sad face, but you can easily turn that frown upside down, save the file and output will become a smiley face. Amazing right? Now imagine having this much power while developing a game. You can start playing with colors, sizes of objects or even gravity in a platform game. It also works if you’re doing an OpenGL application. You will occasionally run into a Hot Code Replace Failed dialog and will have to restart your application, but this doesn’t happen very often.
Moving on to mobile
So now that you are blown away by the awesomeness that is hot swapping, you’ll want to use it in your next project. Lets say you are writing a game for Android. You fire up Eclipse again, create a new Android project, do some setting up and start the application the same way you did in the first example. When you try to do a hot swap a dialog will pop up, telling you that this isn’t possible.
The problem is that your application gets compiled, packaged, signed and sent to your mobile device where it gets installed. Most of these steps happen every time you launch the application. This set of steps apparently can’t be circumvented and thus making code swapping impossible.
Not just Android?
From what I can tell (and please correct me if I am wrong) Android Java isn’t the only one with this limitation. It’s the same sad story with Objective-C on iOS and Windows phone things. Is this really such a hard nut that none of the best and biggest tech companies can crack? This is not a rhetorical question, I am genuinely interested why no one has done this. From the way I see it, this would save lots of developer time. Time that is currently being wasted by slow application restarts.
Solutions?
My current solution is to develop my game using Java with OpenGL ES 2.0 on my desktop and then port it to Android. Most of the code can be shared but this is far from an ideal solution. I still believe hot swapping is well worth the extra work.
Best Github shortcut ever
Today I watched this awesome talk and it blew my mind. I never knew how many secret features github actually has. The talk is rather long, so let me just highlight the best shortcuts mentioned.
My favorite one by far is the t shortcut. Go to a github repo, press t and start typing a file name. It will list all the files that match your query. You can even use the arrow keys to select a file. Is this awesome or what?
You can also put .diff or .patch to any url that contains a diff and it will generate a plain text diff, or you can add ?w=1 to ignore whitespaces changes. l allows you to jump to a specific line while w helps you switch between a branch or a tag.
These are many other shortcuts and you can list them all by pressing ?.
I tried moving to Debian
Yesterday I decided it was time to say goodbye to Ubuntu 12.04 and move to Debian Wheezy. This wasn’t due to the controversial changes Ubuntu made this release cycle, I don’t mind uninstalling a lens I find annoying. I couldn’t upgrade to 12.10 because the legacy fglrx drivers no longer work with kernel 3.5. I still wanted to try out something new though, hence Wheezy.
The installation went without a problem, but when I rebooted I got this:
I couldn’t even get to the root shell. Booting in recovery mode didn’t help as well. I even tried reinstalling the system without a graphical user interface, but the end result was the same. Seems like something was seriously wrong with the drivers, but because I couldn’t reach the shell I didn’t know what to do.
Back to Ubuntu
After a few hours I gave in and decided to reinstall Ubuntu 12.04. Everything went well until I installed all the updates and restarted the system. Instead of Ubuntu booting back up I got this lovely little message:
This was not a good day for Linux. Luckily the solution for this problem was easy - reinstall grub from a live CD. Now I seem to have a working system.
Learning Haskell, wrote startsWith a bunch of times
So I started learning Haskell a day or so ago. I dived right into http://learnyouahaskell.com and read through the first few chapters. As soon as I learned how to write an if statement and got familiar with some basic list functions (head, tail and such) I started experimenting with my own code. I don’t know why, but I decided to implement a simple startsWith function, here is the first version:
startsWith' l s =
if null s then
True
else
if null l then
False
else
if head l == head s then
startsWith' (tail l) (tail s)
else
False
Now I know what you are thinking. This looks horrible and I know I shouldn’t write code that looks like this. I agree completely, but at the time of writing I only knew really basic Haskell syntax. After reading another chapter I quickly improved my code:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' l s =
if head l == head s then
startsWith' (tail l) (tail s)
else
False
Writing code like this is familiar to me as I have done some Prolog programming for a class. It seems ‘academic’ programming languages tend to borrow each others ideas almost as much as other languages do! I was also delighted to see that, similarly to Prolog, Haskell provides a shortcut for retrieving the head and the tail of the list:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (hl:tl) (hs:ts) =
if hl == hs then
startsWith' tl ts
else
False
But unfortunately this is where similarities between these two languages end. If this was Prolog I could get rid of the last if statement like this:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (h:tl) (h:ts) = startsWith' tl ts
startsWith' _ _ = False
Notice that the h variable has been ‘defined’ twice. Prolog magically understands this as the head of the first list needs to be the same as the head of the second list. Awesome, right? Thankfully Haskell didn’t leave me hanging. It has something called ‘guards’ and with their help I got rid of the last if statement:
startsWith' _ [] = True
startsWith' [] _ = False
startsWith' (hl:tl) (hs:ts)
| hl == hs = startsWith' tl ts
| otherwise = False
I would not be embarrassed to introduce this last code snippet to my mother. It’s a great improvement over the hideous first version. I have not yet reached the end of the tutorial and there are probably ways of improving it even further. Any ideas?
I like Haskell so far. The reason I started learning it in the first place was because I wanted to improve my coding in general. Learning a purely functional language seemed like a good idea as it teaches you all about side effects and makes your brain think differently. This something an engineers brain should know how to do…
Disqus redesigned
A couple of days ago I noticed Disqus started experimenting with a new design. Because I am always eager to try out new things I requested an invite immediatly. One day later I received an email informing me I can activate the new design on my sites.
Lo and behold
The “Disqus 2012”, as they are calling the new design, is now enabled for this site and you can try it out right now (just scroll to the bottom of this page). The most prominent change from my point of view is the community tab. It allows you to see which the top discussions and commenters are on the blog. Useful bits of information to get the feel for the community. For instance, if you check out the community on this blog, you will learn that it is a sad thing indeed.
They also seem to be grasping the social aspect much more fiercely than before. Clicking on a commentor now shows you a bunch of his last posts and some basic information. You can even follow people whose comments you like. I don’t remember if this was in the old design as well, but I haven’t noticed it until now, so I guess they did something right! I might even give this feature a try.
But what about commenting?
The community tab and the added social aspects are great, but what did they do to improve the whole commenting process? Well from what I can tell, not a single thing! And I believe this is a good thing. Writing comments worked well, and it would make little sense to change it. They did seem to add upvotes and downvotes instead of a “like” button, but I have no idea how this little change might impact larger communities.
All in all I like the facelift, but will it convince more people to share their comments? Lets wait and see.
Navbar in Django Admin
I wanted to add navigation to the Django top bar. The idea was that all of the installed apps should show up in the navbar beside the brand name. This is a screenshot of the working solution in action:
A solution
I hacked together a solution using a custom context processor in order to feed the installed applications to every template in the django admin site. I borrowed most of the code from the admin index view. context_processors.py:
from django.utils.text import capfirst
from django.db.models import get_models
from django.utils.safestring import mark_safe
from django.contrib.admin import ModelAdmin
from django.contrib.admin.validation import validate
# get_models returns all the models, but there are
# some which we would like to ignore
IGNORE_MODELS = (
"sites",
"sessions",
"admin",
"contenttypes",
)
def app_list(request):
'''
Get all models and add them to the context apps variable.
'''
user = request.user
app_dict = {}
admin_class = ModelAdmin
for model in get_models():
validate(admin_class, model)
model_admin = admin_class(model, None)
app_label = model._meta.app_label
if app_label in IGNORE_MODELS:
continue
has_module_perms = user.has_module_perms(app_label)
if has_module_perms:
perms = model_admin.get_model_perms(request)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if True in perms.values():
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())),
}
if app_label in app_dict:
app_dict[app_label]['models'].append(model_dict)
else:
app_dict[app_label] = {
'name': app_label.title(),
'app_url': app_label + '/',
'has_module_perms': has_module_perms,
'models': [model_dict],
}
app_list = app_dict.values()
app_list.sort(key=lambda x: x['name'])
for app in app_list:
app['models'].sort(key=lambda x: x['name'])
return {'apps': app_list}
We add the custom context processor to the settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"context_processors.app_list"
)
With the context processor in place we should have an ‘apps’ variable available in our admin templates. The only thing left to do is to add the code that renders the installed applications. I am using twitter bootstrap for the navbar. Here is my templates/admin/base.html:
<ul class="nav">
{ % for app in apps % }
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{ % trans app.name % }<b class="caret"></b>
</a>
<ul class="dropdown-menu">
{ % for model in app.models % }
<li><a href="/{ { model.admin_url } }">{ { model.name } }</a></li>
{ % endfor % }
</ul>
</li>
{ % endfor % }
</ul>
Note: I had to add spaces to the { % and { { tags as jekyll/markdown doesn’t seem to be able to handle them in code segments.
This is pretty much it. Suggestions for improvements are welcome!
Gnome Shell and Unity
Ubuntu 12.04 LTS is just a few weeks away and it is going to bring a new version of the Unity desktop. The recently released Gnome Shell 3.4 will also be only one apt-get install command away. I am therefore left with a tough decision: which desktop shell should I primarily use when the new Ubuntu lands.
Unity
Unity has really come a long way since it’s first release back in 11.04. I have already blogged about the most exciting new features a month back. My main issue in the old blog was multi monitor support. The launcher in the middle had a sticky behavior making the mouse stick when transitioning from screen to screen. The sticky behavior is now an option and one can even set which monitor will be used for displaying the launcher! They even made it easy to customize the launcher itself. The appearance dialog now lets you set the launcher background, icon size and such. We finally have some accessible options to customize the look and feel of the Unity desktop, this was one of the chief complaints with Unity in 11.04 and I hope we will get even more options in future releases.
Gnome Shell
Similarly to Unity, there was a lot of hate going round the interntes about Gnome Shell. Gnome Shell introduced a new way of doing things. It removed the bottom bar and changed the way people switch between applications. I understand that the workflow can be confusing at first but after a few hours it gets super smooth. I love it. So much so that I even wrote a Gnome Shell extension to make it even faster and easier to use.
The latest 3.4 version brings many changes. Most importantly for me, the stability on AMD propriety drivers has gone way up and I am no longer getting segfaults every 10 minutes or so. Maximized windows now hide the titlebar (sort of like Ubuntu does) to save precious screen estate, and the application menus are now exposed through a special menu.
The verdict
This really is a tough call. Both of the new desktops seem really awesome to me, and I will probably have them both installed on my new system. But for me the breaking point in favor of Unity is HUD. If it turns out to be as useful as I hope it will be, I might find myself using Unity more often than Gnome Shell.
How about you? Gnome Shell, Unity or something else?
My plans for Raspberry Pi
A week or so ago, I was able to preorder a little piece of hardware named Raspberry Pi. On the day the thing got released I and quite a few other people, managed to take down websites from Farnell and RS Components. The first 10.000 units sold out in 7 minutes or so.
What is it
Unless you have been living under a rock, you probably already know what a Raspberry Pi is. It’s a tiny computer with an ARM processor, hdmi, audio, ethernet and 2 usb ports. It is somewhat comparable by performance to an iPhone, but a Raspberry Pi costs less than a HDMI connector for the said phone. It was made to help children across the world to learn programming, but the first few batches will probably be all bought up by geeks like me.
Why do I want one
I already own a similar device - an ARMv5 board with a 196MHz processor and some RAM. I use it to run an annoying IRC bot, that logs our chats and tells us when a link is a repost (some of it’s code is on Github, but it’s not the prettiest thing I’ve writen). This little ARM board is great, but I have ran into a few problems with it. I haven’t managed to get git working, as all of my crosscompiling attempts have failed and compiling on the actual board takes forever before it throws up a random error. To be fair, I had this problem with everything that isn’t in the default buildroot environment, which only contains a handful of applications I would like to use.
Raspberry Pi is, on the other hand, backed up by actual Linux distributions (Arch, Debian and Fedora) and I am very confident, that installing software will not be such a pain. This will of course make the Pi useful for many things. Here are a few that come to mind:
- Host for private git repositories,
- simple webserver for testing out things like nodejs,
- SSH “entrance” for my home network,
- my IRC chat bot.
The Raspberry Pi is ideal for this as it has a processor that can tackle all of these things and is completely silent, as it doesn’t need a fan. To top off, it uses only a small amount of energy.
And much more
The stuff I mentioned so far is just the geeky stuff that I will be doing as soon as I get my new board. There are many uses for it for less techy users as well. It can be used as a movie player (it even plays full hd videos), and it can probably transform ones USB hard drive into a network disk. As it can run a desktop environment it could even be used for some simple office work or web browsing.
What about you
Do you have any ideas? What are you going to do with your Raspberry 3.14?
Coding and keyboard layouts
Keyboard layouts are important, especially for us programmers, as we spend most of the day cranking out code. But some layouts seem to be better for coding than others. I have recently switched from Slovenian layout to the English one and I am really happy with my decision. Let me tell you why.
Slovenian keyboard is a mess
The Slovenian keyboard layout has 31 letters. This is 6 letters more than they are in our alphabet and 5 more than on a ‘normal’ keyboard. We even have two letters left over from Yugoslavia which we aren’t a part of for more than 20 years. Madness! There has been some talk about a new, refined standard a few years back, but I have yet to see an actual physical model. This means that we are stuck with the extra unneeded letters for the foreseeable future.
What does all this got to do with coding
The number of keys on a keyboard is more or less fixed for all the countries round the world. This of course means that those extra letters need to replace other characters. To access those one must do some weird finger acrobatics. Let me give you an example. Writing square brackets ([]) is really easy on a English keyboard, but on a Slovenian one it requires you to press two keys alt gr and f for [ and alt gr and g for ]. It is similar with curly brackets, the ‘at’ symbol, backslash and so on. These are all characters that programmers use very often and having to excess them by weird keyboard combinations is annoying to say the least.
Reasons why I now code on an English layout
It took me quite some time to decide to move to a different layout, even though @zidarsk8, @swizec and @majcnm were convincing me that the English layout is way better for coding. I was not keen on switching because I would still need to use the Slovenian layout from time to time, and switching between them causes confusion and errors. But once I tried to write a few lines of code with the English layout there was no turning back. Here are my reasons for finally switching:
- While writing code I do not need Slovenian letters at all. Writing code and comments should be done in English without an exception. And besides, have you ever tried putting a UTF character in a Python comment? Try it!
- Removing all those unneeded characters frees up space for the characters that you actually do need. Having easier access to brackets, front/back slashe and is a big performance boost.
- Most programming languages were made by people using the English layout. Naturally they chose characters that are quick and easy to type on a English layout.
- English layout is more universal than Slovenian, which means that I won’t be lost if I will have to do some coding on a foreign keyboard someday.
Now I am not saying that every developer should switch. I am just saying that worked for me. Also before somebody suggests Dvorak I am going to say that I’ve tried it but just couldn’t get it to stick. I am not convinced this is a good layout for programming and it sure makes using VIM confusing.
What about you
Do you use a different layout for coding? Which layout do you think is best?
Ubuntu 12.04 Beta 1
A few days ago Ubuntu 12.04 hit the web and I tried it out immediately. I installed it on my USB stick and loaded it up.
I am impressed
A lot has been done since the last Alpha release, where many of the new features were only available from a special testing PPA, but now most of these new features are available by default. The system also seems really stable, and I only saw a small amount of “App crashed, please send feedback” dialogs.
The HUD
One new feature is the HUD and I think it’s amazing. It enables you to search through application menus using your keyboard, making it really easy to access those hard to reach options of the application. This is not a feature regular Joes will be using a lot, but it will allow more advanced users to find those pesky menu items faster. They will aslo reach for the mouse less often, thus saving valuable time. I know some other desktop shells had this feature before (I hear Awesome has it for quite some time now) but I really don’t understand why this isn’t more common.
I had some issues where the HUD displayed the wrong application menus and it was a bit slow at times, but that could all be due to me running the system on an USB stick. All in all this is a feature I am looking forward to most. It might even make me start using Unity instead of Gnome Shell.
Multiple monitor support
There was a lot of talk this release cycle on how 12.04 will improve the multimonitor experience. What they have done so far is to display the Unity launcher on all of the monitors and not just on the primary display like it was before. This change makes you loose some screen space on both of your monitors, but it does make your application shortcuts more available. I can see how this could annoy some people but I don’t really mind seeing a duplicate launcher (you can even make both of them autohide which solves the screen space issue). What I do mind is that currently, the mouse gets stuck while transitioning from one monitor to the other as it “collides” with the launcher in the middle of the screen. This gets a little annoying after some time and I really hope they will fix this before the final release.
Notifications oddly enough still appear only on the secondary monitor, making them easy to miss when you are focusing on something on the primary monitor.
I was surprised that I had no troubles at all with the AMD Catalyst drivers, as multimonitor support worked out of the box even on the propriety drivers. I even copied the xorg.conf file from the beta back to my 11.10 installation to fix an issue I was having.
All in all
I was really tempted to upgrade to the Beta already, but I am sticking with the 11.10 release as I need a stable machine for (school) work. I can’t wait until the final version gets released on April 26th and it seems like I won’t be switching to Arch any time soon…
Three CS students and a tablet
A few weeks ago ComTrade - a local tech company decided to sponsor a challenge event in association with our faculty. The idea was that three teams, each with three students, would work on a fun little project - building an android application that visualizes data received from a remote controlled car. Because the application was meant to run on a Samsung Galaxy Tab 10.1 me and a few of my friends got excited and we signed up for the challenge immediately.
The rules of the game
Each team received a tablet to develop their solution. We were told that the winning team would get to keep all three tablets so we were really motivated to create the best possible application. We did not have a lot of time to do this though. The time constraint was about three weeks and we were in the middle of the exam period when the challenge started.
The application would be receiving data via bluetooth. The remote controlled car was sending data from its G-force sensor, its wheel turn value and its revs count. It was up to us to come up with cool and interesting ways to visualize this data.
Our solution
We quickly decided that drawing graphs is all well and good but it would not be enough. So we came up with an idea to draw the actual car in 3D space. The car would move on a virtual road that it plotted as it went. Our final solution actually worked rather well although we would have to do some more calibration with the actual car, if we wanted the path in our simulation to match the path that the car actually made. One can’t believe what a difference turning radius can have on the path.
We ended up doing a lot of different graphs as well as many dials and counters, for the more techy people out there. We were drawing all of these in canvas which turned out to be a bad decision as it created quite a few performance issues. We managed to find workarounds but decided that our next app would be OpenGl only. OpenGl ES2.0 if we get a say in it!
The most difficult part of the whole thing was creating a design that looked good. Up until a few hours to the deadline our application looked horrible, but then thankfully @zidarsk8 opened up gimp and made the application look awesome.
There were a lot of things that we could still improve, but the final application somehow managed to impress the judges and we ended up winning the challenge!
The development process
We had one tablet but there were three of us. This of course meant that at any given time, two team mates would be forced to use the emulator. Now the thing with the android emulator is that it doesn’t really work if you are trying to do something a bit more complex. We all had android phones though so we decided to split the main application into multiple parts. We created a library project that did most of the hard work, and two applications one for the tablet and on really basic for the phone. This allowed me to work on the OpenGl part of the application even if somebody else got the tablet for the night.
We have also learned fast that it is way more difficult to work efficiently in a team, than it is to work alone. It is really hard to focus on the task at hand, when you have two other people sitting beside you, disturbing you with the problems that they are facing while developing their own part of the application. But thankfully we soon got used to it and got more productive. We still feel that there is a lot of room for improvements, we just need more projects like this tune our group programming skills.
How git saved our lives
I cannot stress this enough. Without git we would be doomed. The project was rather small which meant that we were editing the same files at the same time quite often. Luckily for us, git handles conflicts automagically 99% of the time, even if the same file was edited by 3 different people. And even when we got merge conflicts they were all trivial to resolve. I used a merge tool called meld, which is awesome and made it really easy to see what code goes where. I ended up looking forward to merge conflicts because they were actually fun to resolve. It is weird how great tooling can create a scary process into a fun activity.
The good and the bad
We had fun and we learned a lot. We even got used to working in a group! But there were some downsides too. There were quite a few sleepless nights as we tried to balance exams, the project and our social lives (@majcnM actually had two hours of social life). And even though the whole thing is over, we didn’t receive the tablets yet. This is because ComTrade took “our” tablets to the Embedded World to show off the applications at their booth. This, of course, means that we will have to wait two weeks or more to actually get them. And by then the new and shinny tablets will be touched by a million people, which is not a pleasant thought as well.
To conclude
We had a lot of fun developing the android application and we already have ideas how we could use the OpenGl part and turn it into a driving game. We look forward to more android projects in the feature. By the way, if you have an android application that needs to get developed, send us an email. We love challenges!
PS: To see the code and more screenshots check out our repository: https://github.com/zidarsk8/galaxyCar
The proper way of reading blogs
Reading blogs is something I believe every developer should do often. Not only is it a good way to broaden ones horizon and get up to date with all the great things happening round the world, you can also get in touch with the author and have a discussion about the subject in the comments.
Define the problem
The only problem I personally have with reading blogs is that it is really hard to focus on the content. While I am on the computer there are many distracting things going on. Twitter is buzzing, my nick is getting mentioned on IRC, a new email pops up etc. It is easy for me to ignore all those distractions when I am doing some real work, but reading a blog is not something I consider real work. The notifications are not the only problem. I find it really difficult to focus on a large wall of text on an LCD screen. My eyes start to hurt before I even start reading and the possibility, that I will stop, increases exponentially after each paragraph.
I have the same problems, give me a solution!
I solved all of the problems mentioned above by reading the longer blog posts on my Kindle. Now I primarily bought a Kindle for reading books. Where I am from, most books are rather expensive and the translations can sometimes be bad, especially with technical books on programming and the like. A kindle allows me to buy books easily and have them delivered to me in a matter of seconds.
Now to get back on reading blogs. Do I even have to point out that reading a longer blog post on an e-ink display is way more enjoyable than on an LCD screen? I also save a lot of time by sending blog posts to my Kindle during the day and then read a batch of them before I go to sleep. I can also get a good safety distance from all the distracting notifications of my laptop and read the blogs in peace, the way they were meant to be read.
How do you get the blogs on your e-reader?
There are many ways of getting a blog on your kindle. You can use the experimental browser to navigate to the blog site for instance, but I would not recommend that, as it can be a bit cumbersome. I found the solution that suits me best is a simple Chromium extension that sends the article (and just the article) to my kindle using my @free.kindle.com email address. For this I use an extension called Kindle It and I’ve been really happy with it, as unlike many others I’ve tried, it just works.
What are your thoughts on the subject? How did you read this blog post?
Published
The AMD Linux Drivers
A couple of days ago AMD released Catalyst 12.1 drivers for Linux. I have been looking forward to this release as I had a lot of issues with previous drivers, namely with gnome-shell support.
Why did I put myself through this?
Installing AMD drivers on Linux is never a pleasant experience and the open source drivers work out of the box, so why did I put myself through this? Well the open source drivers have a few shortcomings:
- Battery life: My laptop battery lasts roughly an hour longer on official drivers.
- GPU temperature: The core temperature is down to a pleasant 42 degrees C (was 60+ on open source drivers).
- I can now run more graphically intensive applications (yay games!).
Full of hope that this new release will fix all the issues I had with previous versions, I embarked on an epic quest to get it working on my laptop.
Installing proprietary drivers
To install the drivers I followed the steps on the Unofficial Wiki page for the AMD Linux driver. The steps themselves are pretty straight forward and I will not go into them here. Instead I will focus on everything that went wrong after I had the drivers installed.
After the reboot I got thrown into fallback mode and something was clearly wrong. Running fglrxinfo in the terminal gave me the following error:
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 139 (ATIFGLEXTENSION)
Minor opcode of failed request: 66 ()
Serial number of failed request: 13
Current serial number in output stream: 13
A lot of googling later I found out that modprobe decided to blacklist the fglrx driver. This was probably due to a failed installation of a previous version. The bottom line was that the kernel module was not being loaded at boot which, of course, caused the drivers to fail. Thankfully the solution was pretty straight forward, I only had to open the modprobe blacklist file, located at /etc/modprobe.d/blacklist.conf and delete the following line:
blacklist fglrx
After another reboot the drivers loaded successfuly working and both gnome-shell and Unity desktop seemed to be working!
There were still some issues though
To my surprise both Unity and gnome-shell worked well on the 12.1 Catalyst drivers. Random crashes and visual artifacts were gone and shell animations (when pressing the <super> key) were fast and responsive. There was an issue with moving windows across the screen though. The animation was jerky and flickery and it annoyed me to the point that I started googling for a solution.
The solution for the Unity desktop is hidden away in CompizConfig Settings Manager, under OpenGl. I had to disable the option called Sync To VBlank. After that dragging windows across the screen worked as it should.
There is a similar solution for the gnome-shell desktop. I had to add the line:
export CLUTTER_VBLANK=none
to the end of the ~/.profile file and then everything seemed to be working. That was a fact until I tried to plug in my second monitor.
Multidisplay support
Cloned display worked out of the box, but I wanted a big desktop, spanning over both of my monitors. I opened up Catalyst Control Center (Administrative) (sudo amdcccle), went to the Display Manager page, selected Multi-display desktop with display(s) 1 and clicked apply. That caused the Catalyst Control Center to die silently without an error. I tried to enable multidisplay in the Displays application, where I got this message:
required virtual size does not fit available size:
requested=(3360, 1050), minimum=(320, 200), maximum=(1680, 1680)
Finally something I can google! A solution for this is to put the line Virtual 3360 1050 into the Display SubSection of /etc/X11/xorg.conf. My “Screen” section now looks like this:
Section "Screen"
Identifier "aticonfig-Screen[0]-0"
Device "aticonfig-Device[0]-0"
Monitor "aticonfig-Monitor[0]-0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Virtual 3360 1050
Depth 24
EndSubSection
EndSection
But this isn’t an optimal solution as it has a few issues:
- It only works if both monitors use the same resolution. In my case both monitors use 1680x1050 and it worked as expected, but a friend of mine was unable to hook up his 1920x1080 monitor beside his smaller laptop screen.
- When I unplug the second monitor, this forces the first monitor to the resolution of 1400x1050 (4:3) and I am unable to set the correct resolution neither in amdcccle nor the Displays application. This is why I have to comment out the
Virtual 3360 1050line every time I want to unplug the second monitor.
There is probably a way to solve both of these issues, but my google skills have failed me, any ideas?
EDIT: I managed to solve the both of these problems by copying an xorg.conf file from the Ubumtu 12.04 Beta 1:
Section "ServerLayout"
Identifier "aticonfig Layout"
Screen 0 "aticonfig-Screen[0]-0" 0 0
EndSection
Section "Module"
EndSection
Section "Monitor"
Identifier "aticonfig-Monitor[0]-0"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
EndSection
Section "Monitor"
Identifier "0-LVDS"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
Option "PreferredMode" "1680x1050"
Option "TargetRefresh" "60"
Option "Position" "0 0"
Option "Rotate" "normal"
Option "Disable" "false"
EndSection
Section "Monitor"
Identifier "0-CRT1"
Option "VendorName" "ATI Proprietary Driver"
Option "ModelName" "Generic Autodetecting Monitor"
Option "DPMS" "true"
Option "PreferredMode" "1680x1050"
Option "TargetRefresh" "60"
Option "Position" "1680 0"
Option "Rotate" "normal"
Option "Disable" "false"
EndSection
Section "Device"
Identifier "aticonfig-Device[0]-0"
Driver "fglrx"
Option "Monitor-LVDS" "0-LVDS"
Option "Monitor-CRT1" "0-CRT1"
BusID "PCI:1:0:0"
EndSection
Section "Screen"
Identifier "aticonfig-Screen[0]-0"
Device "aticonfig-Device[0]-0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Virtual 3360 1680
Depth 24
EndSubSection
EndSection
Why I chose Jekyll
Choosing a blogging platform that you like may seem trivial to some, but not to me. All the blogging platforms out there seem either too simple or too complicated for me. This is why I have always resorted to writing my own simple CMS, but the problem was that my own CMS was even worse than all the others. At first it seemed like it suits my needs but I ended up hating it nonetheless.
I tried really hard to get used to Wordpress, I really did! But in the end it just wasn’t working, here are a few resons why:
- Templating is a nightmare. I felt like I needed to invest a lot of time to get my site to behave the way I wanted too.
- The WYSIWYG editor is crap, but I wouldn’t blame WP for this one. I believe that all WYSIWYG editors (Word is another great example) are flawed. Sooner or later the editor will misunderstand what you want it to do and shoot you in the leg.
- The CMS seems bloated and I get lost in all those settings and sub-settings, plugins, themes and whatnot.
Jekyll to the rescue!
Jekyll is a simple static site generator. Basically you feed it a template directory with a page layout and some Markdown content and it spits out a static website which you can upload to your webserver.
It is really easy to install as well. If you have Ruby installed it is just a matter of getting the Jekyll gem. This is usually done with a single command:
sudo gem install jekyll
I actually ran into a little problem, the error message was:
ERROR: Failed to build gem native extension
It turned out that I needed the ruby dev package, the below command fixed my issue:
sudo apt-get install ruby1.9.1-dev
After that I was all ready to start building my new and shiny blog page.
It gets even better
Github provides something called Github:pages (GP). GP is basically a free static page hosting for your projects and/or personal page. It also has Jekyll built in which means that you simply put your jekyll source into a git repository, push it to a specified github branch and github will generate your blog page automagically.
Not only does this force you to keep your blogs in a git repository (which is a good idea by itself), it also makes for the most intuitive way of posting a blog post (well at least for a programmer like me).
Some more sugars
Have you ever wanted beautiful syntax highlighting on your blog? Well Jekyll does Pygments which means I can have beautiful syntax highlighting like this:
def prob42():
f = open('words.txt')
tri = 0
triangle = []
for n in xrange(1, 1000):
triangle.append(n * (n + 1) / 2)
for i in f.readlines():
for j in i.split(',"'):
w = j.replace('"', '')
x = 0
for k in w:
x += ord(k) - 64
if x in triangle:
tri += 1
print tri
I even heard there is LaTeX to PNG support, although I haven’t had the time to check that out yet.
There is still a possibility that I will start hating Jekyll after a few months of blogging. But that may just mean that I actually hate blogging. Hopefully this will not happen!
