Getting rid of space between inline-block elements

When two elements with display: inline-block are sitting next to each other, whitespace between becomes a space character.

Solutions, in decreasing order of awesomeness:

  1. Don't have whitespace between two elements! See Whitespace Removal in Haml if you're using Haml.
  2. Don't use inline-block. Use floating elements instead (don't forget to clear them!).
  3. Try to compensate for the space with a negative margin. Unfortunately you will never be able to negate ...

Font Awesome: List of Unicode glyphs and HTML entities

A list of FontAwesome icons in the form of copyable Unicode characters or HTML entities.

You might prefer to use FontAwesome by simply typing out these characters instead of using CSS classes. Of course you need to then give the containing element as style:

font-family: FontAwesome

Nested controller routes (Rails 2 and 3)

In order to keep the controllers directory tidy, we recently started to namespace controllers. With the :controller option you can tell Rails which controller to use for a path or resource. For nested resources, Rails will determine the view path from this option, too.

That means the following code in routes.rb

resources :users do
  resource :profile, controller: 'users/profiles' #[1]
end

… makes Rails expect the following directory structure:

app/
  controllers/
    users/
      profiles_controller.rb
    users_control...

Rails: Output helpers for migrations

When you're writing migrations that do more than changing tables (like, modify many records) you may want some output. In Rails > 3.1 you have two methods at hand: announce and say_with_time.

In the migration:

class AddUserToken < ActiveRecord::Migration

  class User < ActiveRecod::Base; end

  def up
    add_column :users, :token, :string
    
    announce "now generating tokens"
    User.find_in_batches do |users|
      say_with_time "For users ##{users.first.id} to ##{users.last.id}" do
        users.each do |user|
        ...

Font sizing with rem - Snook.ca

CSS3 comes with new unit rem. It works like em but it is always relative to the <html> element instead of the parent element.

rem units are supported by all browsers and IE9+.

Simple Naming for Modular CSS Class Names ··· Nico Hagenburger

An opinion how to implement BEM. I don't agree with all of Nico's choices, but I applaud his approach to compile a simple and short list of rules.

Git & Mac: Working with Unicode filenames

I had some problems with Git and the file spec/fixtures/ČeskýÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž. After pulling the latest commits, it would show that file as untracked, but adding and committing it would throw error: pathspec 'check in unicode fixture file once again' did not match any file(s) known to git.

Solution

Install Git version > 1.8.2 using homebrew and set

git config --global core.precomposeunicode true

Done.

Reason

According to the linked Stackoverflow post ...

... the cause is the different im...

The "private" modifier does not apply to class methods or define_method

Ruby's private keyword might do a lot less than you think.

"private" does not apply to class methods defined on self

This does not make anything private:

class Foo

  private

  def self.foo
    'foo'
  end
  
end

You need to use private_class_method instead:

class Foo

  def self.foo
    'foo'
  end
  
  private_class_method :foo
  
end

"private" does not apply to define_method

This does not make anythin...

Firefox file upload breaks after a few megabytes

  • A short browsing revealed that this may be a current firefox issue
  • Current workaround: use another browser
  • If you have further helpful information, please notify me

RSpec: Where to put shared example groups

Shared example groups are a useful RSpec feature. Unfortunately the default directory structure generated by rspec-rails has no obvious place to put them.

I recommend storing them like this:

spec/models/shared_examples/foo.rb
spec/models/shared_examples/bar.rb
spec/models/shared_examples/baz.rb
spec/controllers/shared_examples/foo.rb
spec/controllers/shared_examples/bar.rb
spec/controllers/shared_examples/baz.rb

To ma...

Render a view from a model in Rails

In Rails 5 you can say:

ApplicationController.render(
  :template => 'users/index',
  :layout => 'my_layout',
  :assigns => { users: @users }
)

If a Request Environment is needed you can set attributes default attributes or initialize a new renderer in an explicit way (e.g. if you want to use users_url in the template):

ApplicationController.renderer.defaults # =>
{
  http_host: 'example.org',
  https:      false,
  ...
}
...

RubyLTS

RubyLTS is a long term supported fork of Ruby 1.8 that will continue to receive security updates for the forseeable future.

Remote Debugging on Android - Chrome DevTools

The Google Chrome DevTools allow you to inspect, debug, and analyze the on-device experience with the full suite of tools you're used to, meaning you can use the Chrome DevTools on your development desktop machine to debug a page on your mobile device.

angular/angularjs-batarang

Extends the Chrome WebInspector so you can debug AngularJS applications and hunt down performance issues.

It's really, really good.

Many box shadows will make your app unusable on smartphones and tablets

Box shadows are awesome. Unfortunately they are also very costly to render. You will rarely notice the rendering time on a laptop or desktop PC, box shadows can make your app completely unusable on smartphones and tables. By "unusable" I mean "device freezes for 10 seconds after an user action".

But isn't it the future?

Not yet. Eventually mobile devices will become powerful enough to make this a no...

Git: How to remove ignored files from your repository's directory

When you have files in your .gitignore they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file system.

While a regular git clean will ignore them as well, passing the -x switch changes that:

git clean -x

If you want to see what would happen first, make sure to pass the -n switch for a dry run:

git clean -xn

Clean even harder by passing the -f (force cleaning under certain circumstances; I think this is also required by default) or -d (removes director...

Rails: Disable options of a select field

Simply give the select helper an option :disabled, passing either a single value or an array. You need to specify the option's value, not its text.

= form.select :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']

Also see Cucumber: Check if a select field contains a disabled option on how to test this.

Cucumber: Check if a select field contains a disabled option

For Capybara, use this step:

Then /^"([^"]*)" should be a disabled option for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
  with_scope(selector) do
    field_labeled(field).find(:xpath, ".//option[text() = '#{value}'][@disabled]").should be_present
  end
end

exception_notification 3.0.0+ lets you send errors as HTML e-mails

Exception notifications contain a lot of information: Backtraces, HTTP headers, etc. exception_notification tries its best to format this wall of information using ASCII art, but you can also make it send those notification as simple HTML e-mails that have some simple formatting for clarity, but no images etc. To do so, activate this option:

:email_format => :html

Those HTML notifications are still delivered with a text-only version, so if you are using a console cli...

exception_notification 4.0.0+ makes it easier to ignore errors, crawlers

The new exception_notification has awesome options like :ignore_crawlers => true and :ignore_if => lambda { ... }. These options should be helpful in ensuring every notifications means something actionable (instead of a long log of failures that just scrolls by).

Note that you should not ignore crawlers by default. Ideally, cool URLs never change and always respond with a helpful redirect or similar.

Ignore Errors like this:

# config/initializers/exception_notification.rb

Ex...

RubyMine detects syntax errors where there are none

To make this go away I had to wipe my RubyMine settings (~/.RubyMine) and configure everything again. Fun.

Webservice to mock HTTP responses

Sometimes in the course of development you may need to mock HTTP responses.

This is a simple service to return various HTTP responses.

The Chokehold of Calendars

Most people don’t schedule their work. They schedule the interruptions that prevent their work from happening.

Consul 0.9 lets you optimize records checks

Consul 0.9 comes with many new features to optimize powers that only check access to a given record. e.g. Power.current.post?(Post.last). See below for details.

Powers that only check a given object

Sometimes it is not convenient to define powers as a collection. Sometimes you only want to store a method that
checks whether a given object is accessible.

To do so, simply define a power that ends in a question mark:

class Power
  ...

  power :upd...