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!


Setting up a Debian repo in LAN

It was really a nice experience going to MES College Of Engineering, Kuttippuram last week to attend Debian Mini Conf 2011. Met friends, made new friendships and learned many new things from there. Thanks to Jishnu ettan, for giving me a 50GB Debian repo that contains all the packages of squeeze of both i686 and amd64 architectures. Today, I will explain how to set up a Debian repo (squeeze) so that it be can shared over LAN.

First, run terminal and switch to root user.


If you have the repo as an ISO image file, we need to mount it to a directory. The following command does that:

#mount <path-to-iso> <path-to-mount> -o loop

Edit /etc/apt/source.lst and add the repo we mounted. Append the following line to the file:

deb file:///<mounted-path> squeeze main

Update the package list:

#apt-get update

We are going to share the files using http, hence we need a webserver. To install apache:

#apt-get install apache2

Make a symbolic link of <mounted-path> in /var/www

#ln -s /var/www/repo <mounted-path>

Done! Now add this machine as a repository in other Debian systems in LAN, edit /etc/apt/source.lst to:

deb http://<ip-of-server>/repo squeeze main

The same can be done using a FTP server. All you have to do is to make the symbolic link in FTP’s configured path and use ftp:// instead of http:// in /etc/apt/source.lst. 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':

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

February 19, 2011 8 comments

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
#       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("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("rm mp3files_list mp3files_list1")

Improvements to code and suggestions are always welcome, Happy Hacking πŸ™‚

A simple square pattern in C++

Here’s a small C++ program which outputs a square pattern according to the size entered. Code is given below :

* sqpattern.cpp
* Copyright 2010 Ershad K ershad92@gmail.com
* Licensed under GPL Version 3
* To compile - g++ -o sqpattern sqpattern.cpp
* To execute - ./sqpattern

#include <iostream>
using namespace std;

int main()
  int size;
  cout << "Enter size: ";
  cin >> size;

  int count = 1;
  cout << " ";
  while (count++ < size) cout << " _";

  for (int i = 1; i < size; i++)
      int numOfCharsPerLine = 0;
      cout << "\n";
      for (int j = 0; j < i; j++)
          cout << " |";
          numOfCharsPerLine += 2;

      cout << "_";
      numOfCharsPerLine += 1;

      int k = 1;
      while (k++ < (size*2) - numOfCharsPerLine )
      cout << " ";
      cout << "|";

  count = 1;
  cout << "\n ";
  while (count++ <= (size)-1 ) cout << "|_";

  cout << "|\n";

return 0;


The programs drawsΒ  squares of any size entered. The code needs improvement, please feel free to give suggestions. Click here for ‘experiments’ git repo. Thank you πŸ™‚

Categories: C++ Tags: , ,

How to download .deb packages for offline installation

Some of my friends always complain that they are not able download packages due to Internet availability issues or usage limit. Most of them are using different Ubuntu versions, hence I cannot use APTonCD to download the packages for them. Here’s a small solution for this, Thanks to ilug-tvm and Rajeesh ettan.

Step 1: Get the download URLs in a file :

Execute the following command replacing package-names with required ones, separating by a space.

$apt-get -y install --print-uris package-name | cut -d\' -f2 | grep http:// > apturls

Step 2: Copy this file (apturls) to a machine which has high-speed Internet access, and execute the following command to download the packages:

$wget -i path-to-apturls-file

Step 3: Now get those downloaded packages to your machine, and install them using :

$cd path-to-the-downloaded-packages-directory

$sudo dpkg -i *.deb


Thank you, Good Luck πŸ™‚