Now From Home

Working from home

Got a Transcend 32GB USB 3.0 Flash Drive

I’m preparing a small trip to Seville to visit a couple of customers. One of them has a 12 GB SQL Server database so my current 8 GB USB flash drive is not going to make it. My current 8 GB pen drive is only 6 months old and I payed for it almost the same than for this one that has 4x times the capacity.

Transcend 32GB USB 3.0

Of course the first thing I did with the drive was to protect it

GITT: Git in the Trenches

My journey using SCMs has taken me through SourceSafe (ouch!), Subversion, Mercurial and finally Git.

Despite all that experience, when I started using git I felt a bit lost. Beeing most of the time a sole developer, I really never used the most advanced features of those tools, only the basic stuff. Even with Mercurial, my branching model was based on cloning a full repository in another folder and pulling/pushing as needed.

Now I’m using git for most of my repositories and every day I learn something new. I really like git.

The best resource I’ve found to really grasp git is Git In The Trenches by Peter Savage. Thanks to this book I moved from a “branch/merge” level of understanding, to use “rebase” confident about what is going to happen.

I like the style of the book because is based on scenarios you’ll likely face sooner or later. For example:

  • Have you ever wanted to edit a commit message?
  • Wanted to merge two different commits into one?
  • Wanted to recreate a branch that was deleted by mistake?
  • Search where a change (a bug) was introduced, even automatically?
  • Discovered you have sensitive data (secrete keys) in your repository and want to remove it?

It’s all there. It’s a really good book. Even though I read it cover to cover, I’m sure I’ll get back to it as a reference.

Oh! I almost forgot, it’s free, even the PDF / e-book versions.

Migrate a Repository From Mercurial to Git

I’m using Linux more and more and I’m using git with my Linux projects. Now that I used both Mercurial and git, I feel more productive using git, basically for the branching. So I decided to move my Windows projects to git too, and get the same experience on both OS.

I’m hosting my projects on BitBucket as they offer free private repositories.

There’s a lot of blogs covering how to migrate a repos from Mercurial to git, I’m posting the method that worked for me as a reference.

On Linux:

1
2
3
4
5
6
7
git clone git://repo.or.cz/fast-export.git
mkdir new_git_repo
cd new_git_repo
git init
/path/to/hg-fast-export.sh -r /path/to/hg_repo
git add remote origin git@bitbucket.org:USER/repository_name.git
git push origin master

Ubuntu Server for Rails 3.1 and PostgreSQL 9.1

This is the second time I have to setup a VPS for a Rails/PostgreSQL so I’m documenting the steps in a customized guide to hopefully save me/you sometime in the future. These steps are collected from different sources, mostly from the Linode Library.

The guide is on its own page because I hope to keep it updated.

Enjoying the Simplicity of Octopress & Jekyll

As I spend more and more time on Linux, I’ve begun to enjoy the simplicity of the tools I use.

When I read about Jekyll and static site generators I fell in love with the idea.

I maintain a couple of blogs including this one and I’ve always used Wordpress because it is a one-click install in Dreamhost. Although extremly powerful it has some things that I don’t really like.

For instance, my posts are stored in a database (MySQL), which I have to backup. And then, there’s the blog template, which I tweaked a lot back then but now I don’t really know how to backup. I’d rather use git as I do with most of my documents and projects.

Anyway, I gave Jekyll a try on my Ubuntu box and I liked it a lot. Then I discovered Octopress which is just a framework on top of Jekyll and makes it really easy to work with Jekyll.

I’ve moved this blog from Wordpress to Octopress in a couple of hours, including setting up the comments (Disqus), the deployment (rsync) and the source control (git repository). Loving it!

Jekyll

Octopress

Migrating from Wordpress to Jekyll

Rails, Multi-tenant Applications

I’m facing my second Rails project that has to manage multiple tenants. In both projects each customer gets its own subdomain and it’s own data . There’s three common approaches to solve this:

  • Share nothing (each tenant gets its own database)
  • Share everything (a single database holds the data of all the tenants; table must include a tenant_id column)
  • PostgreSQL schemas or namespaces (single database but a new schema is created per tenant with all the tables)

I strongly recommend to check out this video ”Writing Multi-Tenant Applications in Rails”. It explains all these three options in detail.

For my first project I was a little paranoid about depending on just one column to select the correct data for each customer. If just one query misses to filter by that field you’ll be exposing private data to other customers. And what about backups? First option ruled out.

Even though the third option sounded appealing, I was just starting with Rails, Linux, etc. So I choose the “share nothing” approach using MySQL. It’s not trivial to make it work, and you have to add code to switch between databases per request. Migrations requires you to write some custom tasks too (future post?). That said, it’s working just fine. Backups are easy too as they are just different DBs.

For my new project I’m going to try PostgreSQL and the multiple schemas solution. One of the showstoppers for me to use this solution was that I didn’t know how to handle the hypothetical case that a customer needs to restore its data from a backup. In my mind there was no solution, but to restore the full database. I was wrong.

It’s as simple as dumping the database “per schema” using the PostgreSQL tool pg_dump which allows you to specify the schema.

Time to play with PostgreSQL and Rails 3. I’m using this post as starting point.

Windows 7 USB/DVD Download Tool Unable to Copy Files

As everyone, I downloaded the Windows 8 Developer Preview to start playing with what it looks like a big step forward from Microsoft.

I downloaded the Windows 7 USB/DVD Download tool to create a bootable USB pendrive and it failed with the error message “Unable to copy files…”

I used this very same pendrive to install Ubuntu, so I guess that, even though I formatted the disk, something was still there, on the boot sector or MBR.

I found the solution in this article:

  • Run “diskpart” from a command prompt with admin rights
  • list disk
  • select disk # (the number of your USB)
  • clean
  • create partition primary
  • select partition 1
  • active
  • format quick fs=fat32
  • assign
Run again the tool, it will work without problems now.

When Your Assets Doesn’t Get an Asset_id…

… check that the asset does exist.

I had the following code in my application layout template:

application.html.erb
1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
  <title>My webpage title</title>
  <%= stylesheet_link_tag 'default' %>
  <%= stylesheet_link_tag @current_subdomain %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>

It works great to load a custom stylesheet depending on the current subdomain, however I noticed that for some subdomains Rails was not adding the asset_id:

1
2
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/default.css?1307960871">
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/sample.css">

It is because sample.css must exist. stylesheet_link_tag does not check for the existence of the asset, and if it doesn’t exists it doesn’t add the asset timestamp.

Hope it saves you some time.

Program Does Not Contain a Static ‘Main’ Method Suitable for an Entry Point

I usually create projects in Visual Studio using the Empty project template, even if they are going to be a WPF application. As the code evolves I keep adding the appropriate references (System.Xaml, PresentationCore and so on).

At some point I’m ready to launch the application and I receive the mentioned error:

Program XXXX does not contain a static ‘Main’ method suitable for an entry point

Invariably I keep forgetting where the problem is. So I start inspecting the project properties, the App class, etc. After some minutes, frustrated, I launch Google and I find the answer. It has happened way too many times, so I’m writing it here. Now I’m sure I will never forget it.

The file App.xaml is set to some other thing instead of ApplicationDefinition!!

If You Get Stucked With a RoR Error, Restart Script/server

Yesterday I had an idea for a web app (again!). I decided to sketch it out using Ruby On Rails as a way to experiment what’s outside the .NET ecosystem. Besides, if the idea finally crystallizes, it will fit much better in a Linux box than on a Windows server mostly because I think it will be hard to find a good revenue model.

This post is just a note to myself. I have to admin than I’m totally lost with RoR for now. I’m following several screencasts and reading every beginner’s tutorial I can find.

Following one of those tutorials I got stucked. I checked my config files, checked that I had not misspelled anything but nothing came out.

Finally I saw an error on the server log:

Rendering rescues/layout (internal server error)

That error message was logged 55 minutes ago!! Just restarting the ruby server made my error go away. This is the second time this happens, so I’m writing this post as a reminder. Depending of what files you touch, you could need to restart your app.