Archive

Uncategorized


I have working pretty hard on multiple projects recently, and that’s why I haven’t got the time to document my experiments with Cubieboard 2, but rest assured a good number of blog posts are coming up on that front.  However, I picked up this game from the internet called the 2048-tile game. Its a pretty neat (and addictive game) you can find the link here.

Here is the jist of what the game is – you have a 4*4 tile board and begins with 2 tiles with the number “2” on them. You can use the arrow keys to move all the tiles on the board in the 4 directions. Two tiles with the same number with combine to form a new tile with the next power of two, when they move in the direction you want them to.

Also, with every direction move, the game spawns a random “2” or “4” in one of the empty spaces on the board.

Image

As an example, I have shown the starting frame, and the frames after the first move in the left directions and the second move in the downward direction, notice how the tiles of 2 combine to make a tile of 4. You win the game when you reach the 2048 tile; or if you run out of space to move (the more likely possibility). Its more difficult than it sounds, not to forget, the game is very addictive. 

A lot of people I know, have played the game, but not many have succeeded in reaching to the 2048 tile (If github is to be believed, even the creator himself hasn’t finished the game yet.) The one thing I realized that was always messing up my game was these godforsaken tiles coming up from all directions and blocking by bigger tiles – and it forced me to take another route which took a lot of space on the board. So I figured that restricting the directions from which the tiles could block would be very crucial to the solution.

A simple way to do the above would be to restrict all your movement to the bottom side of the board and never pressing the up direction, just use the lefts and rights and downs to manoeuvre the tiles as much as you can. There will be a few instances where you will have to use the up direction thus causing a disruption if a 2 or 4 blocks your tiles – but its still possible to control single anomalies.

The second step that you need to take is to ensure that the you block the bottom left corner for the tile with the highest power of two, and the subsequent tiles in the bottom row arranged in the descending order. This is very important – because you will soon realize that when you do this, a single tile can sweep away all tiles taking you to the next higher power of two – making your path and hence your movements defined at any point of time – basically at any point in the game, you would be concentrating in making a power of two sufficient enough to trigger a chain reaction of geometric progressions.

A few pictures will make this clearer:

Image

The above picture is an example of this strategy, I kept the all my movements devoid of the up button, and concentrated on keeping the highest tile in the corner with the bottom row in the descending order. If you notice the images, all it will take in say the first image is a tile of 32 to introduce the 256 tile, similarly you see the strategy being applied in the subsequent images as well.

It takes time, but once you have the flow going you know what particular tile to focus on next and once you do that, the entire game becomes a series of local problems.

And now for the winning set of tiles (Narcissistic ego boost ):

Image

I have tried this strategy, and have reached the end goal three times. It seems like a strategy that is reproducible and seems logical that it will work. However, I am trying to see if the problem can be formalized in mathematical terms, and hence the solution would be a formal one as well.


I frequently use GitHub to maintain a lot of my personal projects, minor hacks and if I am upto it, contributing to other open source packages. It is like this free (almost) unlimited remote server where you can push all your code. The downside is, unless you pay them some money, all your code ends up being open to everyone. Now if for some reason, you don’t want the code to be public, you might have to buy private space on GitHub or maybe try and apply for the free educational repositories. (Or move to BitBucket, but again the free ones are limited).

However, there is a cheap, albeit risky alternative to that – You can use your Dropbox space (Or Google Drive – if you are a fan of Google reading through your stuff) as a free Git remote server! This is not a fool proof method and the chances for conflicts arising are high if multiple users are pushing code, so it is best recommended for personal work, where only one person is pushing code to the remote repo.

A lot of people have done this before, so this is old news, but I think its a decent hack and worth telling people about it.

The Steps

Let’s move to the command line and set up our repository!

Step 1 :  Move to your Dropbox folder and create a folder (Git in our example) where you will be creating your repositories and initialize a bare repository like this:

 cd ~/Dropbox/Git
git init --bare dropboxrepo.git 

This will create a folder with the name dropboxrepo.git and inside it, you can see that it has all the essentials for a git repository.

Guts of the bare repository

Guts of the bare repository

Now technically you are making this repository on your local machine, but since it is inside the Dropbox folder, you are syncing it to their servers as well, and can access the folder contents anywhere.

Step 2 : Now go the local repository, where you maintain the code that you want to push to your remote repository, and add the above folder as a remote like this:

 git remote add dropboxremote ~/Dropbox/Git/dropboxrepo.git 

Basically what you did here is  add the path to your dropboxrepo.git folder as a remote alias. So now the alias dropboxremote will refer to this folder and will be identified as a remote repository.

Step 3 : Now that you have initialized a remote repo and added it to the remote alias in your local repo, you can now push your code like this:

 git push -u dropboxremote master </code>
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 458 bytes, done.
Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done.
To /Users/abhinav/Dropbox/Git/dropboxrepo.git
* [new branch] master -> master
 Branch master set up to track remote branch master from origin.

After this, you should see the Dropbox spin sign for a while as it syncs all your files. However you will notice that after syncing, you don’t see your files in the folder but the same files you saw before (they are modified now though). But don’t worry all your files are synced. You can now follow the same steps as above and clone this repository on another machine and you will see all your committed code right there!

Word of caution

As I said before, this is not exactly the best way to have your own private remote server (It’s free!) and it comes with its own dangers. Firstly, if you push or pull while the folder is still syncing you might encounter errors like this:

error: unable to find ea2ae105b8955b3f73d79065bc52ee3126cd2e4f
error: refs/heads/master does not point to a valid object!
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched. 

If you see this error, just wait for the syncing to finish and try again. If it still doesn’t work, you will have to delete your current remote repo and create a new one and try again.

The above issue occurs frequently if there are a lot of contributors pushing the code to the same remote repo. Of course you can be careful and avoid them, just don’t pull/push while syncing!

I recently started using this method to maintain some of my private projects and it works just fine!

Happy tinkering!


A dedicated Home Server is a useful thing to have if you’re a hacker. You can use it as a remote repository for all your code, for hosting your website, dumping all your media and accessing it with any other device and even printer sharing. This post gives a detailed procedure of making (in my opinion) a near perfect home server using a Cubieboard!

Benefits of using a Cubieboard

Low Cost : For $50, the Cubieboard is like the cheapest computer in the world. Complete with 1GB RAM, 4GB space, 10/100 Ethernet port, two USB ports, SDcard slot, camera interface, audio out, HDMI AND along with all this awesomeness, it also has a complete SATA port. It also comes with a nice glass box for protection.

Low Power : The low cost doesn’t just end there with the pricing, the average power consumption of the Cubieboard is 8W, which if compared to standard low power servers is 5 times less! So it just doesn’t cost less, it consumes less as well!

Getting Started

You will need a functional operating system with SSH and Ethernet ports enabled on the Cubieboard before installing the server stack.In case you haven’t seen already, I have described how to do that in this post. Make sure you have followed the steps and installed a headless Debian on your Cubieboard before reading further. I have released the latest kernel images with fixed patches and SATA power enabled over here.

Now that the SATA is enabled, you can now easily connect a HDD, thus removing any space constraint on your server. (NOTE: The SATA works for a 2.5 inch drive only, for other HDD types, you will need external power source)

To ensure that the SATA interface works on boot, just type this command in your terminal (on the Cubieboard, of course!)

echo "sw_ahci_platform" >> /etc/modules

After connecting the Ethernet port, make sure you note down the IP of your server. You can do that by using the DHCP list or just doing a shell login with the TTL pins and running ifconfig, you will get all the network connection details including the IP.

Now that we have all the hardware and Operating System stuff settled, we consider our server stack options. One of the interesting options is the Napkin Server. It is based on JRuby, Sinatara and Neo4j graph database. The Napkin server offers a REST API with predefined services for storing and retrieving configuration information and collecting time series data from client devices. A plug-in model provides extensibility in HTTP handling and periodic processing of stored data. It is a very interesting project, you can refer to the wiki for Cubieboard installation here.

The second option would be to go for the more traditional LAMP stack. The installation is a very simple 3-step process.

Step 1: Installing Apache 2 and PHP 5

Apache is usually the go-to choice for most linux based servers. You can easily install Apache and configure it with PHP 5 with the package manager tool like this:

 root@cubie:~# apt-get install apache2 php5 libapache2-mod-php5 

The folder holding all the php pages by default is located in /var/www/

To check if php is properly installed, just open a sample php file:

 root@cubie:~# vi /var/www/test_file.php 

and add the following php code

 {codecitation}<?php phpinfo();?>{/codecitation} 

After you have saved this file, you can test by opening a browser on a different machine and connect to the following link: http://%5Bcubieboard’s-ip%5D//test_file.php and you will see this :

ScreenShot007-5

Step 2 : Installing MySQL Database server

The next step would be installing the database backbone. Again, installing MySQL is an easy task with the package manager:

 root@cubie:~# apt-get install mysql-server mysql-client php5-mysql 

While installing, you will get be prompted to insert a root mysql password. You can add it there,but in case you forget you can even add it later like this:

 mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=<your password> WHERE user="root";
mysql> FLUSH PRIVILEGES; 

Step 3 : Installing PHPMyAdmin

PHPMyAdmin is an extremely easy-to-use web-tool to manage the databases on your server. It is a very handy tool to remotely manage databases on your server. To install it simply go:

 root@cubie:~# apt-get install phpmyadmin 

During the installation process, you will be prompted with a screen to choose your choice of web-server. In our case, it is Apache2

debian6-kde-2011-04-07-23-07-56

Once the installation is complete, to test it, open a browser on a different machine connected in the same network, and open the link : http://%5Bcubieboard’s-ip%5D/phpmyadmin

Doing so will result in this:

ScreenShot012-3

To enter, you must use the Cubieboard’s login details. Once you enter the correct values, it should lead you to a Dashboard, which is pretty self explanatory to use!

ScreenShot013-3

Now you have a fully functional web-server!! You can now start experimenting with your server, maybe by installing wordpress on it and using it as a host for your own website!

Happy tinkering!