Photobucket

Sunday, July 24, 2011

Finally flashed an android device

Yay!

Before any of you think I was not sober while writing this and before you start imagining stuff, I'd like to make it clear that I am talking about my tablet here. Yes, I finally flashed it. I just couldn't resist trying it out and so I finally tried it out. I still have to confess I don't know what exactly is the whole process of flashing and what happens during this process but the story goes like this. 




<Fart>
So, I got this new tablet from my boss to play around. It was a new android tablet released in India just this month. It is called Zinglife. I know the name sounds so much chinese ( actually this would turn out to be one reason which would help me in my pursuit to flash this ). This is a neat tablet to play around with in India and spoil it, but I would not suggest anyone to buy it if they really want to join the android tablets fun.

Next day, I was asked by my boss to try to change the name 'Zinglife' during the booting . So I set about trying that. First thing is that I did not know what the 'boot logo' was called( it is called boot logo, which I came to know much later). Now, I believed that something like this can only be done by rooting the device. So I started searching on how to root this device.
</Fart>


Actually, Zinglife comes with 'superuser' app preinstalled. But it did not seem to have been rooted. Then I tried z4root applicaiton. It said success. But then none of the applications could get superuser privileges and even in the terminal emulator, when I typed 'su' I was getting some linkage error. So I searched for the error and found that the possible culprit could be the su binary which might be screwed up and I will have to replace it. So now I have to connect the tablet to my pc via adb.


You think that will be easy, right. Just shove the otg-usb cable into the usb slot in your lappy and run a command. It should be connected. That is how it was for my cell phone if I remember right. But nope. My tablet is not detected. So a quick googling tells me that I need to create a rules files somewhere in the /etc hierarchy. And I also need to get the vendor ID for this. I try all I could but still for some reason I just couldn't get it to work for this device :( . Only good thing which came out of this - I learnt a new command 'lsusb' which i needed to find vendor ID.


So next I began a quest of insane googling all the key words I could for various things. It is important to note here that the main thing I _had_ to do was change the boot logo. Not rooting the device and not getting su binary to work. So it was in this journey into the abyss of webdom did I find some tablet which looked identical to Zinglife. After some more research I found that Zinglife is infact just rebranded Zenithink zt-180. Just a cheap chinese product. So the name makes sense afterall ;)


Now that I knew what tablet this was, I could get the extensive data which was already present and found out that I could flash a new rom easily into this tablet. It turned out that Zenithink guys made this easy. All you need to do is create a folder called zt-update in a freshly formatted micro sd card and place the needed files into it and then just switch on the tablet with the 'back'(right button on the face) button pressed. So all I needed to do was get these files, change the file called boot.logo with my custom boot.logo (which has to be vertically inverted to come correctly) and then 'flash' my tablet. A whole series of verbose get printed on your screen and there you have it - your brand new custom rom. So finally I do not fear the word 'flash' as much as I did earlier. Here is a pic of my boot logo.
Now, this made me wonder


How do you flash any new device which was just released?
And what exactly is flashing?


I would like to find out answers to that and would be thankful if some one actually could give me more insights into all this.


This post is basically for those people in India who have recently bought a Zinglife tablet and wish to hack on it and play with it. The almost seemingly trivial knowledge that it is a rebranded chinese tablet should help a lot. BTW mine is a Zinglife ZL 101 10' tablet.

Ignore the 'Read more' button here. This is the end of the post.
Read more!

Friday, July 22, 2011

How to design a game in 10 minutes.

Trust me when I say this is a non technical post.
-


Everyone would have played some game or the other in his/her lifetime. And surely, most would have played a lot of board games or games on electronic devices. So one day I wanted to design a game. A game, which you can play again and again, and not a game which has a definite solution to win. So that is what I intend to explain in this post.


How to design a game in 10 minutes
Step 1 Enroll yourself in a course of Basic Graph Theory in the maths dept, especially under the Prof S A Chaudum. It is a lovely course and the professor is really, as we use the word very often in insti, God in it. So complete the course fast and get an S grade( for people from outside insti it is 10 points ) in it. You are done with graph theory and the first step.


At this point you should be asking me a question.


"Would just a basic course in graph theory suffice to design a game or would you also need to take an advance course".


Trust me my friends, you are not planning to write a solution for the game, you just want to design it.


Step 2 Now enroll yourself in the Automata Theory(most correctly Languages, machines and computation ) course by Prof Kamala Krithivasan in CSE dept. Even this is an awesome course and taught very very well too. Successfully complete this course. Any grade is fine as long as you pass here.


At this point I had like to congratulate you. You are half done.


Step 3 This is the hardest step. Choose an NP-complete problem from graph theory and disguise it as well as you can into some real world objects and their relation. Sprinkle some player interaction so that the game is not something which one player can play independently of the other. Choose a scoring system and you are done. Hurray!! All this shouldn't take more than 9 minutes.


Step 4 This is the easiest step of all. After commercializing this game and marketing it well, you'll be earning millions. Just write me a check for a million dollars. It shouldn't take more than a minute.


That is it. You have designed a game in 10 minutes. Your name will be etched forever in the glorious books of history in bold golden letters.


If you have any technical questions you can directly ask me by mailing me or asking your questions in the comments section. For these people the post ends right here.


At this point I believe some of you might have some questions for me. If you want to ask


"How does semester + semester + 9 minutes + 1 minute add up to 10 minutes?"


I would just like to say to those people that this post was intended only for the students who are pursuing their Master of Arts in IITM or those who've passed out recently ( yes, the first batch of MA students have finally passed out of IIT and god save them ).


Disclaimer: This post was written in the most serious of senses and the author should be forgiven for any non seriousness that might be apparent to the reader in this post.


Ignore the 'Read more' button here. This is the end of the post.
Read more!

Thursday, July 7, 2011

How to create a User Interface (UI) using Glade and pygtk - 1

This is a very basic tutorial to just get started on making small GUI.
I use Ubuntu but I believe any linux distro must do. Part 2 of this is specific to python but you could also do similar things with pure C.


<Important Fart>
I have decided to help readers by identifying the various parts of my posts as fart or not.This way anyone can dive into the actual stuff without having to bear with my runblings :D .
</Important Fart>


<Fart>
So yesterday night I had tried to give a small talk on the IRC channel #iitm-linux about GUI programming. I had intended to give the talk mainly based on what I had learnt during my first year summer as part of writing an application for Shaastra Distro( Shaastra-2010). 


So the main thing which irritated me initially while writing the application was that although I could drag and drop in Glade I couldn't exactly just drag and drop things at the location where I wanted. If I wanted a button at say location 70,30 in the window, I just couldn't place it there directly.And more irritating was that I couldn't even set the size of the button as I had wanted. 


It was not until later that I realized why was it like that and why that was actually a better way to make a UI. I might not have made much sense till now but you will understand what I mean as you proceed along this post. Ofcourse making UI has lot more things than just this dragging and dropping but, to me as a beginner, the most irritating part was this. That is why, although using glade is just something which you get after playing around with it for sometime, I am including it in this tutorial.
</Fart>


We Begin
To make UI there are two parts
One is to design how the application should look, where must a button be placed etc. The other part and the _important & interesting_ part is controlling how your app reacts to user inputs like clicking on buttons or pressing keys on the keyboard.


The easy way to do this is by using glade for the first part and using pygtk coding in python for the second part. This is the link to jump directly into part2


PART 1 : "Dragging and Dropping"


Little Introduction:
Most of the applications based in gnome desktop environment use gtk to show the UI. What is there in the gtk libraries are definitions of various types of objects possible i.e, windows, buttons and stuff like that. So what we try to do is use these libraries to create windows, button etc by setting various properties of these GTKObjects like width, height name, etc and assigning locations to these objects.
We do all this using glade to make our life easier and save time.


So first, install Glade software if you don't have it.
Open up glade. If a smaller window opens asking for some details and stuff like that just close it or click Ok.So first thing you need is a top level window. From your left side menu choose a window and just click on it. You should have it in your main space. You can see that on the right hand side towards the lower half all the window's properties.


Basically you will need to play around with them if you are making UI but in this intro I will just point you to some important things you can tweak in those properties on the right bottom. Name, resizable, default height, width etc can be changed in the 'General' settings tab. Right now you won't need to change anything in 'Signals' tab but that will come in Part 2.So I would suggest playing around a bit at this point in the tut.


Your glade window should look like this.


So now .. if you are done with playing around with those properties we shall proceed.
Important point to note is - when you intend to make UI, the best way to make it is by imagining the whole space into vertical and horizontal boxes. This is how glade wants you to make it. You will understand what I mean as you proceed.


I will use something called horizontal boxes and vertical boxes first. You can find Horizontal boxes and vertical boxes in the left side menu under containers.
Here are steps to follow


1) Click on vertical box
2) Place the vertical box on the window
3) Choose the number of Partitions to 2
4) Click on horizontal box
5) Choose the number to 3 after placing it into the bottom half of the vertical box.
It should look something like this


6) Click on button from left side panel and place it into the centre of the 3 partitions in the horizontal box.


You will observe the button to be huge in size and ugly. Choose the button now in the hierarchy on the top right and go to the 'Packing' tab in the bottom right.


7)Make the 'Fill' and 'Expand' properties to 'No'
8) Go to 'Common' tab and check the width request and height request boxes and fill both of them with a value 50 .


You will observe that the button is not exactly square. Now select the hbox from the hierarchy and go to its 'Packing' tab . And here again make the 'Fill' and 'Expand' property to 'No'. Now you will observe that the button is finally correct. So you should understand that when you are trying to decide a size for any item you are just requesting a size. Only if it is possible to have that size will you get it. The possibility depends on various things especially the container in which the item is placed. It also depends on the neighbors and other such factors. 


This way if you did not do the math properly and kept random sizes or if the user later resizes the window, everything will be taken care.I hope you now understood what I meant by " Imagine your whole UI in terms of vertical and horizontal boxes".


This tutorial was to just point you towards things. You will get better only by playing around with glade.


NICE TIP: I used this a lot. If you want to place something at some particular position but you are not getting it exactly at that position, then you could use an item called 'Label' in the left side menu near the buttons. You can place this at the right places where you want a space, may be so that you could move a button to further right or up. You have to remove the name of this label for it to mix into white space and your final user won't know.


This ends part 1 of the tutorial which I did not expect to be this big.
Find part two here.


Ignore the 'Read more' button here. This is the end of the post.
Read more!

How to create a User Interface (UI) using Glade and pygtk - 2

So this is part 2 in which I am going to explain controlling UI. You can find part 1 here. The coding part will be done in python in this post but you can also do the same in C


PART 2: "Being the God to your UI"
Before we go into the coding you need to understand what I mean by 'controlling'.It is how you would want the application to respond to user clicking and stuff like that. So for this what actually happens is something like this ....


Little Introduction:
There is something called an 'X server' running on your comp. Long long ago when there used to be long bearded hippie coders in front of giant sized terminals and everyone used mechanical keyboards. The main 'X server' would actually be running some place else on some main computer with lots of computing power . Now anyone who wants a window, suppose a gedit window, would request this 'Xserver' to send it a window of gedit You could have asked from any room in your university and the main computer which is running the server will send the data to your machine on how to render this window. 


So your machine just renders this on the screen. When you suppose click on some place, this X server is the one which gets to know where you clicked and it will hand these events to your application so that you can control what happens when a particular event occurs. So the X events include mouse click, key-press, key-release and many more which the 'X server' captures and tells your application about it if it is relevant to it.


To summarize what I said in the last paragraph, there are things called events which you need to handle which is the final step to make UI.


Let us get started.
Select the 'Signals' tab of the button and under 'GtkButton' select the 'clicked' event and under the Handler column for this event select a function name which you would like to define soon. I chose 'on_button1_clicked' .
Some thing like this
Read more!

Daskalos demo

I am storing all the content which I might want to look back at again on this blog. So this is the video of the demo of an application I wrote as part of Shaastra Distro for Shaastra-2010.

This is the github link for project Daskalos



Ignore the 'Read more' button here. This is the end of the post.
Read more!