Pages

Thursday, November 10, 2011

Lets grow with Facebook

Now, this is not some expert advice; just giving words to the thoughts of many. Many of us have realized, at some point of this year or another, that Facebook is not just another site, not anymore. With a user base of over 800 million, there's barely anyone left out of the social networking site.

So what does that mean to us ? Firstly, we must realize that all your dreams to start now and grow up to compete against Facebook, might be a little too far-fetched. I am, generally, not a pessimistic person, so I would like to add that former statement holds for most of the people out there planning to go up against Facebook; you might be an exception.

Secondly, and in my opinion more importantly, the large user base of Facebook gives others the idea to make use of the user base. We need to realize that the number of 'active' users on Facebook is a good indicator of 'active' internet users. These are the people any one wants to attract to their own products. But, if the number of people on facebook includes the people you want to target, why not target them directly ? Facebook now offers plethora of APIs giving developers a whole new world still left to be explored.

The point I am trying to convey should be clear from the following example. Say, you are a developer/entrepreneur with a idea that you think could change the way people think about 'something'. But again, your idea is heavily dependent on the input from your users; their participation is what drives your idea. In that case, you need a lot of users to visit your site. Mark Zuckerberg, on the other hand, is trying to make sure that people spend more time on Facebook and have less reasons to go outside. Given the resources, including the user base and money, they are expected to do a good job at that. I suggest, that we help him do this. How ? Why do you need a new site, when you can just create an application 'within' facebook. Looking at various apps such as The Guardian and Washington Post Social Reader, one can only begin to imagine the possibilities of such applications.

So what's the advantage ? For you, users; for users, the fact that they get the content without leaving facebook. At first, it might sound naive, but think about it and remember what they say,
"If you can't beat them, join them." 

Wednesday, August 17, 2011

Tab completes my life

Sorry for the somewhat awkward title. I just couldn't resist the geeky pun, and couldn't come up with a better phrase to express it. Hope you got the short message from the title. Also please forgive the awful (or awesome?) prose below. I've always wanted to write a post like this :)

Having been a happy Linux user for the past year-and-a-half, I respect the art of command line-fu. The most useful, yet simple, trick in the bag of the CLI ninja is, of course, the all-powerful Tab key. In one stroke - literally - it can help him type even the longest of commands with minimal key presses. I just love going ..<Tab>..<Tab>..<Tab><Enter> on my terminal, commands flowing at the speed of thought.

Now I'm so used to it, I expect it to be present everywhere - my browser, my text editor, in git commands, in the python interactive interpreter. Basically, I expect my computer to do its job - that is, helping me out while I try to do mine. That does not happen easily, however. So I set out on a quest - to try to have some form of Tab-completion in as many programs as possible. Below, I chronicle my journey, for the benefit of the traveller seeking the same end :-

The Switch from Bash to Zsh:
All Linuxes come with the same default shell: bash. However, there's another shell out there - zsh - which is little known, but extremely powerful. It's the first step from CLI apprentice to CLI productivity master. There are some excellent plugins available for zsh which add tab completion for many commands like git, pip, gem, and kill along with some bonuses. It'll also help you out with many other small things, like ignoring case and correcting spelling mistakes.

If you're thinking to try out zsh, I'd recommend installing Oh My Zsh! first thing after you install zsh itself. It'll make it much easier to set up zsh to your liking, replete with themes, plugins, and aliases. Also, as it turns out, the $RPS1 environment variable, along with the git support in Oh My Zsh!, pretty much renders my alternative (and very useful) bash prompt obsolete.

The Text Editor:
Since I'm a die-hard Emacs user, this section's a bit biased. For Emacs, I use Auto Complete Mode. It's fairly easy to setup, and blazing fast once you get used to it. Note that this is not code completion, it's simple, cross-buffer word completion, so it'll suggest words based on what's in the rest of the buffer, or in other open buffers. I find this better than code completion for the simple reason that code completion would require me to install separate plugins for each language I use, while on the other hand, word completion is universally effective, if not as accurate. Heck, it even works in comments. Combine that with YASnippet, and you'll find yourself with one finger on the Tab key nearly perpetually, and code flowing from your fingers.

Oh, and let's not forget ido-mode. It's the coolest, dead-simplest Emacs plugin ever.

For Vim users who feel left out, a quick Google search yields this.

The Interactive Interpreters (Python and Ruby):
I hated it when I fired up python the first time and it didn't offer Tab-completion. I later understood that since whitespace is significant in Python, completion is not enabled by default in the interpreter (or the Python REPL, in purist-speak). I figured spaces could be used for indentation just as easily as tabs, so I enabled completion using this .pythonrc. It's not like I miss tabs for indentation now.

Coming to irb (the Ruby interpreter), you can have Tab-completion and syntax highlighting in it using the wirble gem and a .irbrc. Pretty straight forward, supremely effective, no down-sides.

The Browser:
Not much to say here. Probably the only thing you can Tab-complete in a browser is URLs, which the latest versions of Firefox and Chrome already do, anyway (it's not true, CLI-style tab-completion; just passable). If you want word completion too and you're on a recent version of Firefox, use this addon. Or, if you're using an older Firefox version, you could try this one.


Here ended my quest. Let your chronicles and criticisms be outlined in the comments below.

Friday, July 29, 2011

Ack!

I'm sure you've used grep at some point in your life as a programmer to search for that piece of code in your code base. I was using it myself — until today. It turns out there's a better alternative to all that time spent trying to get the perfect grep alias so it works as it should: searching recursively, ignoring the .git/.svn directory, ignoring backup files (foo~/#foo#), printing out the file names and line numbers, grouping matches by file name. You've got to listen when Jacob Kaplan-Moss, creator of Django, has this to say about it:
"Whoa, this is *so* much better than grep it's not even funny."
It's called ack. Without further ado, you can install it on your Ubuntu system using sudo apt-get install ack-grep (for other distros, check out the ack homepage). Then use it as: ack-grep search_term. It's really that simple (although the default colours are a little irritating). You can see what files/directories it ignores by default using ack-grep --help. Here's a screenshot for the impatient reader:


'nuff said. I'm gonna go explore the man page.

Thursday, July 28, 2011

The alternative (and very useful) bash prompt

Almost all Linux users have used bash at some point, but how many of them know how to customize it to their liking? Here is a screenshot of one custom bash prompt I've created, which I find much better than the default (it took me a few hours to reach this point, owing mainly to my poor skills in bash scripting):

Click the image to view it properly.
So, other than showing useful stuff related to git repositories, it gives me a full line to type my command, and separates each command with a hyphenated separator and a newline, so I can see it clearly as I scroll upwards. The corresponding code snippet is (put it at the end of your ~/.bashrc if you wish to use it):

PS1='\[\033[01;34m\]\$\[\033[00m\] '

parse_git_dirty () {
    [[ $(__git_ps1) != "" ]] && [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

print_pre_prompt () {
    # the first part of the prompt, i.e., the user's name
    local PS1U=$USER

    # the second part of the prompt, i.e., the present working directory
    local PS1WD="${PWD}"
    if [[ $PS1WD = "$HOME" ]]; then PS1WD=\~; fi
    if [[ $PS1WD = *"$HOME"/* ]]; then PS1WD=\~${PS1WD#$HOME}; fi

    # the fourth and last part of the prompt, i.e., the git stuff
    local git_dirty=$(parse_git_dirty)
    local git_dirty_color="\033[1;31m"
    local git_clean_color="\033[1;30m"
    if [[ $git_dirty = "*" ]]; then local git_color=$git_dirty_color; else local git_color=$git_clean_color; fi
    local PS1R=`__git_ps1 "%s"`$git_dirty

    # the third part of the prompt, i.e., the separator consisting of hyphens
    local PS1SEP=""
    while [ $(echo ${#PS1U}+${#PS1SEP}+${#PS1WD}+${#PS1R}+3 | bc) -lt $COLUMNS ]; do
        PS1SEP=$PS1SEP-
    done

    # putting it all together
    printf "\n\033[1;32m%s \033[1;34m%s \033[0;36m%s $git_color%s" "$PS1U" "$PS1WD" "$PS1SEP" "$PS1R"
}

PROMPT_COMMAND=print_pre_prompt

Rather than explaining the code (which I'm not very clear about myself), I'll point you to some links which helped me along the way:
1. https://wiki.archlinux.org/index.php/Color_Bash_Prompt
2. http://superuser.com/questions/187455/right-align-part-of-prompt
3. https://gist.github.com/306785/4da3e39fc012475140fdf33ef0f6bc0a6e7c04a5

-----
Liked this article? How about following me or Rajat on Twitter?

Friday, July 15, 2011

5 Cool Things in Git

Thing #1: Pretty coloured output
Command: git config --global color.ui auto
This will make all output colour-coded. So now git diff and git status will show up in red-green awesomeness (not that that's a great help to me, but it will be to you, undoubtedly).

Thing #2: Aliases
Command: git config --global alias.shortcut command
The beloved time-savers. Here are some of my aliases:
git config --global alias.l log
git config --global alias.s status
git config --global alias.co checkout

Thing #3: Awesome-looking git log
Command: git log --pretty=oneline --graph
Combine that with Thing #1, and you've got an ASCII-art style, rainbow-coloured, git log. And, if you have a lot of free time, or if you're just way too interested in git, you can read man git-log. There's ton of options in there.

Thing #4: A bucket-load of ways to refer to commits
Ok, first of all, branches are not branches. Yes, you read that right. A "branch" is actually just a reference to the latest commit in it. A commit's lineage defines its history, and so arises the idea of a "branch".

You can refer to commits in many ways. Let's agree on some common notations before I explain that. Every commit can be referred to by a commit pointer. The commit pointer may be followed by any number of modifiers, which will together constitute another commit pointer. A commit pointer without any modifiers can have any one of the following forms:
    a. the SHA key of the commit (the first 6-7 characters should suffice)
    b. HEAD (refers to the latest commit in the current branch)
    c. branch_name (refers to the latest commit in the branch specifed by branch_name)
    d. tag_name (refers to the commit pointed to by the tag called tag_name)

A modifier, on the other hand, can be either one of the following:
    a. ~n (refers to the nth ancestor of the commit pointed to by the commit pointer preceding it)
    b. ^ (refers to the parent of the commit pointed to by the commit pointer preceding it. If a commit has multiple parents, you can use ^n to refer to the nth one)

We all learn by example, so let's consider a possible scenario. Say we have a git repository with 2 branches, master and testing. Say the master branch has 2 commits with SHA keys 0af4780... (=HEAD) and 326399d..., and say the testing branch has 3 commits. Say the current branch is testing. Here are some examples in the context of that scenario:
    a. 0af4780... = HEAD = self explanatory
    b. HEAD~1 = commit 326399d...
    c. testing^^ = the oldest commit in the testing branch

Thing #5: Alternate usages
In commands like git diff, which make sense for both commits and files, the commit pointers passed to them can be followed by :file_path, if you wish to compare 2 past versions of a file instead of 2 whole commits. For example, say we have a file called blah.c in the lib/ directory in our repository (which happens to be huge), and we want to see what changes were made to it between the second last and fourth last commits. We could do something like:

git diff HEAD~1:lib/blah.c HEAD~3:lib/blah.c

Another interesting thing is commit ranges, which you can pass to commands like git log to see what has changed in that range of commits. They have the form commit_pointer1..commit_pointer2.

If this got you interested, you really should read this amazing PDF on the internals of git.

----
If you liked this article, why not extend your appreciation by following me or Rajat on Twitter?

Thursday, July 14, 2011

Sed - reducing effort since '74

Sed, short for 'stream editor', is a (pretty awesome) utility created by  Lee E. McMahon of Bell Labs. I would like to take a detour here and mention that I am in real awe of Bell labs. They have given us so much, starting from C and C++ to Unix itself. Another useful utility (which I should cover here soon) made by them is cscope.

Now, coming back to 'sed', it saved me quite some effort today while working with Kate. Well, frankly, the time it took me to learn some basic tricks and perfect the command might have taken a little longer than it would have taken me to manually make the change, but I won't add that time. Why ? Because the time invested would save me plenty more in the future, whereas doing the task manually wouldn't save me anything in the future.

So what was this task ? As I have explained here, I am working on the modeline variable editor in Kate. The widget that my mentor and I had created, to be used in place of the 'QLineEdit' , had some help text. I had forgotten to wrap the text in i18n() wrappers.

The initial text was something like this :-
item-> setHelpText(" Help text goes here ") ;

Now had there been just two or three of such occurrences, I wouldn't have thought about using sed; but there were a lot more (I didn't check then, but as it turns out, about 40 changes were made using sed). Anyways, I needed the text to be modified to :-

item->setHelpText(i18n(" Help text goes here"));

With sed, that wasn't too hard.

sed 's:setHelpText(\"\([a-zA-Z0-9.() ]*\)\"):setHelpText(i18n(\"\1\")):g' <old >new

Just one line and all the changes were made. And I had with me another patch to offer to the community ;-).

Combined with Regular Expression (Regex), sed has a lot to offer.

Suggested links :

For more information on Internalization (i18n), check out the Wikipedia page.
For a tutorial on Sed, I would suggest this.
Online manual for Sed is available here.

Thursday, July 7, 2011

Kate's Variable Editor

Well, as I have mentioned before, I am part of 'Season of KDE' this year and am working on Kate. My project statement is to create a 'Modeline Editor'.

Frankly speaking, modeline variables is a feature that I was unaware of before I read about this project.  It is one of those subtle features that can make editing and formatting very easy. With just a line at the beginning (or end) of the file you can tell the editor things about tab-width, syntax-highlighting, background-color and what not.

With a lot of assistance from my mentor, Dominik Haumann, we began working on the variable editor by creating a new 'widget'. For now, this remains independent of the rest of the Kate but once it is ready (which it almost is), we'd merge it.

Some important lessons learnt during the process that I'd like to share :-

  1. Make use of version control :- After spending about 24 hours on a part of the project, I e-mailed my mentor the new source code; only to learn that those very changes had already been made. So how did I miss it ? I thought I was smart enough to update my working copy in the beginning of those 24 hours, but not once during those working hours did I bother to check if some changes had been made. That was one valuable lesson. As Vicky correctly pointed out though, there was a silver lining : I wrote some code that was written by a more experienced person as well; I had the opportunity to compare and learn. 
  2. Develop complex widgets separately : As I mentioned above, the variable editor is being developed as a widget separately. It required a combination of combo-boxes to cater for boolean, integer, colors, fonts and other strings. The development of widget 'within' the editor would have made it harder. With only this segment to focus on, we can forget about the rest of the editor and develop and test the variable-editor. Here are some snapshots of the widget :-

Here you can see the combo-boxes for boolean and color values
Spin box for integer

The color combo and the line-edit for string values.

The color combo-box (KColorCombo)

The font combo-box (KFontCombo)

Yet another integer spin button and color-combo.
Soon, this widget would be a part of the Kate text editor.

    Sunday, July 3, 2011

    Beautiful code == poetry

    This post is long and a little on the non-technical side, but I think the implications are very relevant to the readers. You might be somewhat pissed that I'm not talking about how sweet jQuery is, but here goes.

    How many of us programmers just drool over clean, self-documenting code? I do. I literally strive to have my code look like elegant poetry, so much so that I spend a good portion of my time refactoring. Some might call that over-the-top. I call it an eye for detail. I believe code is like literature; you have to write it in a way so that others (and more importantly a future you) can immediately understand what you mean without getting bogged down with pathetic, obscure syntax or poor style. After all, code is not meant to be "write-once". Moreover, a few years down the line, you want to be able to look back on your code and say, "Whoa. I used to write amazing code even back then".

    I try to take extreme care about naming my functions in just the right way. So whenever I read it later on, I know exactly what it does. I won't say I'm very good at it, but I believe I'm getting better.

    The language syntax is crucial to how readable the code is. That is one thing Ruby does well. Let's see a contrived example:

    a = [1, 2, 3] + [4, 5, 6] - [5]   # = [1, 2, 3, 4, 6]
    b = "blah"
    return true if a.include? 4 and not b.empty?
    

    Another thing Ruby is good at: Domain Specific Languages (DSLs). They're an attempt to make non-geeks write code to get stuff done easily. As an example, consider this: rocket scientists are good at space-talk, but bad at writing code. What if we could create a program which exposes an API that looks like rocket science? It doesn't get any cooler. The scientist doesn't need to know Ruby, only the API. He can think in terms of space shuttles and takeoff times and things like that. For example, a rocket science DSL in Ruby might allow a rocket scientist to write stuff like:

    shuttle.fill_tank 50   # tank up 50 liters
    shuttle.launch_after 3 if shuttle.prepared? # 3... 2... 1... go!
    

    You might say, "Wait a sec. Isn't that your regular object-oriented code?". Yes, but normally we create that for ourselves. A DSL's API is meant to be used by the users to write code.

    A related example comes to mind. The other day my friend and I were working on a DSL for access control in a web application, which controls what user gets to access what part of the application. The most important thing in a DSL, as you might've noticed, is the API. Everything else is secondary. We needed to name a function which would take a condition, and a result to be returned if the condition was met. We thought up names like make_rule, but we weren't satisfied. After some brainstorming, we came up with an API like this one:

    given :condition => user.admin?, :return => true

    I feel the function name given is the most important thing in this API. It conveys the purpose unambiguously and reads like natural English. Any other name would've made it confusing or misleading. And remember again, some John Doe titled "Maintainer" at a company is going to be using this API directly, without being good at Ruby, that's why the nomenclature is so very important.

    If you're more of a JavaScript guy, you should check out CoffeeScript. It's "a little language that compiles into JavaScript", with and Ruby and Python-inspired syntax. Imagine being able to write stuff like the following and have it run as JavaScript:

    volume = 10 if band isnt SpinalTap
    letTheWildRumpusBegin() unless answer is no

    I've presented my (rather long) case. Let the comments fly.

    UPDATE: We're finally done with the access control DSL, and the API now looks like this:

    given :condition => { :controller.is => :admin, :action.not.in => [:create, :show] },
          :return => true

    isn't that beautiful? :)

    ----
    If you like this article, consider following me and Rajat on Twitter.

    Thursday, June 30, 2011

    APIs and OAuth

    OAuth (or Open Authorization) has become the norm these days. What is it ? In simple terms, it is a protocol that allows developers and third-party applications to use data on a server without giving away the password of the served user.

    A little history about OAuth first ! Interestingly, as mentioned on Wikipedia, OAuth sprang from "Twitter OpenID implementation". Soon, this turned into a project in which people from some well known organizations such as Google were involved. Eventually, the draft for OAuth Core 1.0 was released in October 2007 and the protocol was published in April 2010.

    So now where is this protocol used ? Pretty much every site that offers developers to access their data use this protocol. As Twitter and Facebook Applications become popular, so does this protocol.

    So how does it work ? The basic idea is simple (as is for most great inventions), the developer registers his application with the data provider. The provider then generates a "Consumer key" and a "Consumer Secret key". These two strings need to be a part of the request sent by the application to request any data or authentication. When the user, through the application, tries to access his data, a URL is created which allows the application to be 'authenticated' by the user. Once the user accepts to authorize the application to access the data, a PIN (a string of numbers) is provided. Entering this PIN into the application allows the application to identify itself (along with the Consumer Key) and obtain an "Access Token". This access token (yet again a hashed string), is used by the application with each request. Obviously, this is just the basic idea of the protocol and a lot of numbers and parameters are introduced in order to make it more secure.

    So, why is it better ? Or rather I should first answer, what is it better than ? Earlier, most websites like Twitter used "Basic Access Authentication". It required the user to give his username and password to the application for accessing its data. (Yeah, basic authentication was really basic ;-) ).  So, why is OAuth better ? It is better for applications as :-

    • Applications need not maintain the username and password of the user, which is a responsibility of the application (or developer). 
    • If the password is changed, the application would be rendered useless, unless it is reset in the settings.
    It is better for the users as :-

    • User is not required to give away his or her password.
    • List of the applications authorized to access the data is available on the website. This allows the user to revoke access, especially to applications which are no longer used.
    List of OAuth libraries for various languages can be obtained here.

    Monday, June 27, 2011

    An introduction to jQuery

    This is my first attempt at a technical article, so please bear with me. Comments/feedback on the content and writing style are welcome :)

    You've probably heard of JavaScript: the hacky, ugly language that drives most of the cool stuff on the web. I whole-heartedly agree. Hell, the language itself has more inconsistencies than one can imagine. There is no cross-browser standard implementation of JavaScript. Why then is it so popular?

    I can't say I have the answer, but there is one crucial JavaScript library, in my opinion, that has contributed to its popularity significantly: jQuery. It is one the few code tools I'd say is "cute" (the others on my list, as of now, are Ruby and Python). Also one of the few things with great documentation.

    It's great at manipulating elements on a webpage, and at making cross-browser, pain-free AJAX requests. Let's dive in and see some jQuery code:

    $(function() {
      $("input#animator").toggle(function() {
        $('div#foo.bar').slideUp('fast');
        $(this).val('Show');
      }, function() {
        $('div#foo.bar').slideDown('fast');
        $(this).val('Hide');
      });
    });
    


    Believe it or not, the highlighted line is all the jQuery code needed to hide the <div> element with id foo and class bar with a quick sliding animation. The first part of that line ('div#foo.bar') is called a selector. jQuery selectors are very similar to CSS selectors. This is one of the many qualities of jQuery: it doesn't force you to learn new, obscure syntax if you're already into web development. The $ is actually the jQuery object (yes, $ is a valid JavaScript identifier); it creates a wrapped set out of DOM elements, which you can then manipulate using the extensive API methods (in this example, the slideUp() method is shown, which accepts 2 arguments: the duration of the animation, and an optional callback). This is the basic idea of jQuery: manipulations on a wrapped set of DOM elements.

    There's also another interesting thing in jQuery: plugins. Like this one, developed by me. If you're interested in the code, I've got it on GitHub.

    I'll stop here. Anyway the world doesn't need yet another full-fledged jQuery tutorial. This article was just intended to get you interested in jQuery (and get me started writing on this blog). If you want to continue, you could start working your way through the docs, starting here. And you might want to consider learning some JavaScript too. Sad as it is, you can't use jQuery solely. For that purpose, I'd recommend this great book.

    UPDATE: Interesting fact on the popularity of JavaScript: It accounts for 19% of all code on GitHub, higher than any other language.

    ------
    If you liked this post, consider following me and Rajat on Twitter.

    Tuesday, June 7, 2011

    Base conversion in BASH

    As programmers, we often encounter numbers written in binary or hexadecimal format. Mostly it is written as the context is made easier. For example, a set of flags is better represented as binary than integer. Here's an example :-
    #define IS_TRUE        0b01     // same as 1
    #define IS_FALSE       0b00     // same as 0
    #define CONFIRM        0b10     // same as 2
    #define DOUBTFUL       0b00     // same as 0
    
    This example might not be very common, but this demonstrates the use of binary representation. These flags are useful at binary level to facilitate " bit-level AND " and various other operations.

    In such scenarios, it could get confusing as to what the number represents in integers. Many, here, would suggest creating a program in the language of your choice and using it for base conversion. So, here I explain how one can use BASH itself.

    BASH allows base conversion very easily. Fire up a terminal and try this :-
    echo $((2#1010101))
    I assume, I needn't explain $((<operation>)) is necessary for mathematical operations in BASH.  The output of the above command is 85, which is the decimal value of the number  "0b1010101".

    So here we have a simple base converter. Interestingly, the base conversion allows to convert from any base to decimal this easily  :

    <base>#<number_in_base>

    The above is sufficient to convert number given in any base to decimal value. Go ahead, try it out.

    Mail in the future

    Long time ago, I used a service for online greeting cards and I loved a particular feature; it was the feature to schedule the delivery to a future date. I am not sure if other providers had this feature or not, but they surely didn't make it easy to find; and this made me love this service above all the others. Since then I have wondered how great it would be to able to schedule mails to be delivered in the future. 

    Starting from Birthdays and Anniversaries that I couldn't risk forgetting to serious reminders to myself or others, scheduling an email in the future would be a 'desirable' service. Imagine that you are working on a project and would like to personally mail the team each week to request for their progress. Now this would require time, even if you had to send a simple "What's the progress" message each Monday. It would be cumbersome as it would demand you to take out time from the numerous other tasks that you have to do. Won't it be easier, if on one weekend, you fix 4 such mails to be sent in the future on the appropriate dates and set a reminder for yourself to fix more for later (if the project is not over by then). Such a service would save you the effort, while still getting you the response.

    Another scenario where such a service seems useful to me is sending the 'last words' of a man to his kin. Very often, certain secrets die with people. Sometimes it is because of the fear or of the want of a better moment, that words just don't come out. In such a scenario, if a person could create a mail to be sent in the future once he/she is dead, to a few chosen recipients. Some wonder, at this point, how could the service know about his/her death ? Well, before the mail is sent (on the specified date by the sender), a confirmation mail could be send to the creator of the mail, giving him some time to react (cancel or reschedule). There are many such possibilities. 

    Determined to create such a feature for myself (and use by others), I set out on a domain search. Looking for ideas, I stumbled over 'existing' services that partly fulfill the goals, here are some of them : -
    • FutureMe : This service was the first that I had seen (and brought back my childhood ideas about future mails). In terms of a friend , this is like a 'time-capsule'. 
    • FutureMail : This service fulfills the 'reminder' aspect of my discussion. It allows one to send himself reminders at any particular time in the future.
    • MyLastEmail : This service targets on the final email, mostly in case of death. Although, at the time of writing, the domain seems to have gone dead. 
    • LetterMeLater : This service combines most of the features as it allows you to send messages to both yourself and others at any time in the future. One of the attractive features about this is that you don't need to access  the site to create a new message; using this feature, you can send a mail from your own email client to 'me@lettermelater.com' with a few details on the top, and ZOOP, you have scheduled a mail in the future. 
    • HitMeLater : As the website boasts, this is like creating a 'snooze' button for yourself; more like reminders.
    While these kind of services do solve most of the things that I have in mind, some aspects can't be achieved with one service itself. This motivates me to work on one of my own service to cater my own needs (and that could be used by others as well). 

    One of the things mentioned here is note-worthy :-
    What if your (or the recipients) email address changes ? 
    I believe that this is an acceptable risk. Although, I am convinced that the service provider should facilitate change of 'recipient-address' , 'sending date' or even 'cancellation' of a scheduled mail.

    What do you think about such a service ? If I start one, what would be 'your' requirements ?
     

    Sunday, June 5, 2011

    Software projects and 'grep'

    It might sound as weird title, especially when I emphasize that by 'software project' I refer to absolutely 'any' project. After a few days of trying to understand the source code of a few projects (including Kate), I have come to realize that it is hard to understand the entire code at once.

    Realizing the impossibility of understanding the entire code-base (which could be well over a hundred thousand lines) I started trying other means. The first step was to identify the 'main' file. As I am working with C/C++, this file is easy to identify as it is the one containing the function :-
    int main (int argc, char *argv[] ) 
    Knowing what I am looking for, this simple command (or a few variations) allow me to spot the file where it all begins :-
    grep "int main" * -R 
    As should be clear, this would search the source code directory 'recursively' to find me the file with the keywords. At this point, I would like to highlight why it would be easy to maintain a program that called the 'first' function by the name 'main'. Whichever language it is written in, use of this convention can make it easier to maintain. 

    Once the main file has been spotted, I proceed to find the functions in almost a similar fashion. This saves me the effort of going through pieces of code that are rarely (or at times never) used. I can follow the 'flow of program' more easily and I know which function lies where. As and when I proceed to understand the functions, I try to make certain notes about the functions, in the form of comments. These notes could be something describing the task of the function, or could point to some other piece of information, or at times hints for improving the function later.

    'grep' has proved very useful to me, and although I am not very good with RegEx (regular expressions), I now plan to get hold of them so as to be able to use them to spot what I want in combination with 'egrep'.
     

    Saturday, June 4, 2011

    Season of KDE (SoK)

    Well, this is my first post regarding the Season of KDE 2011. On advice from the mentors, I have decided to put up my progress on the project on this blog. I realize this would be a good exercise, as over the years the single most important thing that I have learnt is that explaining difficult things to others, only makes my own understanding better.

    With that selfish motive hidden deep inside, I look forward to an exciting experience writing about my progress. Starting from the difficulties to the work-arounds, I plan to post about it all.

    Hope you enjoy reading it as much.  

    Friday, June 3, 2011

    Definying variable names using macros

    This is an interesting piece of information I came across while working on a project. Macros, provided by C, have always been something holding a lot of power. Today, I realized another powerful use of it.

    Here is the piece of code that I came across (something similar)
    #define SOME_FUNC(l,i) int l##_flag=i;
    Now this note is made for future reference. Here the most intriguing (and confusing) was the use of the two hashes '#'. I just guessed that it helps use the 'name' of the variable. For example, if I call it as

    SOME_FUNC(debug,3);
    Using the rules of macro, this would change to
    int debug_flag=3;

    Now this is useful. A small test confirmed that this is exactly what was happening. Also, using the '--save-temps' attribute of 'gcc', I confirmed what I thought it was.

    This could be very useful for debugging, as in the above example. Also, this could help us create a general function for creating flags to be created later. It is worthwhile to note that it cannot be used in an 'actual function' (that is not in the form of a macro). This is for the reason that when a function is called, the name of the variable is 'lost', and what remains is either the address or the value of the variable. Unlike function calls, macro expansion can allow the use of the name of the variable. The same could be used to make more complex functions (through the macro expansions).

    NOTE: The above information is based on my own tests. I couldn't find any information on the net for the same and thought it was worthwhile making note of it.

    Tuesday, March 8, 2011

    Hacked (victimised)!! First experience

    Today, I had my first experience as a victim of a intranet based attack. The attack was by a friend and hence nothing severe, but it came as an eye-opener. Here is what happened.



    The friend shared this image. This was being hosted from my own computer in one of the 2 folders that had access for all the users on the computer.  
    What I had missed out all this while was that my computer had a 'guest' user account made once for some work. The account had one of the most trivial passwords, 'guest123', and it wouldn't take anyone who knew the circumstances under which such an account was created to guess the password.

    Now, leaving such a door open and keeping it unchecked was probably the most foolish thing I've ever done. Here I'd like to commend my friend's skill at identifying the weak-spot and hitting it only hard enough to make me feel the pain and yet not bleed.

    But this experience does come as an eye-opener. Thanks once again, my friend.

    PS : By the way, the guest account was deleted SOON after this security bug was found and the necessary permissions (which seemed best) were allotted to the folder(s). Also, this suggests that I keep an eye on the traffic flowing through my APACHE server.

    Friday, March 4, 2011

    Bash script for Extracting text

    This is a script that I made today to solve a particular problem, but I do realise that many a times I, or anyone for that matter, would need to use something similar. For the same reason, I decided I'd share the script here.

    The script was made (as my IITG friends would understand) to extract a set of e-mail addresses from a text file that contained a lot more data. Basically, the file contained the information of each student (Roll no, name, email) in a single line with 'space' as the delimiter. Using this (space as delimiter) characteristic, I extracted the necessary information and dumped it in a file.

    while read line
    do
    line=${line##* }
    echo $line
    done

    This script was sufficient to extract the necessary information. The next task was to dump the output into another file. (if the above was saved as script.sh)

    $ cat list| bash script.sh > list

    This should have been sufficient, but in my case, I had to pass the 'list' file once again through the script.sh file to generate the desired result.

    Consequently, to create a list with commas, the following thing could be performed.


    while read line
    do string=$string,$line
    done
    string=${string#,*}
    echo $string

    This takes care of concatenating the strings with a comma in between consecutive elements.

    The above set of commands helped me create a list of over 580 e-mail addresses in less than 10 minutes (including the time taken to create the scripts), way faster than the manual method of 'copy-paste'. Note that I call it a manual method.

    I hope this tutorial sheds some light on the use and power of simple bash scripts to solve everyday problems and save a lot of time. Do revert in case of any doubts or confusions through comments.

    exit(0)    // End of post