RequestExpired while using Ruby Fog with AWS

Posted on 21 Mar 2014 by Matthew Revell

If you get a RequestExpired => Request has expired error from the Fog library in Ruby, check that your system time is correct. It likely means that your clock is out of sync with AWS.


Introducing the Couchbase Ruby client

Posted on 08 Feb 2014 by Matthew Revell

Playing with Couchbase is easy.

For those first few steps, it’s all about simple CRUD operations on JSON documents: you’re putting JSON in, pulling it out again, making changes and deleting when you need to.

I’m going to write a short series of posts introducing the Couchbase Ruby client. In it, I’ll step through building a small app to keep track of Couchbase swag.

In this post, let’s get acquainted with Couchbase Server and the Ruby client.

Installing Couchbase and the Ruby client

If you haven’t already, get ahold of either the Community or Enterprise edition of Couchbase Server. Installation is straightforward and you can stick with the defaults for now.

For the SDK, we’ll need to install two things. The Ruby SDK is a wrapper around libcouchbase, Couchbase’s C client, so you’ll need to get that first.

Once you have that, install the couchbase gem:

$ sudo gem install couchbase	

Connecting to Couchbase Server

Now we can write some code.

First up, let’s pull in the Ruby client and then connect to Couchbase:

require 'couchbase'
	
db = Couchbase.connect(:hostname => "localhost")

That’s pretty self-explanatory: the database connection is loaded into the db object and the server is running locally. There a couple of other options we could’ve specified, but they’ll wait for another post.

Adding our first document

When we start importing the CSV file, it’ll show that each item in our warehouse has a:

  • product code
  • description
  • quantity.

Before we work the CSV, let’s try it manually.

The product code can act as our key: it is unique and reasonably short.

key = "LAPTOPSLEEVE"	

We’ll take the other two and create a hash:

document = {"Description" => "Red Couchbase-branded laptop sleeve", 
"Quantity" => 91}

Now to write it into Couchbase we pass it to the db object:

db.add(key, document)	

Putting it all together we have:

1 require 'couchbase'
2 	
3 db = Couchbase.connect(:hostname => "localhost")
4 	
5 key = "LAPTOPSLEEVE"
6 document = {"Description" => "Red Couchbase-branded laptop sleeve", 
7 "Quantity" => 91}
8 	
9 db.add(key, document)	

So, here’s what our script does:

  • connects to the Couchbase server
  • specifies a key name
  • creates a hash that the client will convert into the body of our JSON document
  • uses the add method to write both key and document into Couchbase.

Viewing your documents in the Couchbase web console

Open up the Couchbase web console to take a look.

In the top navigation, you’ll see Data Buckets. I’ll cover buckets in a later post but you can think of them as roughly equivalent to a database or collection that you might see in other database systems. For now, it’s just somewhere to put our data.

Click that Data Buckets link and you’ll see that Couchbase created a Default bucket for us at install time.

The Data Buckets page in Couchbases web console

Press the Documents button and you’ll see our LAPTOPSLEEVE document.

The default buckets document listing

It worked!

Adding versus setting

To get our laptop sleeve into Couchbase we used the add method.

Let’s try running our little script again. You’ll get an error from Couchbase that the key already exists.

If we want to write a document into Couchbase regardless of whether there’s already one using that key, we’ll need the set method.

Let’s try that instead:

1 require 'couchbase'
2 	
3 db = Couchbase.connect(:hostname => "localhost")
4 	
5 key = "LAPTOPSLEEVE"
6 document = {"Description" => "Black Couchbase-branded laptop sleeve", 
7 "Quantity" => 349}
8 	
9 db.set(key, document)	

The set method silently overwrites any document already using our chosen key.

Refresh the documents view in the web console and you’ll see that we’ve changed the description and quantity for LAPTOPSLEEVE.

Our updated document

Reading and deleting

Reading the document is just as straightforward:

db.get("LAPTOPSLEEVE")

You can probably guess how to delete a document:

db.delete("LAPTOPSLEEVE")

Next time

We’ll tackle importing the CSV in the next post.


Switching to Jekyll

Posted on 05 Jan 2014 by Matthew Revell

Today I switched this site over to Jekyll.

After close to a decade on Wordpress, I was itching for something lighter-weight. In fact, something a bit more like PyBlosxom, which I used before Wordpress.

Specifically, I wanted:

  • generates flat HTML files
  • posts written in Markdown or similar
  • no complicated theming engine
  • something that was easy to extend
  • ideally written in Ruby
  • community momentum.

Choosing a static site generator

I looked at building something using Jekyll, Octopress, Sinatra or Middleman.

Sinatra was fun to play with but required me to run a Ruby application in production.

Octopress is an on-ramp for Jekyll: it gives you some of things you’d expect from a blogging engine, such as RSS feeds and a default theme. However, I was put off by suggestions that it’s harder to upgrade and some of the choices it made for me.

That left Middleman and Jekyll. Honestly, it came down to nothing more than Jekyll appears to have more community momentum. I could see the advantages of using ERB with Middleman but, right now, I didn’t need to do anything I couldn’t with Liquid templates in Jekyll.

Migrating

Migrating was reasonably straightforward. The only thing I wanted help with was converting the blog posts into Markdown.

For that I chose the ExitWP WordPress plugin. That gave me a zip file of my site’s contents, with a fairly good stab at converting the posts into Markdown. It left a few artefacts, including not converting links with targets and some other chunks of HTML mark-up that got left in the text of the post. It also added a permalink to each post’s front matter, which I removed manually as I didn’t want special case permalinks.

What I needed to add

For design/layout I chose Twitter’s Bootstrap. My pal Joel had mentioned it to me a while back. Along with the Slate theme from Bootswatch and some help from LayoutIt I was able to get a pleasing visual design.

For the RSS feed I used Snaptortoise’s templates, via Drew Inglis. I’ve used an .htaccess redirect for existing subscribers and then this meta tag to point to the feed:

<link rel="alternate" type="application/rss+xml" title="Matthew Revell's blog" href="http://www.understated.co.uk/feed/feed.xml">

The sitemap template came from havvg on GitHub, via Chris Dingli.

Comments were a fairly straightforward choice: Disqus. I’m not yet sure how I’ll migrate the history of comments, if at all.

What’s next

What I have now is good enough but I definitely want to fix some layout issues, pretty some things up and make use of the side-bar on blog posts.

I probably won’t implement categories.


Hiring: Technical Evangelist at Basho

Posted on 15 Jan 2013 by Matthew Revell

I’m looking for a passionate, enthusiastic and opinionated person to join the EMEA community team at Basho.

The job title is Technical Evangelist, but it could just as easily have been Developer Advocate or Community Manager.

The person who’ll suit this role knows the open source world inside-out, can quickly grok technical detail and understand use cases and, most importantly, what solutions are a good fit for them.

If this is starting to spark your interest, do the following items describe you?

  • UK-based.
  • Technical, with the ability to read code and some ability to write code.
  • Excited to travel, for one or two days at a time, two or three times a month within Europe and maybe the Middle East and Africa.
  • Confident speaking to people at meet-ups and giving talks at conferences.
  • Autonomous and full of ideas but able to work to a plan and within a team.
  • You understand that marketing is more than being really good at Twitter.

If you’re interested, drop me a mail (mrevell AT basho DOT com) or take a look at our application form.


New job: Community Manager at Basho

Posted on 30 Oct 2012 by Matthew Revell

Last week I started a new job as Community Manager at Basho‘s new London office, looking after Europe, the Middle East and Africa!

Basho are the people behind the Riak NoSQL database, along with the RiakCS S3-compatible block storage platform. Riak was inspired by Amazon’s Dynamo paper, which describes how Amazon have used their own in-house database system to ensure their services run even in the event of outages and that they can scale quickly and with minimal effort.

It was a pretty easy decision to apply to work at Basho. They have a core product, in Riak, that solves a set of problems that will affect just about anyone deploying services over the net. What’s more, they’re doing that while maintaining a good balance between retaining the independence to create the products customers want while being aware of the broader contexts in which those products are used.

Perhaps most importantly, though, for me was that the people at Basho are smart, friendly and everyone there has a voice and a hand in the success of the company.

As Community Manager in the EMEA team I’ll be making sure that Basho and Riak are at the right events, I’ll be organising meet-ups, podcasting, writing, meeting people and generally helping to grow and maintain a community of people who are interested in and excited by Riak.


Copyright 1999-2014 Matthew Revell.