Call Montréal, Canada 524-949-6869

Blog

Friday, June 20, 2014

Talk: Don't Commit Your Secrets

On Tuesday this week, I presented a talk to Montreal.rb on keeping your application secrets safe. Posted below is the video, slides and some follow-up questions during and after the presentation. Enjoy!

Video


Slides


Questions

How can I remove a secret from your Git repository?
GitHub has an excellent post on how to do this: Remove sensitive data. However, if you have committed a secret to your repository which has been push to a remote, then consider that secret compromised. You will need to reset the secret (i.e. create a new API key) and configure your application using the techniques described above.

How can I keep my secrets safe with an application pre-Rails 4.1?
Check out these options:

  • foreman: recommended - any Rack app
  • dotenv: great for plain old Ruby Gems too
  • figaro: YAML
  • capistrano: linking to a configuration file in production

Tuesday, April 22, 2014

Modeling on the Right Side of the Brain

Update: The presentation is now online. Unfortunately the color has been washed out when the slides were filmed, so I highly recommend you follow along with the slide deck below. Enjoy!




If you attended my talk at RailsConf, Modeling on the Right Side of the Brain, thank you so much for your support and I hope you found the talk helpful. Embedded below are the slides for my talk and resources listed below that you will find helpful in learning more about Object Modeling.

If you have no idea what I'm talking about, here is the abstract from my talk that I gave at RailsConf 2014 in Chicago.

"Since your first web application, you have struggled with identifying domain objects. Assigning business rules and services appears to be a talent that only other developers are born with. Fear not! Object Modeling is a learnable, teachable skill. This talk demonstrates the five essential skills you need for modeling objects and their responsibilities. Think beyond ActiveRecord and your database, and learn how color and patterns will help you explain, maintain and extend your application."


While the book I referenced in the talk Java Modeling in Color with UML is no longer in print, it can be sourced from Amazon if you wish to purchase a used copy. However, there is an excellent on-line resource I highly recommend authored by Stephen R. Palmer titled Peter Coad's 'Modeling in Color' which will provide all you need to get started immediately.

Books

Listed below are the three key books that got me excited (and continue to do so) about Object Modeling:

Java Modeling in Color with UML

Object Models: Strategies, Patterns, and Applications

Streamlined Object Modeling: Patterns, Rules, and Implementation

Online Resources

Peter Coad's 'Modeling in Color' authored by Stephen R. Palmer. As mentioned above, this is a great online resource to get you started today.

Streamlined Object Modeling is the book site hosted by one of the authors Mike Abney. While this is not a stand alone resource, as it does require the book to introduced some of the concepts discussed, it does provide you some insight on this specific approach buidling on Peter Coad's techniques.

Please keep in touch

I plan on expanding on this topic in the future. If you are interested please sign up so I may keep you abreast of new developments.






If there is anything else you need, please feel free to contact me directly or leave a comment below.

Wednesday, October 23, 2013

Installation instructions for Quarto on OSX

I was trying out Avdi Grimm's Quarto a week or so back for ebook generation. The toolchain looks very promising, but has a few dependencies that need to be installed before you can start publishing. These are listed in the README.

Here's a quick guide in getting those installed on OSX (Mountain Lion). Note I already had the following setup:

  • Git
  • HomeBrew
  • pygentize
  • xmllinit

Command line instructions:




The big one here is to ensure ~/.cabal/bin is in your path when you run the rake task to publish.

Tuesday, October 8, 2013

Vendoring Binaires on Heroku: An Example with Aspell

Recently I needed to install the Aspell library on Heroku for a side project. By default a Heroku Dyno doesn't include any non-essential libraries so your left to install these on your own. This introduced me to the world of buildpacks and an awesome build tool that Heroku provides to get the job done.

Objective

The objective is to have a Rails application running with FFI::Aspell, a FFI binding for the Aspell library on Heroku.

Heroku Buildpacks and Vendoring Binaries

First, we need to configure Heroku to vendor binaries. The easiest way to do this is use the Vendor Binaries buildpack which allows you to extract a tarball stored on S3 into your /app directory when the application build process is triggered. This is all configured in a .vendor_urls located in the root of your application.

As Heroku only supports a single buildpack by default, we need to configure it to support multiple buildpacks. In our case, we need the Ruby buildpack in addition to the Vendor Binaries buildpack. Fortunately this is relatively easy to do when we create our new application (and can be done after the fact as well):

heroku create --stack cedar --buildpack https://github.com/dollar/heroku-buildpack-multi.git

Now we have our multi buildpack application, we can configure those buildpacks in .buildpacks:

https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
https://github.com/heroku/heroku-buildpack-ruby.git

For our vendored binaries, although we haven't built it yet, we can configure it's location on S3 in .vendor_urls:

http://your-bucket.s3.amazonaws.com/aspell-0.60.6.1.tar.gz

Commit both the .buildpacks and the .vendor_urls files to your Rails application.

Build the binary

Next we need to build the binary. First, let's download and extract the source into a temporary working directory (not in your Rails application).

mkdir ~/Code/temp && cd ~/Code/temp
curl -o aspell-0.60.6.1.tar.gz ftp://ftp.gnu.org/gnu/aspell/aspell-0.60.6.1.tar.gz
tar -xvzf aspell-0.60.6.1.tar.gz

Now, let's create a build server on Heroku. The Vulcan gem automates the process of creating the server and building the library.

gem install vulcan
vulcan create vulcan-yourname

Now we're ready to build the binary:

vulcan build -s ~/Code/temp/aspell-0.60.6.1 -p /tmp/aspell -c "./configure --prefix=/tmp/aspell && make install"

You will notice that we configure the library to be installed in /tmp/aspell using the prefix option. We also need to tell Vulcan using the -p option where the compiled library will be located. At the completion of the build, a tarball is then download to your /tmp directory.

You can now copy the tarball from /tmp/aspell-0.60.6.tgz to the S3 bucket specified in .vendor_urls. Ensure the read permission on the uploaded file can viewed by "world", otherwise it won't be accessible when you deploy your application and you will receive the following errors:

-----> Found a .vendor_urls file
       Vendoring http://yourbucket-heroku.s3.amazonaws.com/aspell-0.60.6.tgz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Exiting with failure status due to previous errors

 !     Push rejected, failed to compile Multipack app

Build the supporting dictionary files

Typically we would be done at this point, but we need to compile the dictionary files that Aspell uses separately. This makes the process a little more complicated.

We're going to use our Vulcan build server to compile the dictionary files. This requires starting up a shell, downloading the Aspell tarbar we built previously and extracting it into the original installation directory.

heroku run bash --app vulcan-yourname
cd /tmp
mkdir aspell && cd aspell
curl -o aspell-0.60.6.tgz http://yourbucket-heroku.s3.amazonaws.com/aspell-0.60.6.tgz
tar -xzvf aspell-0.60.6.tgz

Now we're ready to build the dictionary files:

export PATH=$PATH:/tmp/aspell/bin
curl -o aspell6-en-7.1-0.tar.bz2 ftp://ftp.gnu.org/gnu/aspell/dict/en/aspell6-en-7.1-0.tar.bz2
tar -xvf aspell6-en-7.1-0.tar.bz2
cd aspell6-en-7.1-0
./configure && make install

At this point you will see output similar to this:

/tmp/aspell/bin/prezip-bin -d < en-common.cwl | /tmp/aspell/bin/aspell  --lang=en create master ./en-common.rws
/tmp/aspell/bin/prezip-bin -d < en-variant_0.cwl | /tmp/aspell/bin/aspell  --lang=en create master ./en-variant_0.rws
/tmp/aspell/bin/prezip-bin -d < en-variant_1.cwl | /tmp/aspell/bin/aspell  --lang=en create master ./en-variant_1.rws
/tmp/aspell/bin/prezip-bin -d < en-variant_2.cwl | /tmp/aspell/bin/aspell  --lang=en create master ./en-variant_2.rws
...

Once the build is completed you can test Aspell is working correctly with:

echo "helloz" | aspell -a

We're almost there. Now just copy the dictionary files over to our original build for Aspell in /lib/aspell-0.60/ We will create a new tarball which includes the dictionary files:

cp *.rws *.alias *.multi *.dat ../lib/aspell-0.60/.
cd ..
tar -czvf aspell-0.60.6.tgz bin include lib share

Finally, transfer the new tarball aspell-0.60.6.tgz to your local machine and upload to S3 again replacing our original tarball.

Deployment

Before deploying you will need to configure LD_LIBRARY_PATH, the path used by the dynamic loader to load libraries into dynamically linked executables. Otherwise, the following error is raised:

aspell: error while loading shared libraries: libaspell.so.15: cannot open shared object file: No such file or directory

This is easy to do:

heroku config:add LD_LIBRARY_PATH=/app/lib

Now let's deploy our application. Remember to include the FFI::Aspell in our Gemfile and bundle. As long as you have your application setup correctly with Heroku you can then:

git push heroku

On a successful build your output will begin with the following (note the vendoring of http://your-bucket.s3.amazonaws.com/aspell-0.60.6.tgz):

-----> Fetching custom git buildpack... done
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
=====> Detected Framework: VendorBinaries
-----> Found a .vendor_urls file
       Vendoring http://your-bucket.s3.amazonaws.com/aspell-0.60.6.tgz
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-ruby.git
=====> Detected Framework: Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using Bundler version 1.3.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
       Fetching gem metadata from https://rubygems.org/..........
       Fetching gem metadata from https://rubygems.org/..
       Installing rake (10.1.0)

Test the FFI::Aspell Gem

The moment of truth! Let's run a Rails console to test the FFI:Aspell gem.

heroku run console

At the Rails console:

speller = FFI::Aspell::Speller.new('en_US', 'dict-dir' => '/app/lib/aspell-0.60')
speller.correct?('cookie') # => true

Note we need to specify the dict-dir option since the Aspell library looks for it in /tmp/aspell/lib/aspell-0.60 by default (based on the prefix option we used when we compiled it). If you were to execute the binary directly from the shell you would also need to include this option. For example:

echo "helloz" | aspell -a --dict-dir /app/lib/aspell-0.60

If you don't include the dict-dir option, the FFI:Aspell library will crash.

Troubleshooting

If you have problems, it best to try to run the Aspell library directly from the shell using the example command above.

If you receive the following error:

Error: No word lists can be found for the language "en_US".

Then the path to the dictionary files is not correct.

References

Talk: Meet Trello

A couple of months ago I gave a presentation on Trello for a lunch and learn at Dynamo. Trello is a collaborative project planning tool that I was trying out at the time. This presentation shares my findings on how to use Trello for project management in an agile development context. Enjoy!

Meet Trello from DynamoMTL on Vimeo.

Monday, October 7, 2013

Recently Launched: Quarterly Co.

My last project at Dynamo involved the porting of a Rails application integrated with Recurly to Spree for Quarterly Co., an LA-based company. Quarterly is a subscription service, curating gifts by their selection of contributors shipped every three-months. Check out this beautifully written blog post written by Quarterly's founder, Zach Frechette, describing why he started Quarterly.

Key Objective

The key objective for this project was to move from their current model of billing their subscribers every three-months, to billing when a curated gift is shipped. Moving to this model also required some solid order management that their current application didn't provide. Spree, an open source e-commerce platform, was the chosen as the foundation for Quarterly's online business.

Technical Challenges

There were some interesting technical challenges for this project that included:

  • Customizing Spree's "Product and Order"-based data model to support subscriptions.
  • Migrating subscription data from two data sources, Recurly and the custom Rails application.
  • Migrating an existing design to Spree's opinionated checkout flow.

Check out the screenshot's below or visit the site, you might find a contributor that you want to subscribe to. Treat yourself!

(A shout out to Rodrigo Dalcin, a Front-end Developer at Dynamo, who worked porting the front-end to Spree for this project. Thank you for all your help!)

Home Page

Home Page

Contributor's Page

Contributor's Page

Rails: undefined method `action' for YourController:Class

You will receive this error if you have created your controller class manually (i.e. without the Rails generators) and have not inherited from ApplicationController. For example


This is easily fixed by adding ApplicationController as the parent. Note the change on line #1.

Developing Ruby on Rails applications and custom Content Management Systems in Montréal. Contact Firsthand.