No more file type confusion in TextMate2

When using TextMate2 with the cucumber bundle, it does not recognize step definitions (e.g. custom_steps.rb) as such but believes they are plain Ruby files. But there is help!

Solution

Add these lines to the bottom of your .tm_properties file (in ~/ for global settings, in any directory for per-project settings):

[ "*_steps.rb" ]
fileType = "source.ruby.rspec.cucumber.steps"

Apparently, this works for any files. Define a regex and specify custom settings. The attached article lists all available configuration options (whic...

PDF Generation in Rails

A look at Prawn, PDFKit, and Wicked PDF

What's new in edge Rails: Active Record enums

Declare an enum attribute where the values map to integers in the database, but can be queried by name.

The MariaDB Foundation Announces General Availability of MariaDB 10

MariaDB 10 includes numerous innovations developed with and for web-scale players like Google, Fusion-IO and Taobao such as Replication, NoSQL Capabilities, Sharding.

Why Ruby Class Methods Resist Refactoring

In a nutshell:

  • Splitting a long method into sub methods is easier in instances since it is in classes. Since you must not save state in a class, you need to pass around context as a long chain of parameters again and again.
  • If your public API has a single entry point, you can still have a class-level method that takes care of constructing the instance etc. So it's all win.

Obfuscating data in Rails applications for screenshots and demonstrations

I recently had a need to demonstrate a data-heavy application to potential customers. Demonstrating the application with bogus numbers is one thing, but everything looks much more realistic when I’m using real data. I can’t reveal any real information, though, so I needed a quick way to obfuscate real names. Faker to the rescue!

IE10 / IE11 Metro mode: How to switch tabs or show the address bar

Internet Explorer on Windows 8 and 8.1 is available in a "Desktop version" and the metro version which is designed for touch devices. \
When using IE Metro with a mouse (e.g. via BrowserStack), controls such as the tab bar or address bar will disappear after a little while.

To show them again, right-click anywhere in the page (except on links, etc).

O_o

Thread Safety With Ruby — Luca Guidi

Ruby’s model for concurrency is based on threads. It was typical approach for object oriented languages, designed in the 90s. A thread is sequence of instructions that can be scheduled and executed in the context of a process. Several threads can be running at the same time.

Ruby’s VM process allocates a memory heap, which is shared and writable by threads. If incorrectly coordinated, those threads can lead to unexpected behaviors.

CSS: Vertically center with margin: auto

Check out the jsFiddle Demo.

CSS

.absoluteCenterWrapper {
 position: relative; /* Declare this element as the anchor point for centering */
}

/* Positioning */
.absoluteCenter {
 margin: auto; /* Required */
 position: absolute; /* Required */
 top: 0; bottom: 0; /* Aligns Vertically */
 left: 0; right: 0; /* Aligns Horizontally */
}

/* Make sure the centered element fits into its container. If you know that's the case, you can omit this part. */
.absoluteCenter {
 max-height: 100%;
 max-width: 100%;
}...

Showcases

Directory of popular Github projects.

Why your previous developer was terrible

When you, as a developer, look at the choices used to build a particular application, you’re blown away at the poor decisions made at every turn. “Why, oh why, is this built with Rails when Node.js would be so much better?” or “how could the previous developer not have forseen that the database would need referential integrity when they chose MongoDB?” But what you may not realize is that you are seeing the application as it exists today. When the previous developer (or team) had to develop it, they had to deal with a LOT of unknowns. They...

BrowserStack has browser plugins for local testing

Local testing allows you to test your private and internal servers using the BrowserStack cloud, which has support for firewalls, proxies and Active Directory.

How to remove/disable the automatic XSS protection helper html escaping for Rails 3

How to remove/disable the automatic XSS protection helper html escaping for Rails 3.

This is probably a horrible idea.

Mouse wheel + Shift key = horizontal scrolling

On Ubuntu, you can scroll horizontally with your mouse wheel when holding the Shift key while scrolling.

It does not work in all applications, but many support it.

Alternatives to drop-down menus

Alternatives to drop-down menus to consider in form design.

Count number of weekdays between two dates

If you need to quickly find out the number of weekdays (Monday to Friday) between to given dates, try this:

require 'date'
a = Date.parse "11.04.2014"
b = Date.parse "31.12.2014"

(a..b).count {|date| (1..5).include?(date.wday) }

Ruby on Rails 4 and Batman.js

Batman is an alternative Javascript MVC with a similar flavor as AngularJS, but a lot less features and geared towards Ruby on Rails.

The attached link leads to a tutorial for a small blog written with Rails / Batman.js.

I'm collecting other Batman.js resources in my bookmarks.

JavaScript: How to log execution times to your browser console

If you are trying to inspect timings in JavaScript, you can use console.time and console.timeEnd which will write to your browser console.

Example:

console.time('lengthy calculation');
lengthyCalculation();
console.timeEnd('lengthy calculation');

lengthy calculation: 1.337ms

Note that this allows using console.timeEnd in another context which is helpful when you are doing things asynchronously, or just in different places.

Works in all browsers, including recent Internet Explorers. For older IEs, you may activate...

Techniques for authentication in AngularJS applications

Article about implementing authentication (current_user) and authorization (access rights) in AngularJS.

Has an surprising amount of practical and understandable code.

Why belongs_to/has_many cannot overwrite methods with the same name

When you use a belongs_to or has_many macro you might be surprised that the methods that it generates does not override a method with the same name. Take this example:

class Project < ActiveRecord::Base
  
  def user
    "foo"
  end
  
  belongs_to :user
  
end

Project.new.user still returns "foo".

The reason for this is that what belongs_to does is actually this:

class Project < ActiveRecord::Base
  include FeatureMethods
  
  def user
    "foo"
  end
  
end

module Project::FeatureMethods

  def user
    # ass...

ActiveRecord 2.3: Nested attribute changes disappear

There is a bug in ActiveRecord 2.3.x that leads to changes in nested forms getting lost.

class Project < ActiveRecord::Base
  has_many :tasks
  accepts_nested_attributes_for :tasks
end

If you access project.tasks after setting tasks through the nested attribute logic, all tasks will be reloaded and all changes will be lost. This usually happens

  • in validations
  • in callbacks
  • after validation errors, when rendering the view again

The attached initializer fixes those issues.

Firefox: Remove dotted border from focused buttons

The following Sass will do the trick:

button,
input[type="reset"],
input[type="button"],
input[type="submit"],
input[type="file"] > input[type="button"]
  &::-moz-focus-inner
    border: none

There's also a plain CSS version.

Note that you can no longer visually navigate through a form with the keyboard without these borders.

Papertrail - Store each models version in a separate table

Store each models version in a separate table

class Post < ActiveRecord::Base
  has_paper_trail :class_name => 'PostVersion'
end

class PostVersion < Version
  # custom behaviour, e.g:
  set_table_name :post_versions
end