01110100110101010101011101100010
fedora
Command Line Fu
Nov 14th
A few weeks back i bought a new monitor Dell U2312HM, its a brilliant monitor with support for portrait/landscape switching.
so as it always happens after buying a new monitor i planned a movie night and ran into the screen lock problem, i have set 2 minute timeout for screen lock and some why changing screen settings didn’t work, i knew i had to find a solution and fast or the above xkcd might actually happen with me
so this is what i came up with, having worked with X bindings before for Game-on this was done in under 5 mins (after reading some docs) , another day saved all thanks to Linux, X11 and previous X11 binding experience
This code moves the mouse pointer back and forth every few seconds, which is defined in DURATION
Weekend Project IV
Sep 25th
Few days back i bought an Arduino UNO board, this is my first Arduino Project and it was damn easy!! I can see the power that Arduino has to offer for hobbyist, i have worked on 8051 and few avr (without Arduino) before, doing stuff with an arduino is pretty easy and straightforward.
In this weekend project i am using a JHD162a (16×2 LCD) connected with Arduino UNO to display the name of the current song being played, i am running mpd on my machine so have used python-mpd to retrieve song info and pyserial to transfer the data over UART to UNO, the UNO just spits out the data received over UART to the LCD.
This is a copy of my earlier project which i did in my third year in college, but that was using a 8051 and i wrote a library (code available here) to control the LCD, currently i am using the LiquidCrystal Arduino library for that.
here is the demonstration
UPDATE -> song name, artist and time also added, video here
PS – you might also want to see the extremely cheap CNC machine being made by one of my friend
6 months in Citrix / Bangalore
Jul 4th

Lot of time has passed since i last updated my blog, i have finished the 7th Semester of my engineering and just one step from my degree, i have moved from Manipal to Bangalore for my last (8th) semester and I was interning at Citrix Systems, working with NetScaler Tools team. The last few days as a college student have turned out to be awesome, living in Bangalore with friends is fun (except for Bangalore’s night life which sucks big time). During the last 6 months i have learned at lot about life, universe and everything :p .

The experience at Citrix was great mostly because of the kind of work and guidance i was given, we arrived in Bangalore on 3rd Jan, it was weird that no accommodation was provided to us for the initial weeks, but since manipal is one night journey away from bangalore, we came here after our exams and searched for a flat, we finally decided on a flat in Cambridge Layout (near Indiarnagar) since it was pretty close to our work place which was near brigade road !! I was working with the NetScaler Tools team on a internal stress testing tool called BlackWidow, the best thing about my work at citrix was that i had to work with FreeBSD kernel, which meant i had to use *NIX development tools (cscope/vim/kgdb which is what i am pretty comfortable with) and not some bloated IDE (for me Vim + cscope > any IDE) which i had to learn for my last internship at microsoft, this helped me get started pretty quickly which surprised my mentor, although i was not assigned the feature i wanted to implement still my work was pretty interesting.
I found Citrix to be a really awesome company to work at, it has a lot of interesting products, the people are friendly and helpful and the work culture is great, ohh and not to forget the facilities they provide to employees, but one thing that I noticed during my internship is that the work can become monotonous, so you really need to pitch in and get some interesting work or one might end up doing similar work again and again, but then i think thats the case with most of the places.

The main motive behind me coming to bangalore was meeting interesting people, not that people in Manipal were less interesting, i wanted to meet with some ‘similar’ minded people. I had hardly talked to other people from my college who interned with me, but they turned out be interesting, also interns from other colleges like PeeShit (read PESIT) were interesting. I didnt actually went out to meet people, but then i guess i can do that now as i am going to stay in bangalore. A few days back i met folks at Artoo on their Demo Day, they are doing some really interesting work.

My internship is over but I will be staying in Bangalore for my first full time job, i have a few on campus and off campus offers but more on that some time later, Thanks to my flat mates Mikhail Jacob, Sohil Himanish and Tushar Dadlani for making my stay in Bangalore awesome and Thanks to my mentor, manager, all fellow interns and everyone else at citrix for making my work awesome, you people rock !!
multiple mouse / keyboard in linux
Oct 4th
few days ago i came upon an article about human computer interactions which mentioned different ways we interact with computes and how we will interact with computers in future, the article instantly reminded me of MPX, now i dont know how many of you remember MPX which enabled interaction of multiple mouse/keyboards in linux. Xserver 1.7 which is used in most of the disto’s was released with MPX, so i decided to find out how to make it work on my existing Fedora 13 box, and using it is pretty simple you just need to use xinput and configure X for multiple input, for that you first need to install xinput, on fedora it is provided by the package “xorg-x11-apps” just do a
[ankur@x144 ankur]# yum install xorg-x11-apps -y
and you are done, for other distro’s i guess there sould be a similar package, after the install we need to find what all is plugged in to the computer, for that we do “xinput list”
[ankur@x144 ankur]# xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ PS/2 Mouse id=14 [slave pointer (2)] ⎜ ↳ AlpsPS/2 ALPS GlidePoint id=15 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ Video Bus id=6 [slave keyboard (3)] ↳ Power Button id=7 [slave keyboard (3)] ↳ Sleep Button id=8 [slave keyboard (3)] ↳ Laptop Integrated Webcam id=9 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)] ↳ Dell WMI hotkeys id=16 [slave keyboard (3)]
this returns a list of all the input devices, i am running this on my laptop so you can see “AlpsPS/2 ALPS GlidePoint” and “AT Translated Set 2 keyboard” which are my laptop’s mouse and keyboard, to enable multiple keyboard/mouse i will create a group and move my laptops mouse and keyboard to the group,
[ankur@x144 ankur]# xinput create-master main
[ankur@x144 ankur]# xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PS/2 Mouse id=14 [slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=15 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Video Bus id=6 [slave keyboard (3)]
↳ Power Button id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ Laptop Integrated Webcam id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
↳ Dell WMI hotkeys id=16 [slave keyboard (3)]
⎡ main pointer id=10 [master pointer (11)]
⎜ ↳ laptop XTEST pointer id=12 [slave pointer (10)]
⎣ main keyboard id=11 [master keyboard (10)]
↳ laptop XTEST keyboard id=17 [slave keyboard (11)]
above i created a group by the name “main”, you can see a second mouse cursor on screen as soon as you do this, to make both these mouse/keyboard active i will move my laptop’s mouse (id-> 15) and keyboard (id-> 13) to this newly created group
[ankur@x144 ankur]# xinput reattach 15 10 [ankur@x144 ankur]# xinput reattach 13 11
now if i connect an external mouse and keyboard to my laptop i can see both working simultaneously, if you want multiple (more then 2) mouse and keyboards to work, you can create a separate group for them and move them to that group in a similar manner.
after doing this I was not able to find any benefit of using multiple mouse/keyboard on a laptop but it will make sense when you have multi monitor setup and multiple users trying to use the same machine simultaneously.
Game On / Weekend Project III
Sep 25th
Few weeks ago I posted about playing pong using tilt sensors on the phone, Now me and Abhimanyu have taken that to the next level and have made it a generic game controller for any game running on the computer. We faced some problems when Abhimanyu’s Samsung Wave refused to work, but luckily i bought a Samsung Galaxy 3 (Android 2.1) about a week before that, so we shifted out focus on Android.
For Game On we make use of the phone’s sensors and touch screen to generate different gestures and motion events, we use these events to generate control data and sent the control data over a socket to the computer over a wireless network. On the PC the received data (different for each motion event or gesture) is processed by the computer and a specific task is performed, in this case generating a Key Event.
The Code for Game On can be found on github
Here is a video of the android phone (Samsung I5800 Galaxy 3) being used to control a car racing game.
And now the working
After this we decided to work on something which i wanted to finish a long time ago (remember Weekend Project I) so we finished Weekend Project III which is well Weekend Project I + Weekend Project II
And the working of Weekend Project III
The Data Flow is Phone —-WiFi—-> PC —-USB—-> USB to RS232 Converter —-UART—-> MicroControler —-Relays—-> Toy Car Remote —-RF—-> Toy Car, which is almost same as that of Weekend Project I, except for processing of Sensor Data on Phone.
PS – if you were not able to look at the video’s above they can be found here, here, here and here, also Game On won 2nd prize in Mobi Vision – a mobile application development competition
Weekend Project II
Aug 29th
In march i posted about a weekend project which involved controlling a small toy car using my cell phone, this is a similar one again implemented in few hours, here we are trying to play the awesome game of pong using the tilt sensor on Samsung Wave. The pong application running on Laptop is written in Qt (C++) and the application on the Phone is written using the Bada SDK.
The working is simple, the pong application running on Laptop requires phones to make a TCP connection to it. Phones just create a TCP connection to the application on PC and sends tilt sensor data to it, movement of paddles is done by the PC application based on the value it receives from the phones. It still requires better calibration and we will work on it after the exams are over (Education prevents you from doing cool things!!), there are a lot of ideas buzzing in our empty heads (according to our teachers!!) , the original idea was by Abhimanyu which we implemented.
if you cannot see the above video here and here are short demo of how it works.
PS – code and proper working for the previous and this weekend project will be posted soon!
Simple Finite State Machines in C
Apr 5th
I was having discussion about State Machines with one of my friend, regarding pro’s and con’s of implementing programs as Sate Machines, it was then that i realised there is no simple way to implement programs as Finite State Machines, so here is a very basic implementation of FSM in C
file: fsm.h contains the function definition for our FSM
Weekend Project
Mar 11th
In Dec 2009 at foss.in at the maemo stall i saw a guy control a small toy car through accelerometer on his N900, i thought of replicating that but it just remained in my mind, so last Saturday i finally decided to implement it and went straight to a toy store and bought a toy RF car, one hour of hacking and i was able to control the small car through by phone (Nokia E61i) here is the video of it working.
the concept is simple, i send commands through my phone over wifi to my laptop which controls the car remote, controlling a toy car remote is very easy with a Parallel port and few transistors but laptops don’t have parallel ports, so i used a micro-controller in between to sort that out, so now micro controller controls the car remote by acting on signals received over UART from laptop.
the working is Phone —(WiFi)—>Laptop —(USB/UART)—> Micro controller —(Relays)—> Car Remote —(RF)—> Toy Car
will post details with code sometime later
How Manipal got its first Linux (fedora) server
Jun 25th
It all started with a failing Student’s Teacher Feedback System, designed by few fourth year students of my college, in oct-nov 2008 the system was not able to scale and everything was reverted back to paper, it was then when i was contacted by a teacher from my Department ( Information and Communication Technology ), regarding if i can improve it.
i asked DJ if he wants to join me and after few weeks of coding there it was Manipal university’s first (working) Feedback System, when the point of hosting it came, i was surprised to find Manipal University has no Linux servers, i mean come on no Linux what are you people click sys admins, then we decided to setup our own server in the department, thus giving Manipal university its first Linux ( fedora 10 ) server.
currently it just hosts the Feedback System, but we are planning to use it as local ( internal ) fedora repository mirror, we need permission from the WiFi provider ION because almost all the students use only WiFi and not LAN, last time we tried we were denied by saying ” You are a threat to our network “, lets see how it goes this time. we will also require people to manage it but i think this can be handled very well by LUG Manipal, some pics
PS – i am looking for a way to convince them that setting up a mirror will be helpful for them as well as students can anyone suggest me how to go about it??
Creating your own service like tinyurl
May 24th
Few weeks ago i came across this article on Techcrunch which says tinyurl is worth $46Million (of course before twitter started using bit.ly as default) which made me think how hard is it to make a simple service like tinyurl and i figured out its not hard. so i used apache’s mod_rewrite to rewrite the url and forward the code to a php script ( url.php ) which will then search for the url in database and take the use to the original url and for shorting, url it is inserted into a table with a auto increment primary key and the key is converted to base36 which contains [a-z] and [0-9], making the short code…
First create a database say ‘shorturl’
CREATE TABLE IF NOT EXISTS `shorturl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`url` varchar(300) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
then create file .htaccess where you want your url to be and write
RewriteEngine On
RewriteCond %{REQUEST_URI} \/([0-9a-z]*)$ [NC]
RewriteRule ^(.*) url.php?url=%1 [L]
and to create the url we will use a simple file say create.php
<html>
<head>
<title>Url Shortner</title>
</head>
<body>
<?php
ob_start();
$host=""; //host
$dbuser=""; // database username
$dbpass=""; // database password
$db=""; //database name
$con = mysql_connect($host,$dbuser,$dbpass);
mysql_select_db("url",$con);
if (!isset($_POST['shorten']))
{
echo "<center><h3>Enter the url to shorten</h3><form method='POST'><input type='text' name='url' />
<input type='submit' name='shorten' value='Shorten' /></form></center>";
}
else
{
if (isset($_POST['url']))
{
$url=" ".mysql_real_escape_string($_POST['url']);
if (strpos($url,"http://") or strpos($url,"https://") or strpos($url,"ftp://"))
{
$url=mysql_real_escape_string($_POST['url']);
}
else
{
$url="http://".mysql_real_escape_string($_POST['url']);
}
$q="select * from url where url='{$url}'";
$res = mysql_query($q,$con);
$row=mysql_fetch_row($res);
if (!$row)
{
$query="insert into url set url='{$url}'";
$res = mysql_query($query,$con);
}
$query1="select id from url where url='{$url}' limit 1";
$res=mysql_query($query1,$con);
$row=mysql_fetch_row($res);
echo "shortened url is http://yoursite.com/".base_convert($row[0],10,36);
}
}
ob_end_flush();
?>
</body>
</html>
then our url.php file
<?php
ob_start();
$host=""; //host
$dbuser=""; // database username
$dbpass=""; // database password
$db=""; //database name
$con = mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($db,$con);
if (isset($_GET['url']))
{
$query="select * from url where id ='".base_convert(mysql_real_escape_string($_GET['url']),36,10)."'";
$res = mysql_query($query,$con);
$row=mysql_fetch_row($res);
header("Location: ".$row[1]);
}
ob_end_flush();
?>
Download here










