Archive
Good bye wordpress.com
Hi, I’m moving to a new home today – ershadk.com. Please update your email subscriptions and feed settings. Thank you very much for reading and sharing your opinions on little posts I wrote and please do that in my new blog too. And I would like to thank wordpress.com for hosting my little blog for last few years. All posts and comments in this blog are copied to the new blog. That’s it, Welcome to ershadk.com!
Tathva memories @ NITC
“.. I’m leaving this campus today. I will miss the late-night hangouts with Kartik and Pankaj.. I will miss the stay in Kartik’s room with Arjun and Rohit (If you are reading this, All the best for your IAS, brother). I will miss Ramnath, Arnab and all my friends here and this great institution.. I’m sure I will be back here for the next event.. With a million beautiful memories in 4 days.. Adieu NITC..”
Anagram Solver in C
Hi, Here’s a small anagram solver written in C. It works based on generating permutations of given string and comparing them using a dictionary. For fast search in dictionary, the program first creates an index of the starting location of each alphabet. It takes a few minutes to process long words.
Here’s the source code. Suggestions are always welcome, Greetings
Update: There’s a little problem in using the term ‘anagram solver’ here. An anagram solver finds words from another valid word – But this program finds words from the characters of given valid/invalid word. Thanks to technikhil for the info
It was really a wonderful experience at MES :)
Yesterday, I went to MES College of Engineering to deliver a small talk on programming and free software, it was entirely a new experience for me. A bigger crowd than expected was present. It went fine
Thanks to Raghesh sir, Raju sir, S@IT and to friends there
I’m happy to share my little slides. It was created according to numerous suggestions by Raghesh sir. For fun, the presentation was started with a SMS trigger from audience
The code for that is like ‘get-thing-done’ and doesn’t have the quality to upload. It’s developed using python with gammu module. Please feel free to tell me if you want to have a look at the code.
Attribution: ‘Input -> Fun -> Output’ is an idea got from Niyam Bhushan during his talk at NIT Calicut on FOSS Meet day.
Thank you
C program to extract email IDs from a file
Here’s a small program to extract email IDs from an input file. It could have done using regex (in Python or in any other high level language), but doing it in C is more fun, eh?
The code is here!
Usage: parseEmail [FILE]
Suggestions and improvements are always welcome
Thank you!
A sudoku checking program in C :)
It just started when my younger bro, Shafeeq who reads hacker news everyday, found a little interesting blog post. It was about the authors experience in applying for an internship at Google. The candidate was asked to write a program to check a completed sudoku during the telephone interview for errors, in his favorite programming language. I asked bro, “Why don’t you give it a try?!”. He’s now in 11th standard and started coding in C++ which he learns in Computer Science subject. He came up with the code in one day, and then it was my turn to do that
Here’s the way I solved the problem and it’s in pure C.
You can find the code here, in github. The input is given as a plain text file that contains 9×9 numbers separated by space. A sample input is given below:
7 2 3 8 4 6 1 5 9
6 1 5 3 9 2 4 7 8
8 4 9 7 1 5 6 3 2
3 7 8 6 5 4 9 2 1
1 9 4 2 8 7 3 6 5
2 5 6 9 3 1 8 4 7
5 6 1 4 7 9 2 8 3
4 8 7 1 2 3 5 9 6
9 3 2 5 6 8 7 1 4
And to check for errors, please call the program with the file as argument, like this -
$checksudoku <data_file>
Hope you enjoyed it, Please go through the code and feel free to post your valuable comments and suggestions here. Thank you
The little twitter client I use :)
Here’s a small python script to update and read tweets from different timelines. You can use it with head/tail commands to customize the output. Actually, I wrote this script just for personal use and now I would like to share it with you
Thanks to tweepy python module, make sure it’s installed before trying the script
#!/usr/bin/env python
# Copyright 2011 Ershad K <ershad92@[nospam]gmail.com>
# Licensed under GPL Version 3
import sys
import tweepy
CONSUMER_KEY = ' Fill here'
CONSUMER_SECRET = ' File here too'
ACCESS_KEY = ' Type yours here'
ACCESS_SECRET = 'Type yours here too'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
if sys.argv[1] == 'u':
api.update_status(sys.argv[2])
elif sys.argv[1] == 'p':
public_tweets = api.public_timeline()
for tweet in public_tweets:
print tweet.user.screen_name,":",tweet.text
print ""
elif sys.argv[1] == 'r':
mention_tweets = api.mentions()
for mtweet in mention_tweets:
print mtweet.user.screen_name,":",mtweet.text
print ""
elif sys.argv[1] == 'h':
friends_tweets = api.home_timeline()
for ftweet in friends_tweets:
print ftweet.user.screen_name,":", ftweet.text
print ""
Hope you like it
Python Script to fix VBR errors of mp3 files in a directory, recursively
If the seek bar of your rhythmbox is not working with some mp3 files, it might be an issue with Variable Bit Rate of them. The tool, ‘vbrfix’ written by William Pye solves the issue, but the problem is that it doesn’t have an option to search for files recursively. Here is a small python script that gets the paths of multiple mp3 files recursively and give them as arguments to vbrfix tool. Make sure you install vbrfix (from the software repo) before running the script.
Please see comments for a better, 1 line substitute to do the same. Thanks to Rajeesh ettan and Syam ettan
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# vbrfixdir.py
#
# Copyright 2011 Ershad K <ershad92@gmail.com>
#
# Usage: python vbrfixdir.py
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import sys
import os
quote = '"'
folder = sys.argv[1]
find_command = "find " + folder
find_command += " > mp3files_list"
os.system(find_command)
os.system("sed 1d mp3files_list > mp3files_list1");
f = open("mp3files_list1", 'r')
for line in f:
line = line[:len(line)-1]
command = "vbrfix -always "
command += quote + line + quote
command += " " + quote + line + quote
print command
os.system(command)
os.system("rm mp3files_list mp3files_list1")
Improvements to code and suggestions are always welcome, Happy Hacking
Irssi notification in terminal using ‘write command’
In Desktop Environments like KDE or GNOME, we have special libraries like knotify or libnotify to display notifications from various applications. Some applications like Konversation has its own notification systems. But what about command line tools like Irssi? Imagine you are chatting in tty1 using irssi and doing something in tty2.How will you know if someone has mentioned you nick in channel message? Well, here is a small solution for this.
Luke Macken has written a wonderful perl script to display notifications using notify-send command in desktop environments. Thanks to open source, I tweaked the call to notify-send command to suit our tty-notification. All that you have to do is this :
Step 1 : Get the Script and write it to a file ‘notify.pl’.
Step 2 : Replace
system(“notify-send -i gtk-dialog-info -t 5000 ‘$dest->{target}’ ‘$stripped’”);
With
system(“echo ‘$dest->{target}’ ‘$stripped’ | write <Your username>”);
Make sure you replace <Your username> with your system username.
Step 3 : Put it in ~/.irssi/scripts/ directory.
Step 4 : Execute the following commands in irssi:
/load perl
/script load notify
Done, you will get notification to the latest tty to which you are logged in!
Good luck
PS: The notification that you get is not eye-candy, please adjust for it now

