pjain's blog

Use Your (Yourls) Own URL Shortening Service with Perl

URL Shortening services like Bit.ly have been all the rage with the popularity of Twitter and other micro-blogging services. As some of us use Twitter quite a bit for sharing links to various sites and blog posts, we're sending lots of traffic to people that isn't easily identifiable beyond the URL shortening service being used.

Bit.ly does a great job of providing statistics on the URLs that you're sharing. However, it doesn't allow the receiver of the traffic to easily know anything about who you are or your brand. I felt if I was providing enough traffic to a publisher, it would make sense to use my own URL shortener so the publisher could easily get more information about me.

I dug around and found quite a few open source shorteners. I eventually decided to use Yourls for a few reasons:

  1. It's open source
  2. It's written in PHP and can be deployed easily, even on shared hosting services
  3. The developer of Yourls, Richard Ozh is really quick about fixing bugs and implementing new features.
  4. The feature list may not be as complete as Bit.ly but it comes really close.
  5. Setting up Yourls was a breeze, now came the fun part of doing something with it beyond the bookmarklet. I decided that I would convert all my shared Google Reader items to use Yourls. To do this, I created WWW::Shorten::Yourls which I had introduced in this post.

    Below is a small Perl script which uses the WWW::Shorten::Yourls module to give you a shortened URL for use on Twitter, FaceBook, LinkedIn, email, whatever.

Personal Finance for Barcampers at BarCamp Delhi

Sunday, October 25th was another installment of BarCamp Delhi. The turnout was intimate and the location, IMI (International Management Institute) was a much better place than the last two BarCamps at IIT Delhi and MDI - Gurgaon. It was also refreshing to see quite a few new faces this time around.

The bulk of the attendees were students with a few entrepreneurs showing off their products and services as well as others sharing information about things ranging from web standards to how to startup. I decided to do a presentation on personal finance and getting people to think about investing. Out of roughly 25 people in the audience, 4 or 5 people said they actually track their monthly finances. 6 people said they actually invest. The bulk of people there weren't managing their money and also, were not investing in anything beyond a bank account.

Below is the presentation I gave, urging people to get a handle on their income and expenses, track them, and start developing a plan for saving some percentage of their monthly income and then investing it. I gave a quick example of investing in stocks vs. mutual funds and the difference in returns based on an assumption of an 8% annualized return over 10, 20, and 30 years. I'm not advocating one investment over an other, I'm instead telling do-it-yourselfers how they can compare stocks vs. mutual funds and how those that prefer to run on auto-pilot could expect their returns to look like.

All values and fees are in Indian Rupees and fees are calculated based on prevailing rates in India.

You can view or download the presentation directly on slideshare as well.

I'd love to hear your thoughts.

Perl Module for use with Yourls Released

I wanted to put an image of the Perl Camel up on this post but it would have required getting permission from O'Reilly to do so. Hence, I decided to use this beautiful picture by angeloux.

I just got around to finishing the alpha version of WWW::Shorten::Yourls which is a simple Perl module to shorten URLs using the open source Yourls.org project.

You can take a look at the code at GitHub or install the code using CPAN.

The Top 10 Myths and Misconceptions of Long-Term Capital Management (LTCM) by Eric Rosenfeld

Eric Rosenfeld, one of the founders of Long-Term Capital Management (LTCM), gave this presentation at MIT back in February. If you have even a remote interest in finance (and even if you don't), this is an hour and a half very well spent. Eric is brilliant and fun to listen to.

Semblr Private Beta Is Open

Semblr - Start Assembling Your Team

It's been a long road, oft-delayed, but we've officially started our private beta of Semblr today. The basic premise around Semblr is simple. It's an online marketplace where you can assemble your team of experts using a reverse auction process. It's a market where people that are looking for work can connect with people that need to get work done by bidding for the work. In this kind of economic climate there are more and more experts around the world that are available to help with projects that previously they had no time for. We want to make Semblr the go-to destination for experts and those looking for those experts.

If you have an expertise in Programming, Writing, Video (online and offline) and various other topics, come on over to Semblr and sign up for our free private beta. If you're someone who is looking for an expert to help you get something done, come on over and sign up.

We're just getting started so the marketplace is a bit small and we're launching with a limited number of job categories but we expect to grow the list over time to encompass all kinds of personal outsourcing categories. We will also be inviting new users almost daily to join our marketplace.

We look forward to all your feedback and we'll do everything we can to make the Semblr marketplace a profitable place for you. BTW, if you have suggestions on categories that you'd like to see added to Semblr, please let us know thru the contact form or via Twitter (don't forget to follow us on Twitter so you can get to see the latest auctions.

Twitter Opens up OAuth, Where's Perl?

Twitter opened up their OAuth implementation last week. It's a much welcome aspect of working with Twitter's API since we're planning on implementing some functionality into Semblr that uses Twitter. Hence, understanding OAuth and prototyping it's use was important for us.

My problem with Twitter's implementation is that the documentation is sparse and there isn't a single example in Perl or Java. Maybe these two languages aren't cool enough to warrant examples but to me, they're important because they're all I know. I spent some time over the last few days trying to implement OAuth for Twitter in my Perl scripts. The example below is a bit messy but it works.

It will create a few temp files, request a token for you, ask you to go to the URL printed to authorize the application. When you've authorized the application, run the script again and it will allow you to submit a status update.

#! /usr/local/bin/perl
# $Author: pankaj $
# $Date: 2009-03-22 23:46:27 +0530 (Sun, 22 Mar 2009) $
# Author: Pankaj Jain
# Copyright: Teknatus Solutions LLC
################################################################################################################################
use Modern::Perl;
use Carp;
use Net::OAuth;
use Data::Random qw(rand_chars);
use LWP::UserAgent;
use Data::Dumper;
use JSON::Any;

main();

sub main{
    my $ua = LWP::UserAgent->new;

    my $consumer_key = 'sdBwlvTkpZr7eiCmB0Evig';
    my $consumer_secret = 'asSINZmwnxwIfLwmdNvVBW7OSVzFOWj4mjJeDDaA';
    my %tokens = getTokens();

    requestToken(consumer_key => $consumer_key,
                 consumer_secret => $consumer_secret,
                 %tokens,
                 ua => $ua);

    my $message = "This is a Perl Net::OAuth test for twitter!";
    my $foo = {status => $message};
    my $url = 'https://twitter.com/statuses/update.json';
    if (defined $message && $message ne "") {
        my $request = Net::OAuth->request("protected resource")->new(
            consumer_key => $consumer_key,
            consumer_secret => $consumer_secret,
            request_url => $url,
            request_method => 'POST',
            signature_method => 'HMAC-SHA1',
            timestamp => time,
            nonce => join('', rand_chars(size=>16, set=>'alphanumeric')),
            token => $tokens{token},
            token_secret => $tokens{secret},
            extra_params => $foo,
        );
        $request->sign;
        say Dumper($request);
        my $response = $ua->post($request->to_url);
        say Dumper($response);
        my $response_code    = $response->code;
        my $response_message = $response->message;
        my $response_error   = $response->content;
        if ($response->is_success) {
            my $retval = eval { JSON::Any->jsonToObj( $response->content ) };
            if ( !defined $retval ) {
                say "TWITTER RETURNED SUCCESS BUT PARSING OF THE RESPONSE FAILED - " . $response->content;
            }
        } else {
            say $response_code;
        }
        exit;
    }
}


sub requestToken {
    my %args = @_;
    if (defined $args{consumer_key} && defined $args{consumer_secret} && 
            !defined $args{access_token} && !defined $args{access_secret} && 
            !defined $args{token} && !defined $args{token_secret}) {
        my $token;
        my $secret;
        my $request = Net::OAuth->request("consumer")->new(
            consumer_key => $args{consumer_key},
            consumer_secret => $args{consumer_secret},
            request_url => 'https://twitter.com/oauth/request_token',
            request_method => 'GET',
            signature_method => 'HMAC-SHA1',
            timestamp => time,
            nonce => join('', rand_chars(size=>16, set=>'alphanumeric'))
        );
        $request->sign;
        my $res = $args{ua}->get($request->to_url); # Post message to the Service Provider
        if ($res->is_success) {
            my $response = Net::OAuth->response('request token')->from_post_body($res->content);
            print "Got Request Token ", $response->token, "\n";
            $token = $response->token;
            print "Got Request Token Secret ", $response->token_secret, "\n";
            $secret = $response->token_secret;
            if (defined $token) {
                my $auth_url = "https://twitter.com/oauth/authorize?oauth_token=" . $token;
                my $message = "Please visit $auth_url and authorize this application to access your twitter account.  You may revoke access at any time you wish.\n";
                say $message . "\n";
                open(TMP,">/tmp/request_token.txt");
                say TMP $token . "|" . $secret;
                close TMP;
                exit;
            }
        } else {
            die "Something went wrong";
        }
    } elsif (defined $args{access_token} && defined $args{access_secret} && 
            defined $args{consumer_key} && defined $args{consumer_secret} && 
            !defined $args{token} && !defined $args{token_secret}) {
        my $auth_req = Net::OAuth->request("access token")->new(
            consumer_key => $args{consumer_key},
            consumer_secret => $args{consumer_secret},
            token => $args{access_token},
            token_secret => $args{access_secret},
            request_url => 'http://twitter.com/oauth/access_token',
            request_method => 'POST',
            signature_method => 'HMAC-SHA1',
            timestamp => time,
            nonce => join('', rand_chars(size=>16, set=>'alphanumeric'))
        );
        $auth_req->sign();
        my $res2 = $args{ua}->post($auth_req->to_url); # Post message to the Service Provider
        if (!$res2->is_success) {
            die 'Could not get an Access Token: ' . $res2->status_line . ' ' . $res2->content;
        } else {
            open(TF, ">$ENV{HOME}/.teknatus/.twitter_token");
            my $response = Net::OAuth->response('access token')->from_post_body($res2->content);
            print STDERR "Got Access Token ", $response->token, "\n";
            my $access_tok = $response->token;
            print STDERR "Got Access Token Secret ", $response->token_secret, "\n";
            my $access_secret = $response->token_secret;
            say TF $access_tok . "|" .$access_secret;
            close TF;
            unlink("/tmp/request_token.txt") if (-e "/tmp/request_token.txt");
        }
        exit;
    }
}

sub getTokens {
    my %args = @_;
    my %tokens;
    my $tokenFile = $ENV{HOME} ."/.teknatus/.twitter_token";
    my $reqTokenFile = "/tmp/request_token.txt";
    if (-e $tokenFile ) {
        open (TF, "<$tokenFile");
        while() {
            chop($_);
            next if ( $_ =~ /^\s?$/);
            my @tmp = split(/\|/, $_);
            $tokens{token} = $tmp[0];
            $tokens{secret} = $tmp[1];
        }
        close TF;
    }
    if (-e $reqTokenFile) {
        open (TF, "<$reqTokenFile");
        while() {
            chop($_);
            next if ( $_ =~ /^\s?$/);
            my @tmp = split(/\|/, $_);
            $tokens{access_token} = $tmp[0];
            $tokens{access_secret} = $tmp[1];

        }
        close TF;
    }
    return %tokens;
}

1;

2008 Reflections and 2009 Plans

Happy 2009 everyone!

2008 has been a very interesting year by all measures. We saw record drops in global stock market indices - 34% drop for the Dow, the worst since 1931. We saw vast amounts of wealth obliterated. We saw the US moving closer and closer to a socialist economy. We saw the election of the first African-American to the office of the President of the United States. We saw another round of incredibly well planned terrorist attacks across India, culminating in the sixty hour standoff in Mumbai. We saw Indians get up and rebuild quickly from the attacks. We saw a new sense of urgency in the fight against terror by the Indian middle class. And we have seen India and Pakistan, once again, come to the brink of war.

Obviously, we've seen a number of other things that I've missed but these are some of the events that will always remind me of 2008. 2008 is also the year we got Teknatus Solutions Private Limited up and running in India. We did a soft launch of our Bridal network, Brides' View and we're getting ready for a private beta of our next product - Semblr. It's been an interesting and tough year all around. We've seen an incredible amount of interest generating around the Indian startup scene, both with prospective employees and also with the media. Plenty of folks have done a great job in catering to this interest. We've had Proto, Head Start, Startup Saturday and also BarCamps across all major Indian cities to help get startups some visibility and to help those interested in learning/joining/startip a business. With the economic downturn, a good deal of media attention is turning to startups and venture funding. The amount of Indian startups has been increasing steadily and now, with many people getting laid off, the numbers should increase even more. As far as VC/angel funding, well, the picture in India and globally isn't as rosey as it was six months ago. However, there are still quite a bit of deals closing.

For Teknatus, 2009 is going to be an interesting and challenging year. Our major goal for the year will be to launch a few additional products and start generating revenue. It won't be easy but I feel confident that the product we're getting ready for soft launch will be generating revenue by the end of the second quarter of 2009 and by then, we are planning to launch our third product which will be a SaaS product geared toward SMEs. Our next major goal is going to be working on building the team out. We're going to have positions opening up for various roles over the coming months and, hopefully, we'll be able to fill them with some great people.

In 2009, we also plan to continue working on helping the entrepreneurial ecosystem in India, specifically New Delhi. We've found platforms like Startup Saturday to be wonderful areas to connect with like-minded individuals. Hiring and building a team in India is difficult but it's not insurmountable.

Once again, happy 2009!

The Financial Ninja and "Greenspan Sees market Rebound"

Here's a great post over at the Financial Ninja's Blog about how Greenspan sees the market rebounding in six to twelve months. I couldn't agree with the Financial Ninja more when he says, "I too believe we'll bounce significantly... but only to dive into abyss after."

Don't Believe the Market Hype!

Intro
As all of you who've been keeping up-to-date on the happenings in the financial markets know, there's been a good deal of turmoil and volatility continuing. GM and Chrysler, in the US, are begging for bailouts, small, medium, large and extra large companies are laying off people in droves (Citigroup will be laying off 53,000 people). Things are pretty bad in the US right now. We all know that, we all hear about it, and the US stock market shows us daily.

What about India? Well, if you ask the Prime Minister, the Finance Minister, various financial "analysts" on TV, etc. they will tell you that India is very well insulated and the India growth story continues, with a few minor speed bumps along the way. My personal opinion is that the politicians and media are generally telling us what we want to hear. They're not accurately portraying the severity of the situation in India. The situation is about to get worse in India but, barring any further catastrophic meltdowns, India should see some incredible growth post 2011.

Relative GDP Growth
Let's look at India's economy on a relative basis. Relative to the US and other developed, highly deregulated economies, India's still got a growth story, whereas, the US, the UK, Japan, etc. are all in a recession (negative growth). The talking heads in India tell us that India is still on track for 6.5% to 7% GDP growth in 2009. Assuming that is true and exactly what will happen, it's huge number (in aggregate terms) compared to other developed and many developing countries! However, India still has roughly 450 million people at or below the poverty line. This is one and a half times the population of the whole US. In order for India to decrease the number of poor and continue to provide for the basic necessities of the economically disenfranchised and cater to the increasing consumption of the middle and upper classes, growth needs to accelerate, considerably. GDP growth in India MUST be at least 10% if India is to continue to grow, relative to other economies. In my opinion, 7% GDP growth is akin to a recession in a developed economy. How can India grow at more than 7% in 2009? It's a complicated question that the smartest economists from Harvard, Oxford, LSE, etc. are trying to answer. I won't be pretentious enough to suggest that I know the answer. However, I will say that whatever the answer is, it's very complicated and it will most likely make a vast amount of people very unhappy. Hence, it won't be politically viable, especially, in an election year.

Layoffs
On the 20th of November, there was a nice little piece on Livemint that quoted Cabinet Secretary KM Chandrashekhar, "Most of our productions are based on domestic demand. As long as domestic demand remains reasonably strong, I don't think there would be any large-scale job cuts in India," he said. Domestic demand for many goods and services is growing but is it growing enough to keep up with supply?

The article also went on to describe how Jet Airways was "asked", by the government, to take back all of the 1,900 employees that they had laid off in October 2008. As a business, Jet Airways has every right to hire and fire the people they need to in order to stay competitive, and profitable. However, the Indian government, must also do what they can to avoid mass layoffs across large, high profile, Indian companies. Mass layoffs across Indian industry will have a devastating affect on the economy. However, how many additional companies can the Indian government "ask" NOT to layoff people before companies start feeling intense pain?

Smaller companies are laying people off and some are even shutting Indian offices. Zapak, a mobile games company, recently announced that they would be shutting their Bangalore office. In the Business Section of the Hindustan Times (Saturday, November 22, 2008 Edition), HSBC is predicted to layoff approximately 200 employees across India. Dell has decided to scale back their hiring of new employees. These are just large companies.

About ten days ago, I had spoken to an executive at a premium tissue maker in India. They said sales have fallen dramatically. People have switched from using premium tissues and toilet paper to non-premium essentials. If the current sales numbers continue, not drop, they will probably have to layoff some people.

When I told a family business exporter of garments that he must be happy since the USD has climbed dramatically against the INR, he told me that he's more scared then ever. He told me that orders are being cut by his clients, some of them have begun renegotiating contracts to pay in INR rather than USD because they feel that the Rupee can only depreciate against the US Dollar. I'm not quite in agreement in that statement but it highlights a very important fact - sales are down globally, not just in the West.

Real-Estate
The real-estate sector in India has slowed. There's no questioning that statement even if developers/builders in your neighborhood are still jacking up rates. They generally see the downturn but don't want to make a loss on their investment. Just wait it out and eventually, they will cave in. How can I say that, well, it's simple. They made some profits from other deals. Those profits allowed them to get funding from a bank. They have a mortgage to pay and at some point, probably six months, they will feel the excruciating burden of carrying the property and will realize that they have no choice but to cut their losses and run.

Investments in second and third tier cities have dropped dramatically. Indian and foreign investment firms are finally stating the obvious, "The Indian Real Estate market is slowing". Many projects from large RE developers like DLF and Unitech have been put on hold indefinitely. Indiabulls sees a 15% correction in the real-estate market over the next six months. I'd put the number a bit higher, closer to a national average of 25%. Marriott recently decided to shelve building a 250 room hotel in Pune, by at least two years.

For now, gone are the days when your driver or plumber is quitting his job to become a real-estate broker or a handyman is quitting his job to become a real-estate developer/builder.

Stocks
The BSE Sensex is at a three year low. Confidence is shaky at best. Corporate earnings look ok (on a relative basis) but earnings growth appears to worrying investors. Most companies are no longer expecting 20% or 30% growth rates for 2009. Info Edge (Naukri.com) has said that they see fiscal Q209 revenues to be half of fiscal Q208. Earnings growth is slowing. The question to ask is, "Is the rate of deceleration increasing?".

The BSE has failed to rally after two very big days of gains for the Dow. People in India are still bullish on the market and the Indian growth story so why hasn't the BSE soared like the Dow did on November 21st and November24th? There's still too much uncertainty and the Indian stock market is telling us that cautious optimism is warranted.

Currency
The Rupee is at an all time low against the US Dollar (though a one week high, as of November 25th, 2008). There are a great deal of challenges that India faces in the next two years - much like the whole world. I look at the Rupee relative to the US Dollar and I think that they INR should settle somewhere around INR 49 per USD by the second half of 2009. The US also faces great challenges but the Indian scenario is quite a bit more precarious in many ways. GDP deceleration, inflation (currently at 8.56%), rising import costs, FX reserves are much too low for comfort. Morgan Stanley expects the Rupee to depreciate to 57 before it appreciates. They may be right but the USD is going to be under a great amount of strain considering how much additional debt is going to hit US tax payers in the pockets.

It's hard to say what will happen. All we know is that many many things can change, very drastically, fairly quickly. I believe the next two years are going to be very difficult, globally, and we should be prepared for it - financially and psychologically.

Startup Saturday Volunteer Meetup

For anyone interested in volunteering for Startup Saturday Delhi, we're meeting today, November 22nd, 2008 at 3pm at the Teknatus office in NSIC. If you're interested in joining us, please drop me a note.

Syndicate content