Protip: Always leave a failing test
Mornings can be rough. To make them a little easier, leave yourself a failing test if your work isn’t finished. When you come back to the project, it makes it much easier to understand where you were and figure out what you still need to do.
Resolving Element cannot be scrolled into view (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError) on Mavericks
After I upgraded to Mac OS X Mavericks, I regularly got this error message when running Cucumber features with Selenium:
Element cannot be scrolled into view:[object XrayWrapper [object HTMLInputElement]] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)
I had the Terminal window running the test on my secondary screen, whereas the Selenium-webdriven Firefox always started on my primary one. Now if I had focused the secondary screen when running the tests, Selenium could not start Firefox and switch to it (probably because t...
We are not normal people
Nice thoughts about marketing and sales for developers.
Ruby number formatting: only show decimals if there are any
Warning: Because of (unclear) rounding issues and missing decimal places (see examples below),
do NOT use this when dealing with money. Use our amount helper instead.
In Ruby, you can easily format strings using % (short for Kernel#sprintf):
'%.2f' % 1.23456 #=> 1.23
'%.2f' % 2 #=> 2.00
However, what if you only want the decimals to be shown if they matter? There is g! It will limit the total number of displayed digits, disregarding...
[Openstack] "Failed to schedule_prep_resize: No valid host was found." when trying to resize an instance
If you get this error while trying to resize an openstack instance:
# nova resize fooinstance 16 --poll
==> /var/log/nova/nova-scheduler.log <==
2014-01-30 17:40:34 WARNING nova.scheduler.manager [req-aaaaaaa-bbbb-cccc-dddd-1ed34b64adef bajd7394hftgs71dba31d642342effa0f bfe2djhg6538sg384jgb82ks070ce0b] Failed to schedule_prep_resize: No valid host was found.
2014-01-30 17:40:34 WARNING nova.scheduler.manager [req-aaaaaaa-bbbb-cccc-dddd-1ed34b64adef bajd7394hftgs71dba31d642342effa0f bfe2djhg6538sg384jgb82ks070ce0b] Setting ...
git: How to forget a recorded resolution
If you recorded a bad fix for a conflict, you can tell git to forget that bad resolution:
git rerere forget your_file.rb
Afterwards, the badly resolved file will still be in your working directory. To get it back with confict markers, say:
git checkout -m your_file.rb
Resolve the conflict again, properly now. ;)
ActiveRecord's where.not
Rails 4.0 introduced a helpful new method for ActiveRecord queries: where.not. It can make clunky queries easier to read.
Trailer, a faster and easier way to deal with pull requests
Introducing Trailer from HouseTrip, a simple menu bar app that helps you manage your GitHub pull requests. It’s one feature we felt was lacking from our workflow!
rbenv: How to switch to another Ruby version
If you want to switch to another ruby versions, you have several options, depending on what you want: Do you want to switch temporarily, per project, or globally?
Here is a short guide.
Unlike RVM, rbenv does not offer a command like rvm use. By default, it respects your project's .ruby-version file.
If you need to change manually, you have several options:
rbenv shellrbenv localrbenv global
You probably want rbenv shell.
How to switch your Ruby version temporarily: rbenv shell
In case you only want to...
Code Colorizer Formatter — LibreOffice Extensions
Colorizes code in LibreOffice Writer.
Note that you need to create a paragraph style _code for this to work.
krisleech/wisper
Publish/subscribe for Ruby classes. Bonus: You do not have to declare events before using them.
Bash: Setting the title of your terminal tab
If your terminal has many tabs, you'll want to keep them organized. To change their title from the prompt, run this function:
function tab_title {
if [ -z "$1" ]
then
title=${PWD##*/} # current directory
else
title=$1 # first param
fi
echo -n -e "\033]0;$title\007"
}
Put it into your ~/.bashrc to have it always available. Adjust to your needs.
Usage
$> tab_title
# title set to the current directory's name
$> tab_title new_title
# title set to "new_title"
Auto-setting the title
=================...
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:
- Open
~/.rbenv/plugins/ruby-build/share/ruby-build/ree-1.8.7-2011.03 - Replace the file's contents with those from fgrehm's gist
-
rbenv installagain
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 ...