Tuesday, 30 November 2010

Gotcha: heroku with git+svn pushes your working copy

For the MatchFounders website, I've been working with svn on Heroku using git just as a deployment tool... and I came across a bit of a gotcha the other day.

git commit will add your *working copy* to your next deployment.

Luckily it didn't turn out too badly for us - I was just mucking about with some pagination links... and quickly fixed the bug I'd been working on before deploying again... but if I'd been right in the middle of some big hairy code refactor, or something... I'd have had to go find heroku's docs on rollbacks pretty darn quick.

So - just be aware that if you use this method, to add a step to your process-control to make sure you only deploy from a 'clean' working copy.

Tuesday, 23 November 2010

Ruby median

Was trawling through the google analytics search keywords and noticed somebody was looking for an Enumerable#median method when they came to this site. Got me thinking...

I went googling for solutions and found that some of them were just plain wrong... can't have that.

module Enumerable
  def median
    # trivial cases
    return nil if self.empty?

    mid = self.length / 2
    if self.length.odd?
      (entries.sort)[mid]
    else
      s = entries.sort
      (s[mid-1] + s[mid]).to_f / 2.0
    end
  end
end

This one isn't the most time-efficient (the sort can get long). I'd need to implement the selection-algorithm for the most optimal solution... but it'll do for a quick fix. I'll post again here if I get around to the better one.

Friday, 19 November 2010

MatchFounders hits 500

MatchFounders.com hit its first milestone today: 500 registered members. I'm pretty pleased with that, seeing as how it's been a part-time on-the-side project that started on what's basically a hackfest.

Still got heaps to do before it becomes a world-dominating site, of course... but I'm pretty happy with that amount of activity after only a month and a half. Enough to post about it on the matchfounders blog... along with our upcoming dastardly plans.

Saturday, 13 November 2010

mobile broadband roaming

The directors of MoneySpyder have been reading "The 4-Hour Workweek" by Timothy Ferriss and are all fired up about the idea of us working from home (amongst other things). Basically, they're hoping to kick the expense of an office - which is fair enough.

So I casually asked "so, does this mean I can take my laptop on the road?"

I was kinda surprised when they answered yes.

w00t!

So, I finally have the option to live my original dream - spend a month in France, a month in germany, a month in spain...

BUT...

(you knew that was coming)...

I've just checked what it costs to get international roaming on mobile broadband, and it doesn't look pretty.

Actually, that's an understatement... it looks downright atrocious.

I'm currently on three mobile - and I pay around £15 a month for 5G of internet usage. As yet I've never busted that limit - I think I use around 1.5-2G. I used to have a 1G account (with O2) but that wasn't enough for me - eg when I needed to do a full ubuntu upgrade.

However - when I checked into the mobile broadband roaming rates I discovered that they don't bundle your monthly allowance - it costs per mg... and not at the usual overlimit pricing rate of around 10p per meg - it costs you £1.25 per meg!

This would mean my normal monthly usage would come to cost of £2000-£2500 PER MONTH!

Yes, that's over two thousand pounds per month!

Now - I can understand that it costs a fair bit more to use overseas carriers, than to use their own.... but even if *they* bought the data at retail prices, and then charged *us* retail on top of that - this would come to only *twice* our normal per-meg rate...

Not 166 TIMES my normal monthly amount.

There is something seriously wrong there!

Now - the pages all say "well, just don't use as much internet when on the road"... but unfortunately, I have no choice. I am a Web developer - that requires me to do a bit more than just checking email or checking the local weather online. I need to download the latest codebase, get copies of db dumps, upload and deploy sites, go to the online site and test it thoroughly... etc etc. Even if I cut out all recreational internet use (and where's the fun in that) I'd still be using about a Gig a month.

I've noticed that a very few enlightened companies have begun to offer something a *little* better (eg orange travel bundles), but even so - they're still not even approaching regular internet usage. The orange bundle offers 50M at £40 - which would make my monthly spend "only" £1200 - so, half the rate of the Three option... but still in the ridiculous zone.

Now, I've wandered about online in search of a better solution, but I have only a couple of viable options.

Firstly - I could spend my life in a Maccas or Starbucks (or equivalent) for the purposes of the free WiFi connections... rather than actually enjoying the variety of local establishments. Of course - they do expect you to actually purchase some of their wares - and I refuse to eat the former, and the latter is definitely not my cup of coffee-flavoured-milk.

Also - it's quite difficult to actually do real work in a busy cafe. It's ok for a few hours - but it's tough to be there all day. I'd also have to shut down, pack up and potentially lose my table every time I needed to dash to the loo. :P

The second alternative would be to just buy a new dongle from the country I'm visiting... for each country I visit. This feels expensive and wasteful... but if you compare it to the roaming rates - it actually works out cheaper... *far* cheaper.

With Three's quoted roaming rates, it would cost me an average of £85 per day.
Even if a new dongle cost me £100 (for the PAYG version) - I could buy one every two days - and still be paying less.

Ridiculous as this seems, it seems to be my best real option.

If anybody knows of a better solution, let me know!

Dongle-sharing?

But then I got to wondering: perhaps there's others out there wanting to do the same thing. If we each buy a dongle for a different country and then swap with each other - this would be far less expensive. Just buy our own PAYG sims. Or perhaps there are others of you out there already in a different country (that I want to visit) who'd be willing to rent me your own dongle for a month... I'd even pay a refundable deposit!

Any takers?

Wednesday, 3 November 2010

NaNo Wrides again!

It is the month of November, and once again would-be-authors are hurriedly scribbling on pages, or tapping away furiously to meet their daily goal... the elusive 1667!

NaNoWriMo has begun!

I've got my wordcount up on the left again, but you can see more at taryneast's author page.

For those not in the know, "NaNoWriMo" Stands for "National Novel Writing Month" - a writerly self-challenge where people from all around the world pledge to write 50,000 words in the month of November. No, it's not a charity, and it's not a competition... it's just a chance to give it a go and see if you can finally pull that novel out of yourself that you've been procrastinating about for years...

Before you dismiss it as an obscure, minor little thing that only a few weirdo wannabe-writers have heard of... you might want to know that it's more popular than you might think! As of yesterday there were 156,415 authors signed up worldwide, who wrote a collective 55 million words. Yes, that's millions, and yes that's just yesterday!

It's crazy-fun and I recommend it to anyone - especially anyone who thinks they're a terrible writer, or who thinks nobody wants to read what they write... but secretly has a tiny desire to be known as an author. Trust me, NaNoWriMo is for you.

It's only day two - there's still plenty of time to join in the fun! Go on, give it a shot! What have you got to lose? :)

Sunday, 31 October 2010

Gravatar in rails

Just a quick code-snippet today. A quick helper to take an email and spit out a gravatar image.

  # show the gravatar image for a profile - based on their email
  def gravatar(email, size = 100)
    the_hash = Digest::MD5.hexdigest(email).to_s
    image_tag "http://www.gravatar.com/avatar/#{the_hash}?s=#{size}&d=mm"
  end

This one displays the "mystery man" image if the person doesn't have a gravatar. More details on the options and how to tweak it further are available on the Gravatar Image Requests page.

Thursday, 21 October 2010

Profiling inside of procs

I've been using ruby-prof and kcachegrind to delve into our code recently - in an attempt to speed up some of our heaviest views - these are mainly big admin pages listing, say, all orders that are waiting on backordered products.

One of the joys of kcachegrind is the ability to see the actual lines of source-code with the actual time spent in each LOC nicely indicated. You can then click on that line and it'll jump into the slow method that is called by that line.. so you can dig down to where the actual pain is being caused in your app.

One of the problems with with the source-code tracking, though is that it just doesn't deal well with ruby procs. Kcachegrind assumes it's some kind of method-call, but when you click on that LOC, it doesn't take you to the code inside that proc, but you instead end up diving into the *ruby* source-code itself... definitions of blocks and procs etc... which are all aggregated together and thus you can't tease out the bits that you actually want (ie the code operating inside the proc itself).

So if you have something such as the following wrapping almost your entire view page:

   @orders.each do |order|
      # tons of lines....
      # displaying and formatting the order values follow...
      # ...
   end

You'll often only get a single, aggregated line of information n the "orders.each" line... and clicking it only takes you to Ruby's Array#each rather than your actual code.

Entirely unhelpful.

For the sake of profiling that code, though, you can unroll it into a while loop - just to check which LOC are the ones giving the pain by switching it (temporarily) to:

   idx = 0
   while idx < @orders.size do
      order = @orders[idx]
      idx +=1 # don't forget this line or it will take some time to finish.. ;)
      # tons of lines....
      # displaying and formatting the order values follow...
      # ...
   end

It's a dirty hack, but in the absence of "each" it's kind of a necessary evil - and it works. Just make sure to remove it once you're done!!!

Saturday, 16 October 2010

Quick RubyProf action filters

A good while back I spoke about using ruby_prof and kcachegrind at LRUG.

I was asked back then if I could stick up my ruby=prof filter-code... and I've been just a *little* bit slack about getting around to that... but recently I've been profiling again, so I thought I'd bring it out again for general use.

Here's a way to quickly add ruby-prof profiling to any given *action*. Use the following around_filter on your action. Note: this will *only* profile what happens in the controller-action. I use this on our uber-heavy summary-page views to make sure that the mammoth Active Record fetches aren't themselves the problem... before getting onto a full-stack profiling-run.

  around_filter :profile_it, :only => :my_slow_action

  # profiling around-filter - just does the controller-action only
  def profile_it
    require 'ruby-prof'

    logger.info "Starting profiling"
    # profile the first set
    RubyProf.start

    # actually do the action
    yield

    result = RubyProf.stop
    logger.info "Profiling finished, printing files"

    # Print the callgraph profile
    filename = Time.now.strftime("RubyProf_#{params[:controller].gsub('/','-')}_#{params[:action].gsub('/','-')}_%Y-%m-%d_%H:%M:%S.grind")
    File.open(filename,'w') do |the_file|
      printer = RubyProf::CallTreePrinter.new(result)
      printer.print(the_file, 0)    
    end
    true
  end

or to profile the full stack through to the template render, you'll want to split the start/stop. I tend to call start_profiling at the top of the controller action (to get rid of most of the rails loading time), and then call stop_profiling at the bottom of the relevant layout.

Put this into application_controller.rb

  # Will only start the profiling... to stop, you'll need to use the helper
  # at the bottom of your template.
  # Use this pair to catch template-rendering in your profiling data
  # Pass ":wall" as a variable to use wall-time instead of process-time
  def start_profiling(time_type = nil)
    require 'ruby-prof'

    logger.info "Starting profiling"

    RubyProf.measure_mode = RubyProf::WALL_TIME if time_type == :wall

    # profile the first set
    RubyProf.start
  end

Put this into application_helper.rb

  # Use this helper in your template to stop profiling. Asumes you have
  # called "start_profiling" in your action somewhere
  # Will asplode if you haven't actually *started* a profiler
  # (eg if the previous action threw an exception before completing the profiling run)
  def stop_profiling
    if RubyProf.running?
      result = RubyProf.stop
      logger.info "Profiling finished, printing files"

      # Print the callgraph profile
      filename = Time.now.strftime("RubyProf_#{params[:controller].gsub('/','-')}_#{params[:action].gsub('/','-')}_%Y-%m-%d_%H:%M:%S.grind")
      File.open(filename,'w') do |the_file|
        printer = RubyProf::CallTreePrinter.new(result)
        printer.print(the_file, 0)    
      end
    else
      raise "Stop profiling called when no profiling started!!!"
    end
    true
  end

Sunday, 10 October 2010

RedBubble Gallery page

I've posted earlier about how cool RedBubble is... but now they let you set up a gallery page, to show off (and even sell) your best pics. So here's the Ruby-coloured glasses gallery

Sunday, 3 October 2010

Heroku with svn

and here I was thinking I'd never get to play much with Heroku as I prefer svn over git... [*]

It seems you can easily use Heroku with svn, by using git just as a mode of transport onto Heroku.

If you've never used Heroku before, you must set up your keys and project before following the above instructions. Use the quickstart guide to get up and running in no time.

You may think that handling two version control systems is difficult, but so far I've actually found it fairly simple. Basically you treat git like you'd treat "tags" - you commit to git just before you push up to heroku.


[*] For most of my projects, I prefer having one source of truth. I've also had some rather spectacular failure-modes using git which I've not seen the like of in all my years of svn... if you're adamant on learning git, read my Number one thing to learn if new to git first...

Sunday, 26 September 2010

MatchFounders: a launch48 company

So, you are a business guy with a dream, looking for a savvy techie to turn your dream into reality

OR

You are a rockstar developer, looking for a business guru to take your idea to market.

Both of you are looking for somebody hard-working, willing to commit and sharing your values and passions.

They say that looking for co-founders is like a marriage, so how do you find your perfect match?

Match Founders will match your skills, values and passions against other people that also match your needs.

A bit of explanation...

Launch48 has begun, and this time around I'm running a team.

We're building a match-making service to help co-founders find each other, called MatchFounders.

We've got a blog on posterous: MatchFounders and are working on our initial web demo. Stick around to find out what happens...

Wednesday, 22 September 2010

To stealth, or not to stealth

I've been working on a new startup with two other founders that I found at launch48 last year. I've already mentioned launch48 on this blog, but I haven't yet mentioned my startup... That's because we've been keeping it quiet until recently... when we had a kind of "trial launch" at the previous launch48 weekend (in June).

Now, based on my reading on the matter (see links at bottom), I don't believe that "stealth mode" is actually a good way to go about building a web business. I think the reality is that if you've got a good idea, not only will it not instantly be stolen from you, but you'll have to cram it down people's throats before they take any notice...

But you see, I have two business partners. One of which is a strong believer in protecting your IP - and the other wanted to make peace between us... so we compromised and kept a lid on our idea until the trial launch.

Now, we're fairly new to the game, and we think there's a good idea in our startup, but it's no iPhone. It's not something people are screaming for and they aren't going to start beating path to our door immediately. Because of this, I was never afraid of people "stealing our idea" - because, to be honest, it just isn't sexy enough. When I explain it to people they go "oh, ok, cool I can see that... did you think about doing Y?" I've never seen a gleam of greed in their eye, followed by hasty notes scribbled down... and I never expected that this would happen.

So in my opinion, I don't see a big reason to keep it quiet.

Instead, I think it's important to get exposure to your idea as early as possible from people Out There in the Real World... that way you immediately get to see whether people think your idea is actually worth spending eight months of your life on... or not. This is simply my own reasoning behind Seth Godin's Ship it philosophy.

Stealth mode redux has some interesting case studies on which "startups" do and don't need to stay quiet about the product they have in production.

What I see most clearly is that stealth mode is mainly useful for companies that are large and already have a big audience... or who have enough funding to keep them going while they beaver away in secret on a product until it's perfect... ie companies that aren't actually startups.

The problem is that real startups - the tiny, self-funded groups of new founders - can't afford to be in stealth mode for very long - for the very simple reason that they do not have enough capital for long periods of development.

I'm not talking about people that slowly hack away doing a few hours every week while working a day job... I mean real "cash flow positive from day one" startups, rather than ones that require such extended self-funding.

Such things need to start gaining revenue asap, and the only way to do that is to attract customers... and the only way to do that is to tell everybody about them!

In the interest of balance, of course, there's a great post pointing out that releasing early is not always Good - which covers some of the reasons why *not* to release early... and they're all very fair points. But I'd argue that all of them point to a new variant of Einstein's famous "make it as simple as possible, but not too simple" ie:

"Release as early as possible, but not too early"


Update:

After having read The small man builds cages for everyone on The art of non-conformity, I'm convinced that NDAs and other stealth-measures are a cage-building habit.


Notes

Links on stealth-mode being bad, or the philosophy of "release early, release often":
Startup lessons learned
The Cathedral and the Bazaar

More links on stealth mode:
why choosing to go into stealth mode could be the kiss of death for your startup
Does Being In Stealth Mode Damage Your Business?

Wednesday, 15 September 2010

Single sign-out using ruby-cas... Not!

We considered this... right up until the point where I read that you were advised to disable forgery-protection.

It's easy enough to send a message to the rubyCAS server to invalidate a given ticket - but mostly users only authenticate with rubyCAS once, and from then on deal only with a given client-application. Killing rubyCAS's ticket only comes into play when a user tries to re-authenticate with the rubyCAS server.

I don't have a good solution to this one...

This is one article in a series on Rails single-sign-on with rubyCAS

Friday, 10 September 2010

Signup: Ask the right question

The sign-up process is much more than just the form that gets a potential customer's details. The majority of the sign-up process actually takes place inside the customer's head. A customer will sign up - even using a crappy signup form as long as they're actually motivated to buy your product... not that you should make a crappy signup form - because that also just puts hurdles in the way of an otherwise motivated potential customer.

This awesome presentation explains how you can design your signup process to get customers motivated and rearing to go on your site. It points out where the friction is in the process, where they usually fall out of the sales funnel, and the ways to change your way of thinking about your site: to provide ample opportunities for a confused or skeptical customer to change their minds. It also picks out the pain-points for the sign-up process - giving some great examples of how to get out of their way and let them get on with paying you money straight away... always a good thing.

I only wish I'd seen the original talk, but the slides themselves speak the story clearly and are well worth a few minutes of paging through.

Thursday, 9 September 2010

gotchas: gem cleanup

Note to future self: do not type "gem cleanup"...

...now reinstalling rails v 2.3.4, 2.3.5, 2.3.8... etc

Wednesday, 8 September 2010

Launch a startup in 48 hours!

Launch 48 teams up business-gurus and techies, where the aim is to pitch, plan and launch a viable web-product in the following 48 hour period. It's 48 hours of hard-slog startup-founding that is guaranteed to leave you buzzing (honest)

I've been twice now, and just signed up for a third time. It may sound a little crazy... but it is an awesome experience, and I confess I'm now addicted.

If you can make it to the conference (on the Friday) they also line up a set of speakers from some of the best IT companies in the world (google, paypal, et al), along with VC, successful IT businessmen and other assorted useful types to give a talk about how you can turn your idea into reality.

and it works too. Several of the startups have gone on to become successful online businesses... of course some don't but I can honestly say I've learnt a lot in the process. I even met my co-founders there, so I can attest to the benefit of working with people to see if you can work with them...

Early bird tickets are on sale for the next one (the 25th Sep)... so I hope to see you there :)

PS: just to make it clear - I'm not affiliated with launch48 in any way except for having gone along to it (twice now) and found it to be awesome!

Wednesday, 1 September 2010

Rails 3.0 is Done!

As you've probably already heard, Rails 3.0 is done, no longer just a beta, it's out there and beginning to be used. Go look at all the goodies we've got lined up!

Tuesday, 31 August 2010

The culture I prefer

This article named telecommuting culture is an interesting look at how job ads can make it pretty clear about the associated company culture. It pretty much sums up my own experiences of how to tell a company culture that I like from one where I'll just never fit in...

"The world’s a big place. There’s a lot of developers in it. There’s even a few kick ass ones. Most of those don’t live near you ... By being up front about telecommuting not being and option, you’re telling me that company comes first ... Hiring someone good is important, but hiring the best you can afford isn’t."

There's a follow-on post on taking stances that points out how much of a controversy was stirred up by his original, highly opinionated post. He's nicely pointed out that his stance was a strong one - in order to generate discussion, but that he's not unreasonable, basically he just wants people to understand that job-hunting is a two-way street. The following quotes best summarise his (modified) stance.

"Companies that start the conversation with prospective employees by outlining the things they aren’t going to stand for are starting off on the wrong foot..."
"Companies, particularly in the tech space, are asking their potential employees to take a chance on them. Companies are taking a risk too, but when companies expect the employees to be the only ones giving (broadly disregarding monetary compensation from the companies for the moment), they set the wrong tone."

I completely agree with this feeling. Sometimes employers forget that they're not just interviewing you, but that you are also interviewing them - and that this really is a business proposal that has to be fair to both sides. If a company comes across as unwilling to be flexible for any reason, it doesn't bode well for the rest of the employment relationship.

I've too often seen employers that seem to think they own your soul once you sign on the dotted line... that they can make any demand of you and that you'll jump-to. This is the business equivalent of "the customer can have any colour he likes so long as it's black". Which may well work just fine for people that like black... but if you find it overheats in the sun and you need white... you'll find it best to take your business elsewhere. In fact I wrote about the lack of viability of this attitude (at length) in Up or out: the attitude for contractors.

This seems especially to be the case in a down economy as has recently been the case - where I've even seen some employers demand unpaid overtime and drop loud hints about how people should be grateful for having any job at all in this economy.

Apart from being incredibly rude, such employers are short-sighted. Firstly - the economy is going to pick up again... at which point, the indentured slaves are quite capable of picking up sticks and going elsewhere. Secondly - even in the down economy, there were enough jobs (at least in my field) to go and find somewhere that treated their employees like human beings rather than indentured servants.

It pays, in the long run, to be considerate to your staff; to even be flexible, or generous. After all, they're the ones who are literally making your company's money, day-in and day-out.

Tuesday, 24 August 2010

The two faces of Optimism

I've often been accused of being a pessimist.

I'm actually not. Far from it, I truly am an optimist. The problem seems to be that often people use the word "optimist" to mean something quite different to my (accepted) understanding of the word; and so, not agreeing with their worldview, they label me as a pessimist.

I think the real issue stems from divergent ways of viewing the term.

There are two definitions in common use.

A world of abundance

First is the one that I subscribe to. Optimism, for me, is to see a world of abundance, rather than a sea of troubles.

I believe that there is a solution to every problem (even if the solution is to throw out the old game and find new rules) and that anyone has the ability to get through the problems and find their dreams. Nobody is a lost cause and there is plenty of abundance to go around.

For me, that is optimism.

*You're* not an optimist

The other view I generally see in the pejorative sense. I can best explain by example:

You don't agree that my <* patently-impossible or highly-improbable *> plan will succeed, That's because you're just not an optimist!

I guess I'm just not a yes-man

Let me be clear: It's not "optimism" to be in deep denial about the efficacy of your plan, and I am not a "pessimist" just because I have looked at the numbers and found that they don't add up quite as well as what you hope them to be. I simply don't agree with you.

I am not a pessimist because I believe that *this* solution of yours won't work. I am an optimist because I believe that there *is* a solution, and that we will find it if we keep trying.

Optimism and employee relations

This issue often crops up at its most pathological in employee relations. In my experience, this is because there's a certain breed of manager that simply doesn't want to hear anything negative - even if it's the facts surrounding a potential solution. If solutions to a problem are proposed, then the most optimistic *sounding* solution will often win, regardless of actual likelihood of being the correct fit. Any nay-sayer to the offered solution will simply be dismissed as a curmudgeon, and thereafter will often be viewed as a "troublemaker".

As human folly goes, if the plan then fails, the nay-sayer is hardly likely to receive any recognition for having pointed out the potential... in fact, if the subject is ever brought up again, greater dislike is sure to follow - nobody likes being told "I told you so", especially on the heels of defeat.

More often than not, however, the initial solution will not fail miserably, but will simply provide sub-optimal results. The originator of the idea will be convinced that it was the best that could possibly have been achieved and that you were clearly a pessimist to think that it could fail...

Trust me... there is no point to trying to persuade them that your idea could have been better.

So, what to do?

The only way out of this dilemma is to make sure that instead of simply taking pot-shots at a bad idea, always provide an alternative solution that you can show is more likely to work. In this way you can show that you are optimistic about solving the problem, just not about the particular solution on the table. It's even better if you can reuse aspects of the original solution in your own - to show that the first proposal wasn't all bad, just needs re-alignment... but this isn't always possible.

It's certainly not a guaranteed solution. The first idea may well not be removed from the state of play - and may still be valued seeming more optimistic (ie providing a promise of a better end-solution... even if not more likely to succeed). This is even more likely to happen if the solution has been championed by a manager in an environment where Highest Paid Opinion wins reigns supreme). However, offering a solution will show that you are presenting a positive outlook, and you're less likely to be tarred as strongly with the pessimist/troublemaker brush. You show that at least you are trying to be helpful.

Of course... in some environments it still makes little difference, and even a dissenting opinion will brand you.

In this case, my suggestion is to be an optimist and trust that the world will get along in the end, and that perhaps there might be bigger, better places for you... if you choose to go looking for them. :)

Notes

Pessimist:

In reaction to them, I'll often tell them that I am a "realist" - which unfortunately makes them just snort and underscore the "pessimist" label in their heads. After all, I've found that a lot of optimists don't know the difference. Of course, mainly I'm just playing with their heads. :)

yes-man:

Sorry, "yes-woman" just sounds stupid, so I won't use it regardless of the truth of my actual sex; And I will bite anybody that suggests that I use "yes-person" :P