Just 5 bash shortcuts

Saw a good blog post on bash short cuts. I won't remember all of them for sure. So, going to get used to just 5 of these.

Fire up a bash/zsh whatever your favorite shell is and try these.

Ctrl + k => Delete from cursor to end of line

Ctrl + u => Delete from cursor to beginning of line

Ctrl + b => Move the cursor back one character

Ctrl + f => Move the cursor forward one character

Ctrl + t => swap the character under the cursor and the previous one

 

I just did the above a bunch of times. Pretty sure it has gone into my long term memory now :)

 

Have a good weekend,
Mahesh

css frameworks

For my new project, I was looking for a good css layout to use. I have never been comfortable pulling an entire theme I found online into my project. I find it too messy because I wouldn't know what is going on in those styles and layouts for the most part and I would leave most of it unused. What I used to do is extract some layouts, styles etc. from the theme I like and build on that idea.

Last week twitter released there collection of css and js which can be easily used as a framework for your site's design. You can check out their blog post here and the code is here. I was looking into it and through hackernews I found some other similar frameworks like skeleton, blueprint, boilerplate, gridless, 960.js and so on. I ended up going with skeleton because it looked simple, lightweight and easy to use.

After tinkering with it for few days now, I think any one like me who is not good at these UI things and pretty much hates doing it but have no other option should definitely give it a shot.

That's it for now. Back to my floats, styles, and clearfix!

 

Cheers,

Mahesh Murthy

jquery - Part 3

I am continuing with my jquery book after a 3 week break. I was in Boston for 2 weekends and last weekend was busy moving into my new apartment (continuing to be a nomad in chicago).

Chapter 2 was all about different ways of selecting dom elements and such. Chapter 3 is about selecting and filtering and manipulating dom elements. The blog post on Chapter 2 turned out to be really shabby with horrible formatting and not very clear content. So, trying to make amends this time. Let's see how it goes.

Problem: Given the below html, how do you extract the urls from it?

Solution: Enter jquery method each(). So, you would do

It is pretty self explanatory. You pass in a callback function to each method which is applied to each element of the selected array of anchor elements.

Problem: Now from the above html, what if you wanted to select the 3rd link and apply some highlighting to it?

Solution: You would use the eq(index) method to do that.

Next, do you know what this is doing?

$("div")[0].innerHTML?

It should be easy to guess, you are basically getting all the div elements and selecting the first one's html content. Remember when you do $("div"), it returns a jquery object but innerHTML is applied to a raw dom object. It is [] which converts jquery object into a raw dom object.

Now, let's say you have a list of dom elements and you want to just extract a subset of the list based on some condition. You can eithe loop through the array and do an if check and select the element or just use the map function like this.

slice: If you are from the ruby world, you will probably know the slice method on an array. However, the functionality of jquery slice method is completely different. It basically performs a specified operation on a subset of elements. For example:

$("p").slice(1,3).wrap("<i></i>")

 

That was a quick and easy chapter I must say. It helps to have those simple chapters when you are coming back from a 3 week break :P Hope you got something out of the post today (assuming you made it all the way to here)! I will be back next weekend with Chapter 4.

 

Namaskar!

Mahesh Murthy

 

 

Part 2 - India

Continuing where I last left off in the previous post, I finished reading the section about India yesterday. Unlike what I wrote towards the end of my last post, the author does seem positive about things in India. Of course, the book is about scrappy entrepreuners and how they are building companies amidst third world challenges. So, how can she be so negative right? The things which she dislikes about India are not anything new. It is the same old corruption, pollution, traffic, terrible infrastructure and so on. Things are definitely getting better from my point of view and that's what she writes in the book based on interviews with various people.

Amidst hundreds of copycat startups in India (copycat startups are those which basically pop up right after a company in Silicon Valley is mentioned on say Techcrunch. It is fascinating how little time it takes them to put up application which is exact replica of those silicon valley startups), she talks about few companies which are making a real difference, which are solving India's problems. Funny how all of those she talks about revolve around SMS (btw, I work for a company whose core product is SMS marketing. Signal FTW!). 

One of them is RedBus which I had heard when I was in India. It is a service you use to book bus tickets in India. It is hugely popular I hear.

Another one I personally used when I was in India was JustDial. Unlike US where you can just google or yelp for restaurants, bars or whatever, it is not easy to find anything online. That's where JustDial comes in. You want a plumber, call them. You want the address to some restaurant, want some recommendation, just dial. They are basically the human search engine. Eventually they will become less important as online presence of services improve but they are doing a great job right now.

Eko India Financial Services is another one she talks about. I have never used this but I had heard this concept in Economist a while ago. This is basically a service you use to transfer money between people through SMS. So, if I have to pay you Rs.1000, I just text a registered pin and the amount and your phone number and you will be credited that amount. And guess where you can go get your money? Nop, not any banks. It is in that store on the corner of the street! Lot of people in India can't open a bank account because them don't meet the eligibility requirements (I have no idea about the requirements). So, this is how money changes hands. The technology is not all that complex but I think this is brilliant.

The one other interesting I thought was this company VNL which puts up solar powered towers in remote villages to give them cell phone connectivity. Solar is the key here because there is hardly power in those places. What a fantastic way to connect them to the rest of the country.

It is no secret that 2 things India has got it right so far is mobile infrastructure (it is so cheap and easy compared to all the developed countries I have traveled to atleast) and the information technology (Outsourcing). According to her, product companies are slowly starting and is a good sign. Overall, I think she has done a great job of covering India.

I just finished reading the entire book, next were Brazil, Indonesia, Rwanda. It is interesting to how things and issues are so different among different developing countries. To some it up, it was a good read.

Brilliant, Crazy, Cocky

I am reading this book called Brilliant, Crazy, Cocky ... by Sarah Lacy of Techcrunch for the past couple days. It's a great read if you are interested in knowing about the economy of developing countries, how the entrepreneurs there think and act and how they are different from developed countries (mainly USA and silicon valley in particular), the history and evolution of the technological companies there.

I just finished reading the chapters on Israel and China. I didn't know much about Israel's tech scene, so it was kind of good. The chapter on China was really surprising. From outside, you would think of China as this communist country where people don't have any freedom and all the tech companies out there are pure copycats of Silicon Valley. From what I read, there are lot more companies who are solving China's problem. Another thing which was interesting to know is Entrepreuners there are going after more customers, more users (basically landgrab) vs quality and differentiation. One thing which helps is to have good infrastructure and China has and is continuing to build it. If you want to know how things work in China from inside, this book is a good read.

I just started reading the chapter about India and I can already sense the author not too happy with things there. I am looking forward to reading the rest because I am from India and pretty sure I can relate to some things and completely disagree with lot of her viewpoints. Will keep you posted!

 

Mahesh Murthy

Code Retreat

I was at an Obtiva sponsored code retreat today (Thanks John for letting me know about it). It is basically a day long event where you are given a problem and you implement a solution in any language. You do it by pairing with other programmers. Each session lasts 45 minutes after which you discard the code and restart again by pairing with another programmer. So, you are implementing a solution over and over again but with different programmers and in different languages. It really was a fantastic experience. We worked on implementing Conway's Game of Life. You can read more about Code Retreat here. If you come across anything like it, I highly encourage you to attend it.

One of the big things I learned was TDD is not as hard/annoying as I thought it is. I always lose patience and just implement my code and then write tests for it. But really once you put in a little extra effort and switch to TDD mode, you will gain a lot out of it. I am by no means saying I am a hard core TDD guy now and I don't want to be one of those. In some cases, you just have to ditch it and go do your own thing. But for lot of cases, it really helps you design your system better and build a better, stable, easily testable, maintable piece of software.

That was the lesson of the day.

Cheers,
Mahesh

Selecting Elements

[Update: All the html and formatting turned into a total cluster fuck once I saved it. I am too lazy to fix it now. I will figure this out for next week :P]

Last week I started learning jQuery and had decided to do one chapter a week. So, here is the second installment. This week is all about selecting elements in the dom. Last week I just read through the entire chapter and then started blogging and it didn't really turn out great. This week I am writing as I read. We'll see how this goes. The pattern for this post is going to be in the form of a series of Problems and Solutions. You can test your jquery skills by coming up with a solution without looking at the answer. So, here we go.

Problem: 

Category

<ul id="nav">

<li>Anchor 1</li>

<li>Anchor 2</li>

<li><span>Anchor 3</span></li>

 </ul>

 

Given this html, select the anchor elements within each list item.

Solution: jQuery('#nav li > a')

 

Problem: 

<div id="content">

<h1>Main title</h1>

<h2>Section title</h2>

<p>Some content...</p>

<h2>Section title</h2>

<p>More content...</p>

</div>


Given the above html, select all h2 which come right after h1.


Solution: jQuery('h1 + h2') - I have to say this is non intuitive.

 

Problem: 

 

<ol>

<li>First item</li>

<li>Second item</li>

<li>Third item</li>

<li>Fourth item</li>

</ol>

From above, select the 3rd <li>. Bonus, select <li> at even indices. 

 

Solution: jQuery('ol li:first')

Bonus: jQuery('ol li:even')

 

Problem:

<li>

    <input type="text" />

    <input type="password" />

    <input type="button">Enter</input>

    <input type="text" />

 

</li>

 

Select elements of type "text"

Solution: jQuery(':text')

Those were very basic ways in which you can select elements in a dom. Once things get complicated, the best thing to use is the filter method.

Ex:

 

  <li style="width:100px">First item</li>

  <li style="width:200px">Second item</li>

  <li style="width:300px">Third item</li>

  <li style="width:400px">Fourth item</li>

 

 

 

Let's say you want to select li whose width is between 150 and 350. Here is what you would do:

jQuery('li').filter(function() {

width = jQuery(this).width();

return width > 150 && width < 350;

});

filter basically applies the function to every element returned by the selector (in this case jQuery('div)) and returns a new list whose elements match the function.

Now, let's say you want to use this in multiple places. There is a slick way to create a new custom filter that selects div with the width between 150 and 350 and use it wherever you want. So, to do that,

jQuery.expr[':'].customWidth = function(elem, index, match) {

 

width = jQuery(elem).width();

return width > 150 && width < 350;

 

};

Now, once you have defined that, you can use it like you use inbuilt filters like :text, :radio etc.

So,

jQuery('li:customWidth') should return 2 elements whose width is 200 and 300.

 

That's it for the day. I think I will remember lot more from this week because I was writing, playing with it as I was reading. See you next week with third chapter! 

Plus!

I was scratching my head thinking about what to write today and then I saw a tweet from Jeff that google plus is now open to everyone with a google account. The entire blogosphere for the past week has been flooded with Google plus, so was time to check it out.

Overall I like it and I am pretty sure I will use it regularly going forward.

Things I liked are:

- Circles: Facebook has groups you can create but it has all this bullshit like open group, secret group and so on. Circles is just group. Nice and simple. It is almost like secret group except that no one other than you knows what group your friends are in and the stream/feed activity just shows up on their wall seamlessly based on what they can see/not see. Majority of people probably don't care for this but I am not very "social", I don't like to post everything to everyone. So, circles really comes in handy for me.

- Hangout: Finally I can hangout with my family and do video chatting. There was no good way to do 3 way video chat and now that problem is solved!

- UI: Pretty slick. They have done a neat job on the look and feel.

Things I didn't like are:

- Facebook does a really good job of showing lot of posts in a page. I can see may be 4 or 5 posts before having to scroll down in plus. And there are too many things on the plus page. Wish I could just hide lot of those little widgets lying around. 

That was my initial reaction playing around for 20 mins with it.

See you tomorrow!

Mahesh

ps: I have 9 circles already :-)

3 vim tips of the day

Three vim commands I learned and have started using from today:

1. Marker: m<char> and `<char> to mark a line and jump back to it from anywhere else.

Ex: Open a file in vim and then go to some line and type mt. Go to some other line and then type `t and you are back to the line which you had marked before. It comes in handy sometimes when I am jumping back and forth between methods in a file.

2. retab: This is courtesy of John today in the chat room. It converts all tabs into spaces.

3. bwipeout: Sometimes I have so many files in my buffer that I end up closing the entire vim session and starting up again. That kinda sucks. Well, now I know I can just do a :ls and :bwipeout and specify bunch of files which I want to remove from my buffer.

Ex: Open a bunch of files in vim and do :ls. You will see a list of files in your buffer. :bwipeout <file1> <file2> etc to delete those files.

Every time I see blog posts and articles listing all the cool vim commands, it gets overwhelming for me and I don't end up picking up any. So, I will just add commands slowly one by one to my repository.