Spritz has popularized RSVP, a technique for comfortably increasing reading speed.

1. Download or grab a local PDF of an eBook that I want to read

2. Use an online converter for PDF to ePub (such as Online Convert)

3. Sign up at Fastr to upload the ePub version

4. Download the fastr app

5. Sign into the account (via mobile)

6. Profit! Start using RSVP on eBooks


I am not affiliated with Spritz or Fastr.io in any way. Just a developer that almost recreated the wheel. I found this (albeit complicated) solution while doing technical research.

There’s still an opportunity to simplify the process. I don’t think that Amazon will accommodate RSVP anytime soon.

Meaning is more dispersed in books than articles, which is why I feel that eBooks are the best use of this technology.

What else? Hit me up on Twitter (@DruRly)

People often use %:p:h to retrieve their current path in vim.

You can use :set acd to automatically perform this task. acd is shorthand for autochdir. With this option set, you will always be placed on the same path as your current file.

Commands such as :tabnew or :tabedit reveal that your path is no longer static, instead it inherits from your current file’s path.

For more information, run :help acd.

Yesterday I had an issue using AngularJS’s $http.jsonp method to fetch data from a separate API service which I built.

It turns out that the issue was with my API and not the client.

I had to add cross-domain JSONP support.

api_controller.rb
1
2
3
...
render :json => @items.to_json, :callback => params[:callback]
...

Source: JSONP in Rails

Timerizer gives you Rails-like time helpers without Rails.

> Time.now
#=> 2013-07-10 12:31:50 -0400

> 5.days.ago
#=> 2013-07-05 12:31:43 -0400

Libraries such as these become increasingly important as developers adopt a (only use what I need) approach to development.

While building an API with Sinatra, you can use Timerizer without regretting your decision to forgo the weight of a Rails app.

I recently messed up my .vimrc file while trying to add some productivity hacks.

It took a major scare for me to invest the effort in figuring out how to symlink my .vimrc file. I needed version control.

Here are the summarized steps that I took:

$ cd
$ mv .vimrc .vim/
#=> Move your .vimrc file into the .vim/ directory

$ cd .vim/
$ git init
$ git add .
$ git commit -m "First Commit"
#=> Get your .vim/ directory under version control

$ cd
$ ln -s ~/.vim/.vimrc .vimrc
#=> Go to your home directory and symlink the version controlled .vimrc

Yeoman ships with Twitter Bootstrap’s responsive CSS but this functionality is not enabled by default.

To enable responsiveness modify main.scss as shown below:

main.scss
1
2
3
4
@import "compass_twitter_bootstrap";
@import "compass_twitter_bootstrap_responsive";

...

Yesterday I received a great question regarding one of my posts on using around hooks in Rspec.


I’m interested as to what use you would personally use this for.
Can you recommend any use in particular you like?


Below I demonstrate two use cases for around hooks:

1. VCR

VCR automatically stores HTTP responses to prevent your tests from hitting the network each time.

I love VCR but despise the effort required to name each cassette. I took an idea from Ryan Bates and decided to use around hooks to have these cassettes automatically named.

Typical VCR Setup:

1
2
3
4
5
6
7
8
it "shows Beverly Hills given 90210" do
  VCR.use_cassette "zip_code/90210" do
    visit root_path
    fill_in "zip_code", with: "90210"
    click_on "Lookup"
    page.should have_content "Beverly Hills"
  end
end

The typical VCR setup requires that you name the file where the HTTP response will live. I’m too lazy to accept this.

My VCR Setup:

1
2
3
4
5
6
it "shows Beverly Hills given 90210", :vcr do
  visit root_path
  fill_in "zip_code", with: "90210"
  click_on "Lookup"
  page.should have_content "Beverly Hills"
end

I simply pass :vcr after the description for automatic file naming. This is accomplished by using around hooks in my spec_helper.rb file. Check out the code below:

spech_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
RSpec.configure do |config|
  ...
  config.treat_symbols_as_metadata_keys_with_true_values = true

  config.around(:each, :vcr) do |example|
    name = example.metadata[:full_description]
      .split(/\s+/, 2)
      .join("/")
      .gsub(/[^\w\/]+/, "_")
    VCR.use_cassette(name, record: :new_episodes) do
      example.call
    end
  end
  ...
end
...

Note: More info on the method chaining trick used above.

These integration tests are making API calls. VCR captures and replays the response on subsequent test runs.

The code above allows me to pass :vcr to the example when I want the HTTP response captured by VCR.


2. Proxy

I have also used around hooks for proxing in my tests. If you want to do any type of scale testing with real data, you can mask your IP to collect the information.

Here’s the typical setup for doing such a thing:

1
2
3
4
5
6
7
it "masks my ip to visit google" do
  tor = Tor.new
  tor.proxy_mechanize do
    visit 'http://www.google.com'
    page.should have_content "Gmail"
  end
end

My setup:

1
2
3
4
it "masks my ip to visit google", :proxy do
  visit 'http://www.google.com'
  page.should have_content "Gmail"
end

Here’s the spec_helper.rb file that allows me to do this:

spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
RSpec.configure do |config|
  ...
  tor = Tor.new

  config.treat_symbols_as_metadata_keys_with_true_values = true

  config.around(:each, :proxy) do |example|
    tor.proxy_mechanize do
      example.call
    end
  end
  ...
end
...

I have also combined these hooks to store the response of a proxied request.

1
2
3
4
5
6
...
it "masks my ip and stores the response", :vcr, :proxy do
  visit 'http://www.google.com'
  page.should have_content "Gmail"
end
...

Thanks for the great question Brett!

I ran into a bower issue while running grunt test on a new yeoman/angular project.

The error read:

"app/bower_components/angular/angular.js" does not match any file."

I noticed that I didn’t have a bower_components directory but I did have a components directory.

I changed my karma.conf.js file to watch components and waited for something to blow up.

I was able to run grunt test without any issues. This has been working for a couple of days without any side effects.

$ git diff

diff --git a/karma.conf.js b/karma.conf.js
index ffd77ce..f4ca129 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -7,8 +7,8 @@ basePath = '';
 files = [
   JASMINE,
   JASMINE_ADAPTER,
-  'app/bower_components/angular/angular.js',
-  'app/bower_components/angular-mocks/angular-mocks.js',
+  'app/components/angular/angular.js',
+  'app/components/angular-mocks/angular-mocks.js',
   'app/scripts/*.coffee',
   'app/scripts/**/*.coffee',
   'test/mock/**/*.coffee',

I received this error while writing controller tests for an API. ActionController::UnknownFormat was introduced with Rails 4 and has not been well documented yet.

Here’s how I resolved the issue.

Doesn’t Work

controller_spec.rb
1
2
3
  ...
  post :create, title: "Example Title", body: "Example body"
  ...

Works

controller_spec.rb
1
2
3
  ...
  post :create, post: { title: "Example Title", body: "Example body" }
  ...

You may still face an ActiveModel::ForbiddenAttributesError but that’s a different issue requiring that you address strong_params.

Haml support isn’t built into yeoman so I had to practice a bit of hackery to get my preferred setup.

It took about a hour to figure this out but infrastructure tasks are worth the effort.

Here are some notes from the process:


About the Gruntfile:

Load grunt-haml in module.exports

1
2
3
...
grunt.loadNpmTasks('grunt-haml');
...

Add a task inside of grunt.initConfig

1
2
3
4
5
6
...
 haml: {
   files: ['<%= yeoman.app %>/views/*'],
   tasks: ['haml']
 },
...

Detect haml file extensions for livereload

1
2
3
4
5
6
7
8
9
10
11
...
livereload: {
  files: [
    '<%= yeoman.app %>/{,*/}*.{html, haml}',
    '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
    '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
    '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  ],
  tasks: ['livereload']
}
...

Set haml file targets

1
2
3
4
5
6
7
8
9
10
11
12
...
haml: {
  index: {
    src: "app/index.haml",
    dest: "app/index.html"
  },
  main: {
    src: "app/views/main.haml",
    dest: "app/views/main.html"
  }
}
...

It would be nice to have dynamic file targeting.

Check out this thread for more information.

“You need to have Ruby and Compass installed and in your system PATH for this task to work.”

I received this error while generating a yeoman project. This message is extremely confusing for Mac users because they already have Ruby installed.

Run gem install compass to get past this issue.

Linkback: Original

I decided to use yeoman for a new AngularJS project and ran into this issue when generating a project with yo angular [APPNAME].

Many times this error results from a path issue. My case was different in that I assumed angular-generator would install the dependency yeoman for me.

If you have exhausted the path solutions or identified that you do not have a path issue. Ensure that you have yeoman installed.

1
npm install -g yo

Well all know about before_each and after_each but you can also wrap your tests in blocks for VCR cassettes or proxying requests.

This can be accomplished within your spec_helper.rb or a specific file.

Examples

Within Rspec.config spec_helper.rb:

...
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :two_times) do |example|
  2.times do
    example.call
  end
end
...

Tests are wrapped when :two_times is passed in.

...
it "confirms the obvious", :two_times do
  15.should == 15
end
...

Within a spec file:

...
describe "around filter" do
  around(:each) do |example|
    puts "around each before"
    example.run
    puts "around each after"
  end

  it "gets run in order" do
    puts "in the example"
  end
end
...

Gemrat is now better thanks to @shime, @mivanek, @bloudermilk, and @timmow.

Version 0.3.0 introduces some new features:

1. Multiple Gem Support

$ gemrat rspec capybara sidekiq

#=> gem 'rspec', '2.13.0' added to your Gemfile.
#=> gem 'capybara', '2.1.0' added to your Gemfile.
#=> gem 'sidekiq', '2.12.4' added to your Gemfile.
#=> Bundling...

2. Usage (Help)

$ gemrat --help OR gemrat -h

Gemrat

Add gems to Gemfile from the command line.

Usage: gemrat [GEM_NAME] [OPTIONS]

Options:

  -g [--gemfile]  # Specify the Gemfile to be used. Defaults to 'Gemfile'.
  -h [--help]     # Print these usage instructions.

3. Gem not found - Error Handling

$ gemrat im_not_real

Unable to find gem 'im_not_real' on Rubygems. Sorry about that.

Thanks to Ruby Weekly and the reddit/ruby community for introducing gemrat to developers.

I published a gem earlier this week which allows developers to add gems to their Gemfile from the command line. The utility of Gemrat lies in it’s ability to grab the latest version of a gem and lock it into your Gemfile.


Example

$ gemrat sinatra

#=> gem 'sinatra', '1.4.3' added to your Gemfile.
#=> Bundling...

$ gemrat rspec

#=> gem 'rspec', '2.13.0' added to your Gemfile.
#=> Bundling...

Github Page


Inspiration

Lately I’ve been taking a service oriented approach to developing software. This means that I build smaller apps which depend on each other rather than having a huge monolithic codebase.

This approach lends itself to reusability, polyglot programming, and it gives me more chances to implement lessons learned from previous applications.

The service oriented approach also carries some debt. I’m often wrangling dependencies as I rebuild infrastructures. Developers working on monolithic apps with lots of legacy code can go days or weeks without adding dependencies. This is usually not the case in service oriented architectures.

The manual process of adding gems usually involves searching for the latest version of a gem then adding the gem and it’s version to the Gemfile. This process calls for a browser and text editor.

The same result can now be accomplished by running $ gemrat gem_name from your command line.

I use this tool on a daily basis. Solving my own problems and sharing solutions with the world is extremely gratifying work.

Enjoy!

You can use Amazon Glacier. Here are the steps in summary:

  1. Open your bucket

  2. Click “properties”

  3. Click “Lifecycle”

  4. Click “Add Rule”

  5. Click “Move to Glacier”

  6. Fill out the rule form

  7. Apply the changes

More details here.

Here’s a basic pattern for running Sinatra with Puma.

config.ru

1
2
require './app'
run Sinatra::Application

Gemfile

1
2
gem "sinatra"
gem "puma"

app.rb

1
2
3
4
...
require 'sinatra'
configure { set :server, :puma }
...

The next time that you run ruby app.rb, it will use Puma instead of WebBrick.

“Please point sidekiq to a Rails 3 application or a Ruby file to load your worker classes with -r DIR|FILE.”

I received this error while attempting to use Sidekiq in a Sinatra app. To solve this problem, use the -r option to point Sidekiq to your main Sinatra file.

1
2
3
...
`sidekiq: bundle exec sidekiq -r ./app.rb`
...

The -r option is also used by pry to preload dependencies.

pry -r ./app.rb gives you access to all our your methods in app.rb without the need to require it via console.