Pure CSS Timeline | CSSDeck

Clever hack to allow user interaction without Javascript (by using radio buttons and selecting on :checked).

How to load only a subset of a massive MySQL dump

I had a huge MySQL dump that took forever (as in: days) to import, while I actually just wanted to have the full database structure with some data to use on my development machine.

After trying several suggestions on how to speed up slow MySQL dump imports (which did not result in any significant improvement), I chose to import just some rows per table to suffice my needs. Since editing the file was not an option, I used a short Ruby script to manage that.

Here is how:

pv huge.dump | ruby -e 'ARGF.each_line { |l| m = l.match(/^INSERT ...

Installing therubyracer and libv8 with Ruby 1.8 on OSX Mavericks

There seems to be no way to use therubyracer -v '0.11.4' and libv8 -v '3.11.8.17' on OS X Mavericks.

However, running bundle update therubyracer worked for me. It installed therubyracer -v '0.12.1' and libv8 -v '3.16.14.3' and I had not side effects.


Log of my attempts to get it working

Probably you got here when bundling failed building native extensions for therubyracer.

The libv8 (3.3.10.4) should have been installed when bundling. Unfortunately it is not building correctly on Mavericks, so the libv8.a f...

pngquant — lossy PNG compressor

pngquant is a command-line utility and a library for converting 24/32-bit PNG images to paletted (8-bit) PNGs.

The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency.

MySQL 5.6 slightly changes DECIMAL data type

About

A MySQL DECIMAL column is used when it is important to preserve exact precision. It takes two parameters, where precision is the total number of digits and scale the number of digits to the right of the decimal point. A DECIMAL(6,2) column may store numbers up to 9,999.99.

In Rails, a decimal column definition looks like this: t.decimal :amount, :precision => 6, :scale => 2.

Issue

MySQL prior to 5.6 stored leading zeros (0003.1) and +/- characters (+2.1) within the column. However, **it would permit storing ...

How to install older versions of REE with rbenv on Ubuntu 12.04

Rbenv won't compile REE 2011.03 properly on Ubuntu 12.04, failing with an error in tcmalloc.cc.

If you want to keep tcmalloc functionality, you can do it like this:

  1. Open ~/.rbenv/plugins/ruby-build/share/ruby-build/ree-1.8.7-2011.03
  2. Replace the file's contents with those from fgrehm's gist
  3. rbenv install again

You could also try CONFIGURE_OPTS="--no-tcmalloc" rbenv install, but that would disable tcmalloc. Doing that, you might still encounter issues with ossl_ssl.c -- which is ...

Workflows of Refactoring

Great slide deck about various forms of refactorings.

Don't use "self" as a Javascript variable

You might sometimes use self to capture the context of this before it is destroyed by some function.

Unfortunately self is also an alias for window, the global top-level object. Save your future self some headaches and use another name like me instead (Coffeescript chose to use _this).

The new Modularity 2 syntax

We have released Modularity 2. It has many incompatible changes. See below for a script to migrate your applications automatically.

There is no does method anymore

We now use traits with the vanilla include method:

class Article < ActiveRecord::Base
  include DoesTrashable
end

When your trait has parameters, use square brackets:

class Article < ActiveRecord::Base
  include DoesStripFields[:name, :brand]
end

Note how you ...

Linux: Disable Bluetooth on startup

In /etc/rc.local add:

service bluetooth stop

Cucumber / Selenium: Access and test document title

If you want to test that a certain text is contained within the document title of your page, you can do so using Selenium and a step such as

Then /^"(.*?)" should be shown in the document title$/ do |expectation|
  title = page.driver.browser.title
  title.should include(expectation)
end

Careful with '||=' - it's not 'memoize'

When you do something like this in your code:

def var_value
  @var ||= some_expensive_calculation
end

Be aware that it will run some_expensive_calculation every time you call var_value if some_expensive_calculation returns nil.

This illustrates the problem:

def some_expensive_calculation
  puts "i am off shopping bits!"
  @some_expensive_calculations_result
end

When you set @some_expensive_calculations_result to nil, ||= runs some_expensive_calculation every time....

Choosing the Right Size and Format for Icons

Icons Sizes for Windows, MacOS X, iOS, Android and Linux. It's a mess!

Prevent long strings from stretching your <table> with CSS

  • Give the table a style table-layout: fixed
  • Give the cells in the first row a width
  • The same width will be automatically used for following rows

Opal, A new hope (for Ruby programmers)

Opal is a source to source ruby to javascript compiler, corelib and a runtime implementation that currently passes 3000 rubyspecs w/a reachable goal of passing them all.

Rails always tries to use a layout with the same name as your controller

If you have a FooController and also have a layout app/views/layouts/foo.html, Rails will use this without being told so.

This is super convenient except never.

Threads and processes in a Capybara/Selenium session

TLDR: This card explains which threads and processes interact with each other when you run a Selenium test with Capybara. This will help you understand "impossible" behavior of your tests.


When you run a Rack::Test (non-Javascript) test with Capybara, there is a single process in play. It runs both your test script and the server responding to the user interactions scripted by your test.

A Selenium (Javascript) test has a lot more moving parts:

  1. One process runs your test script. This is the process you...

Careful when writing to has_many :through associations

tl;dr: Using has_many associations with a :through option can lead to lost or duplicate records. You should avoid them, or only use them to read records.

Consider this:

class User < ActiveRecord::Base
end

class Party < ActiveRecord::Base
  has_many :invitations
  has_many :users, through: :invitations, include: :user, order: 'users.name'
end

class Invitation < ActiveRecord::Base
  belongs_to :party
  belongs_to :user
  
  after_create :send_invite
  
  def send_invite
  ...

Howto set jQuery colorbox overlay opacity

Setting the colorbox opacity by hash parameter when initializing doesn't work the way like the documentation tells you.

  $(selector).colorbox({ ..., opacity: 0.5, ... }); // has no effect

The opacity value of 0.5 will be overwritten by the inline style attribute style="opacity: 0.9" that colorbox sets.

To manually set the opacity you have to add the following css rule

  #cboxOverlay { opacity: 0.5 !important; }

Sort a Ruby array with multiple criteria

If you want to sort a Ruby array with a primary, secondary, etc. criterium, use a sort_by that contains a block:

users.sort_by { |user| [user.age, user.name] }

This trick also works with our natural sort method.

How to fix "undefined method `name' for Array" error when running bundled commands on Ruby 1.8.7 + Rails 2.3

On recent/fresh installations of Ruby 1.8.7 you may encounter this error why calling any bundled binary (or just bundle exec):

/home/arne/.rvm/gems/ruby-1.8.7-p374@global/gems/rubygems-bundler-1.4.2/lib/rubygems-bundler/noexec.rb:75:in `setup': undefined method `name' for #<Array:0x7fe04783ef30> (NoMethodError)
  from /home/arne/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `map'
  ...

Apparently, this is due to bundler (or maybe the rubygems-bundler that RVM supplies by default) no lon...

Skype screen sharing: Select which monitor to share

If you have multiple monitors and want to share a given screen with your call partner, drag the caller window to the desired monitor, then start sharing.

This is for Skype 4.2+ on Linux.

Auto-coerced virtual attributes with Virtus

We've since created ActiveType which has a restricted subset of Virtus' features. It might be enough for your needs.

We sometimes give our ActiveRecord models virtual attributes for values that don't need to be stored permanently.

When such a virtual attribute should contain integer values you might get unexpected behavior with forms, because every param is a string and you don't get the magic type casting that Rails would give you if it ...