Seeking recommendation for some Fantasy/Sci-Fi/Fiction books

It’s been quite sometime since I read anything substantial and so I am planning to take a “reading break” and want to dedicate my free time in the next couple of months for reading.

Since I have a couple of months for this, I don’t want to read short stories or a single novel. Instead, I want to read a series so that once the characters are introduced, they will continue to be present for most of the series. This will be an important factor for me, since it motivates me to complete all the books in the series. This is one of the reason, why I was able to complete the entire Sherlock Holmes series in less than a week :)

I am not very particular about the genre very much, but I would prefer either Fantasy or Sci-Fi. The series that immediately came to my mind were Harry Potter and The Lord of the Rings. I posted about it today morning in Twitter and asked for recommendations.

Within a few minutes, I got the following good suggestions and now I have the tough job of picking it up from here ;)

I have not made up my mind yet, but I am leaning towards Foundation series by Isaac Asimov.

Meanwhile, if you guys have any more suggestions, kindly do let me know.

Update: I have decided to take up Foundation Series by Isaac Asimov first. Thanks everyone for the recommendations.

Posted in Books | Tagged , | 6 Comments

Including external Pig files into Pig Latin scripts

In one of my projects, we had huge number of Pig scripts which dealt with data from a single source. The schema for this common data source is quite complex and changes every few months. Since this schema was present in all Pig files, when ever it changes, it was a real pain to update all Pig scripts.

I was looking for a way to separate out the schema into a separate Pig file and then include it in all other Pig scripts, like how you import a class in Java, instead of copy pasting it into all Pig files.

After some quick web searches, I found that from Pig 0.9 and above this feature is indeed available in Pig itself. It’s called macros. All you need to do is to just include the following line in your Pig script where you need it to be included.

import 'other-file.pig'

You can either give relative path in the above line or set the search path as well from where Pig should include the scripts. If you want to include the search path, then you can do something like this.

set pig.import.search.path '/usr/local/pig,/grid/pig';
import 'external-file.pig';

Now my Pig scripts are organized properly. Hope this helps you as well :)

Posted in Hadoop/Pig | Tagged , , | Leave a comment

Parsing JSON in Pig UDF written in Python

When I wrote about using Python to write UDF functions for Pig, I mentioned that Pig would internally be using Jython to parse the code, but 99% of time this shouldn’t be an issue. But I hit the other 1% recently :)

I had a small piece of Python code that used the built-in json module to parse JSON data. I converted that into a UDF function and when I tried to call it from Pig, I was getting “module not found” exception. After some quick checks, I found that the latest stable version of Jython is 2.5.x and json module was added from 2.6

After some web searches, I came across jyson through a blog post about using JSON in Jython. jyson is an Java implementation of JSON codec for Jython 2.5 which can be used as a drop-in replacement for Python’s built-in json module.

I downloaded jyson jar and then added it to Pig’s Dpig.additional.jars property. In the Python code, I changed the import statement to import com.xhaus.jyson.JysonCodec as json. After that everything started to work again :)

Posted in Hadoop/Pig | Tagged , , , , | 1 Comment

Install OpenCV in Mac using Homebrew

Recently, I switched to a new Mac Retina (one of the numerous perks of working at Yahoo ;) ) and wanted to install OpenCV in it using Homebrew.

I ran the usual brew install opencv command and got No available formula for opencv error message. I have personally ran this command before to install OpenCV and was wondering what went wrong.

After a couple of web searches and ‘hair tearing’, I found that the opencv formula has moved to homebrew-science and I had to do the following.

brew tap homebrew/science

brew install opencv

Finally everything worked. So even if you are facing the same problem, then you know what to do now (and possibly save some hair as well) :)

Oh, by the way, if you own a Mac and don’t know what Homebrew is, then stop everything and install it right away. You can thank me later ;)

Posted in iPod/Apple | Tagged , , , | Leave a comment

Writing Pig UDF functions using Python

Recently I was working with Pig (the apache one, not the animal ;) ) and needed to implement a complex logic. Instead of struggling to write it in Pig, I decided to write a UDF (User defined Function). Also, I was too lazy to copy paste lot of boilerplate code to write the UDF in Java and decided to write it in Python. Long time readers might know that ever since I learned Python (around 7 years ago), I have been a huge fan.

In the end, I found that it was too easy to write UDF’s using Python, when compared with writing them in Java. I thought of writing about it here so that it would be helpful and will act as a starting point for people who also want to write their own UDF using Python.

Python vs Jython

Well, before we start, one thing that we have to keep in mind is that, even though we would be writing our code in Python, Pig will internally execute the code using Jython. 99% of time there will not be any difference, but it is good to keep that in mind.

Python code

First in the python side all we need to do to expose a Python function as a UDF, is to just specify a decorator to it.

Let’s say we have the following Python function that returns the length of the argument that is passed to it.

All we need to expose this function as a UDF is to add the @outputSchema decorator. So the code becomes

When data is passed from Pig to Python, it is passed as bytearray. Most of the time, this shouldn’t be a problem. But there are times when this could be a problem. In those cases, we can just convert it into proper string before we consume it. So the final code would look like this

Pig code

In the Pig side, we should do two things.

  • Register the UDF
  • Call the UDF ;)

Register the UDF

As I said in the beginning, Pig internally will use Jython to parse Python code. So we first need to register our Python file using the REGISTER statement. We can just say REGISTER 'udf.py' USING jython as pyudf

Call UDF

Once we register the UDF using the REGISTER statement, we can then call the UDF function using the alias that we created.

Here is the complete code in the Pig side.

And believe me, that’s all you need to do to write Pig UDF functions using Python. No more unneeded Java classes, boilerplate code or Jar creation process :)

Posted in Hadoop/Pig | Tagged , , | 1 Comment

Hack 101 at IIT Kanpur for HackU

I am currently in IIT – Kanpur to conduct Yahoo! HackU (Hackday for University), as I am part of the Tech crew that is conducting the event. This is similar to my previous HackU events.

During the event, I gave a talk titled “Hack 101″, which basically explains what is an hack, what is HackU and how to participate etc.

Slides

You can view the slide that I used for my talk in my slideshare account. While you are at it, you can also checkout some of my other talks.

I have also embedded it below for easy reference.

Posted in Events/Camps | Tagged , , , | Leave a comment

Make your hack standout using PureCSS

I am currently in Hyderabad, attending Yahoo’s 6th Open hackday and I just finished my talk titled “Make your hack standout using PureCSS”.

PureCSS

PureCSS is a set of small, responsive CSS modules that you can use in every web project and is one of the latest offering from Yahoo.

Do check it out, it is really awesome :)

Slides

You can download the slides from my slideshare account or you can view it below. Do checkout slides from my other talks as well.

Workshop

I am also doing a PureCSS workshop later in the evening and if you are right now in open hackday make sure you attend it as well :)

Posted in Events/Camps | Tagged , , | Leave a comment

Rollback a commit in git, while maintaining history

I use git for pretty much all my projects these days. When ever I do a commit, I make sure that it is atomic and has a proper commit message. One of the main reason why I keep the commits atomic is that, I can rollback the commit if needed.

Recently, I faced a situation, where in one of my projects, the feature I added a couple of commits back wasn’t working properly and I decided to completely get rid of it. Since I follow semantic versioning, I wanted to make sure that I maintain the different release of my project properly.

After a bit of digging up, I found the exact command in git to do that. Since the command was not that intuitive I thought of documenting it here, so that I know where to lookup when I face the situation again ;)

Problem

Let me explain problem properly. Let’s assume that I have the following list of commits in my history.

A -> B -> C -> D -> E

The head is at E now. The feature that I was talking about was introduced in commit C. Now I want to rollback the changes that I did in commit C, after E, but still maintain the history. In short I want the commits to look like

A -> B -> C -> D -> E -> C'

where C' is the opposite of C

Solution

I could have manually removed that changes I did in commit C. But being a fan of fancy one-liners, I was looking for a solution and found that there is a command in git which can do this for you.

All you need to do is to execute the following command.

git revert 'SHA_of_C'

It’s really fascinating to see, how the developers of git have thought of these different cases :)

Posted in Unix/Server Stuff | Tagged , | Leave a comment

Sum up all values of a column in a text file

Recently, I had to sum up all integers of a column in a text file (similar to how you do in excel). After some digging up, I came up with a awk one liner to do it.

Following my tradition of documenting one liners, I am going to document this one as well :)

Input and output data

Here is the super simplified version of input data that I was using.