Introducing “Adsense Client” – a new Android application I have created to help you track your Adsense Earnings on the go. I have been look for a decent application to track my Adsense Earnings. However all the free applications are severely limited and do not offer even the basic functionalities and hence I decided to make one of my own. This is my first attempt at making a full fledged Android application. I have tested this application across all Android software versions greater than 1.5. This application won’t work for Android s/w versions less than 1.5. Continue reading
Yearly Archives: 2010
Ruby 1.9.2 Final Build for Ubuntu, Kubuntu Maverick (10.10) Uploaded to Launchpad PPA
Sometime back I added the final ruby 1.9.2 build for Ubuntu Lucid. I have recompiled the same for Maverick today and have uploaded it to the ppa. Along with the ruby1.9.2 packages I have uploaded the ruby-default package too. This setups the update-alternatives system for different ruby versions. Read more about it here. Continue reading
XSL template for Generating Per Page TOC for Docbook HTML Output
Sometime back I worked on this upcoming Ruby On Rails Book and helped the author convert his docbook to various formats like HTML, PDF, EPUB, Kindle etc. While working with the HTML output, I figured that the standard output spewed out by the Docbook XSL stylesheets is quite boring. So I improvised a lil, added per page TOC, pretty css, icons etc. I spent quite some time on the per page TOC feature. Here’s the XSL template that I wrote for the TOC. Continue reading
Bash Tricks: Deal with a Flaky Internet Connection
Its been about 9 months in Vietnam now. One problem that I have to deal with on a day to day basis here is the flaky Internet connection. There are good days and bad days and bad days are incredibly frustrating. The Internet is ON and OFF every five minutes. I wrote this simple script which will wait for the Internet to be active before executing commands given to the script as an argument. I have found this very useful for commands like git pull/push, svn update etc.
#!/bin/bash
COMMAND="$@"
PING=$(ping -q -c 1 8.8.8.8 &>/dev/null; echo $?)
while [ $PING -gt 0 ]; do
PING=$(ping -q -c 1 8.8.8.8 &>/dev/null; echo $?)
done
$COMMAND
I call it "wfi", wait-for-internet. Dump this script into your bin directory and give it executable permissions.
To test this script, disconnect your wifi/ethernet connection and then run the following command.
wfi ls -l
Reconnect your wifi/ethernet, and you'll see that the command gets executed as soon as your Internet connection is up.
wfi git pull
Now I can execute these commands through wfi and then go back to my work and be less exasperated.
Sample Bluetooth RFCOMM Client App in Python
I recently wrote a bluetooth rfcomm client app in C. However before I started writing the code in C, I prototyped it using python. The python code obviously is 50 times shorter than the C code and was very easy to write. Surprisingly it also feels snappier than its C counterpart. May be I screwed up the C code somewhere. Continue reading
Sample Bluetooth RFCOMM Client App in C
I recently worked with a client who wanted a Bluetooth RFCOMM client-server application. The server would sit on an android phone, while the client will run on an embedded linux device. The rfcomm client portion was just sample code that he wanted to base his implementation on. I wrote a quick app for the same. The code you are about to see is ugly and can be rewritten to look more pleasing to the eye. Also includes a horrible goto hack. But it works and can be used to base rfcomm implementations on. Continue reading
Bash Tricks: Get the Value of a Variable whose Name is Stored in Another Variable
If want to find out the value of a variable whose name is stored in another variable, you need to dereference the variable. This is how you do it.
Lets say the name of the variable is test123 and it has a value equal to 123. Also the name test123 is stored in another variable varname. To find out the value of test123, you will use the ! dereferencing operator.
@~$ test123=123
@~$ varname=test123
@~$ echo ${!varname}
123
Took me a while to figure this out.
Easily Create Sitemaps for Static HTML Websites Using Google’s Sitemap Generator Tool
All popular CMS softwares come with addons/plugins to automatically generate sitemaps for your website everytime you add new content. I recently added a few documentation sites which are all plain html files. I needed a tool to generate the sitemap files for these websites. After googling around a bit, I came across google’s own sitemap generation tool. It’s a very good tool and I highly recommend it for sitemap generation for html websites. Continue reading
Bash Tricks: Delete the Last Substring from a Delimited String
I wrote a post about how to print just the last substring of a delimited string. Instead if you’d want to delete just the last substring, and keep rest of the string intact, thats a little trickier.
Here’s how you do it.
@~$ echo "abc:cde:efg" | awk 'BEGIN {FS=ORS=":"} {for(i=1;i<NF;i++) print $i}' | sed 's/$/\n/'
abc:cde:
FS is the field separator, while ORS is the output record separator. ORS by default is the new line character \n. What we are doing here is splitting the string using awk, and then printing all but the last records i < NF. The sed statment is just adding a newline at the end.
If you want to skip the trailing delimiter, you could use the code below.
@~$ echo "abc:cde:efg" | awk 'BEGIN {FS=ORS=":"} {for(i=1;i<NF;i++) print $i}' | sed 's/:$/\n/'
abc:cde
Here the sed statement replaces the trailing : with a newline. To skip the newline, you can change the sed statement to sed 's/:$//'.
Bash Tricks: Print the Last Substring from a Delimited String
@~$ echo "abc:cde:efg" | awk 'BEGIN {FS=":"} {print $NF}'
efg
The variable NF holds the number or records in the string, which is 3 in this case. So when you’re do a print $NF, you are actually executing print $3, and thus printing the last record/substring.