Wednesday, February 14, 2007

part of the seattle coffee shop scene

I guess one common way to get over the loneliness of working for yourself is to work out of a coffeeshop.

But, given my recent ergonomic adventures, I have been a little reluctant to do that for fear of my hands hurting from prolonged laptop typing.

Plus, it just seems superdorky to walk into a coffeeshop with your own keyboard.

Well, I'm a dork.

I'm at a cofeeshop right now with my keyboard sitting comfortably on my lap and mostly out of sight under the table. You'll have to ask the other people here how dorky they think I look.

For the most part I've been pretty productive, minus the distraction of listening to some startup deals taking place (that was very informative)

Tuesday, February 13, 2007

an unbalanced life

I remember when I was in college, more so in grad school, I had to try really really hard to take time out of my day to go running or to work out.

Whenever I actually got myself into the discipline of doing so, I'd usually be more productive and creative, but deciding to take that time out of my day was very hard.

A few weeks ago I was thinking that, now that I can choose my own hours, I'll be very good about going to the gym or at least going for a run. But somehow it's been ridiculously hard to pull myself away from the computer; I've been spending most of my waking hours getting up to speed on ruby on rails, and getting started on building my application. It sucks; I can even feel my energy levels dropping.

I think the commonality between grad school and now is that I own my own time. Maybe subconsciously in undergrad and at work I was able to say "you know if you're going to make me work this hard, I'm going to damn well make sure I have 'Hemant-time' to go be healthy". Whereas now (and to a large part in grad school) the entire day is 'Hemant-time' so it's harderer to justify taking time out of that.

Either way; I'm at the point today where my productivity is going to suffer if I don't get in some solid exercise. Hopefully, having written this, I'll make it out to the gym today.

Thursday, February 08, 2007

dvorak, anyone?

this is probably an incredibly stupid idea, but i'm thinking of trying to use a dvorak keyboard layout. has anyone tried that? anyone using one right now?

Wednesday, February 07, 2007

a simple tcp server

In the past, I've found it really useful to have a simple server that is able to listen on a TCP socket and print out everything it receives. It's a great debugging tool.


The following ruby snippet (adapter from an example in 'Programming Ruby') does just that:


require 'socket'
port = ARGV[0] || 80
server = TCPServer.new('localhost', port )
while( session = server.accept)
while !session.eof?
puts session.gets
end
end

Probably cooler would be if it took everything on STDIN and echo-ed it back to the socket as well.


Update: Thanks pooja. I couldn't think of netcat at the time but that does exactly what I want. I'm such an idiot for not remembering.

open source and deployment

I apologize in advance for those of you who don't particularly care to read any code.

But one of the things I'm going to try to do while working on my startup is to post as many code snippets as possible.

Why? Because I'm a believer in open source. My startup is not focussed around building great deployment tools. By posting my code, I'm helping other people who also need to solve similar issues. At the same time, there's a good chance that someone smarter than me will read this and tell me a much simpler or more elegant way of achieving the same result.

If it starts taking up too much of my time, I might post less stuff. If I start to see value in posting code, I might try to do more of it. Either way, I'm running as fast as I can to build an amazing product.

The following script should help me to write common config files and test them out on my mac first and then deploy them with no changes. See the usage function for more info.

Oh - and I'm still a newbie ruby programmer. So if you have code suggestions, or if there's a tool that already does what this does, then let me know. I have no qualms about throwing away my code and using someone else's. Less code = less bugs.


#!/usr/bin/env ruby
require 'yaml'

def usage( msg )
STDERR.puts msg
STDERR.puts <<EOF

USAGE
generate <config_file> <stage> files..

DESCRIPTION
Given the following config.yml:
--
test:
base: path1
user: name1
prod:
base: path2
user: name2
--
and a lighttpd.conf:

--
server.username = "$user$"
server.document-root = "$base$/public_html"
--

% generate config.yml test lighttpd.conf
will create the file lighttpd.conf.generated which looks like:

--
server.username = "name1"
server.document-root = "path1/public_html"
--

EOF
exit
end

usage() if( ARGV.size < 3 )

config_file = ARGV.shift
stage = ARGV.shift

usage( "config file #{config_file} not found. " ) unless File.exists?( config_file )

all_config = YAML.load_file( config_file )

unless( all_config.has_key?( stage ) )
usage("config file #{config_file} doesn't specify stage '#{stage}'.")
end

config = all_config[stage]

# build up the regexp to match all identifiers:
regexp_string = '('
config.each_key { |id|
regexp_string += '\$' + id + '\$|'
}
regexp_string.chop!
regexp_string += ')'
matcher = Regexp.new( regexp_string )


# Iterate through each file
ARGV.each { |filename|
unless( File.exists?( filename ) )
STDERR.puts "file '#{filename}' not found. continuing"
next
end
g_filename = filename + '.generated'
if( File.exists?( g_filename ) )
# TODO: move old file out of the way instead..
STDERR.puts "file '#{g_filename}' exists. OVERWRITING!"
end

generated = File.new( g_filename, "w" )
# check each line
File.open(filename).each_line{ |line|
# replace each instance of a token
line.gsub!( matcher ) { |match|
id = match[1..(match.size - 2)]
# with the value specified in the config file
config[id]
}
generated.puts( line )
}
}

Monday, February 05, 2007

Stepping over the edge.

After five years (well, technically about four years, eleven months, and change), I'm leaving amazon.com. It's been a pretty awesome time, and I've learnt a lot from some really smart and passionate people.

But sometimes, it's just time to move on. In my case, I'm stepping off the cliff of getting a paycheck to living on my savings and attempting to create something meaningful and with monetary value. I'm starting a company.

It's scary thinking about it.

Stay tuned here for more info, if you so desire.

-Hemant.

Update: I suppose, technically, the title should read stepped over the edge. I can feel the wind rushing by.

Thursday, February 01, 2007

Growing Up!

A few weeks ago I got the first DVD in the Up series, 7 Up!

The series is a set of documentaries, filmed every 7 years starting 1964, chronicling a bunch of British children from different backgrounds.

7-Up was funny, interesting, and boring at the same time. The kids were super cute, and their differences (most notably along socio-economic lines) were stark. At the same time, it was a little boring to watch the whole thing.

Yesterday I watched 21-Up (they skipped 14 apparently) and that was a whole lot of fun. It was amazing to see how the 7-year-olds had turned out 14 years later. And 21 wasn't so long ago that I don't remember what it's like! :)

The wonderful thing is to be able to see myself in many of the kids chronicled; and to try to remember back to when I was seven and fourteen and twenty-one and what my views were on life, politics, society, sex, class, opportunities, marriage, family, ... (the list is long).

I'm really excited to see the rest of the DVDs in the series. It goes all the way up to 49 Up, which was released in 2005.

Highly recommended viewing.