Show MySQL process list without sleeping connections
Usually you don't need to, but when you want to see which queries your MySQL server currently needs to handle (and if there are locks, etc), you could say SHOW PROCESSLIST
in a MySQL shell.
Unfortunately, SHOW PROCESSLIST
does not allow filtering. When you are on MySQL ≥ 5.1.7, do this instead:
SELECT * FROM information_schema.processlist WHERE command != 'Sleep' ORDER BY id;
That also allows you to only show some values or order differently, like so:
SELECT user, time, state, info FROM information_schema.processlist WHERE co...
Change how Capybara sees or ignores hidden elements
Short version
- Capybara has a global option (
Capybara.ignore_hidden_elements
) that determines whether Capybara sees or ignores hidden elements. - Prefer not to change this global option, and use the
:visible
option when callingpage.find(...)
. This way the behavior is only changed for this onefind
and your step doesn't have confusing side effects. - Every Capybara driver has its own notion of "visibility".
Long version
Capybara has an option (Capybara.ignore_hidden_elements
) to configure the default...
Hack-fix Selenium::WebDriver::Element#select is deprecated
In some older Capybara versions (e.g. 0.3.9), we're getting lots of deprecations warnings:
Selenium::WebDriver::Element#select is deprecated. Please use Selenium::WebDriver::Element#click and determine the current state with Selenium::WebDriver::Element#selected?
Hani-elabed on Github helps. Add this code to features/support/env.rb
to remove them temporarily:
# June 30th, 2011
# a temporary hack to disable the annoying upstream warnings capybara > selenium-webdriver 0.2.2
# capybara folks know about this and are working on it. S...
VirtualBox host IP address and hostname
When you are using NAT in your virtual machine (which you should), the host's IP address is:
10.0.2.2
You'll need it to access shared folders or your host's web server when testing pages in IE.
Fun fact: You could also use vbox.srv
-- that's the corresponding hostname.
Customize path for Capybara "show me the page" files
When you regularly make use of Cucumber's "show me the page" step (or let pages pop up as errors occur), the capybara-20120326132013.html
files will clutter up your Rails root directory.
To tell Capybara where it should save those files instead, put this into features/support/env.rb
:
Capybara.save_and_open_page_path = 'tmp/capybara'
Connecting the "sequel" gem to MSSQL via ODBC
After you configured your ODBC describe in
- Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
- and Connecting to MSSQL with Ruby on Ubuntu - lambie.org
you can connect with sequel
:
require "rubygems"
require "se...
Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
I followed this nice guide Connecting to MSSQL with Ruby on Ubuntu - lambie.org until I ran in the following errors:
irb(main):001:0> require "dbi"; dbh = DBI.connect('dbi:ODBC:MyLegacyServer', 'my_name', 'my_password')
DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV
from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect'
from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect'
from /usr/lib/ruby...
Linux: Mount second encrypted HDD automatically without entering a password
This is one possibility to do this. There are other and maybe even better ways to do this.
-
Generate a key for your encrypted harddisk:
dd if=/dev/random of=/home/bob/keyfile_sdb1 bs=4096 count=1
-
Then add your keyfile to encrypted harddisk: How to change your dm-crypt passphrase (step 3)
-
Create a mountpoint:
mkdir /mnt/space
-
Create a script e.g. in your homedirectory (/home/bob/mount_sdb1.sh):
#!bin/bash ...
MySQL shell: Enable UTF-8
When you do a script/dbconsole -p
, your MySQL shell will already be using UTF-8. When you call it yourself using mysql
, it may not be enabled.
You'll notice that when you get ASCII salad and/or question marks instead of special characters. \
Example: Hlavn� m?sto Praha
instead of Hlavní město Praha
.
You need to manually switch on UTF-8, in the MySQL console:
SET NAMES 'utf8';
Render Single-Line Markdown Text with Redcarpet
We love Markdown. We use it wherever we can for text formatting. In a web app, the obvious place for it is in large text areas, where we can allow complete freedom of formatting. Headers, paragraphs, lists, it’s all good.
What about the formatting of text in single-line text fields? If our form entry is a single line, that’s usually how its text will be displayed in our interface. In this case, we probably want to avoid all the block-level elements that Markdown will let the user create.
Ruby, Ruby on Rails, and _why: The disappearance of one of the world’s most beloved computer programmers
Nice article to educate your non-geek girlfriend/boyfriend about the joys of programming.
Capybara: Test that a string is visible as static text
This is surprisingly difficult when there is a <textarea>
with the same text on the page, but you really want to see the letters as static text in a <p>
or similiar.
The step definition below lets you say:
Then I should see the text "foo"
You should not look too closely at the step definition because when you see the light, it will blind you.
Then /^I should see the text "(.*?)"$/ do |text|
elements = page.all('*', :text => text).reject { |element| element.tag_name == 'textarea' || element.all('*', :text => text...
Fix error: rails console - no such file to load -- readline
Install libreadline:
sudo apt-get install libreadline-dev
Reinstall the ruby and tell rvm where to find readline
rvm reinstall 1.8.7 --with-readline-dir=/usr/include/readline
Make sure you get a huge cup of tea before running the command above! It will take some time.
References
- github issue
- stackoverflow
- [rvm documentation](https://rvm.beginrescueend.com/pack...
Bundler 1.1 has been released, is very fast
Bundler 1.1 has been released. With this version you no longer need to wait for this:
Fetching source index…
The new Bundler is smarter and can fetch required metadata in a few seconds.
You can install the new version by saying:
sudo gem install bundler
Install the typhoeus gem with native extensions
If you get this:
Installing typhoeus (0.3.3) with native extensions
/usr/local/lib/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby1.8 extconf.rb
checking for curl/curl.h in /opt/local/include,/opt/local/include/curl,/usr/include/curl,/usr/include,/usr/include/curl,/usr/local/include/curl... no
need libcurl
You can fix it by installing the libcurl3-dev
package:
sudo apt-get install libcurl3-dev
Now you should...
responsive.is
Online tool to test how a site behaves in popular desktop, tablet and phone resolutions.
Sass: Use black or white foreground color depending on the lightness of the background
This article shows how to create a Sass mixin for a colored button. The button's foreground color is dynamically chosen between either black or white, depending on the given background color.
It's a nice intro into @if
and @else
conditionals in Sass.
Find out your SSH key's fingerprint (e.g. to authenticate on GitHub)
If you want to know your public key's fingerprint, do this:
ssh-keygen -lf ~/.ssh/my.key.pub
This may be necessary to authenticate your key on GitHub because of recent events -- you need to do that if you get an error like this when talking to them (to pull etc):
ERROR: Hi foobear, it's GitHub. We're doing an SSH key audit.
Please visit https://github.com/settings/ssh/audit/...
to approve this key so we know it's safe.
Fingerprint: ab:cd:ef:...
fatal:...
Setup or update Passenger to use Ruby Enterprise
- Your current
ruby
must be Ruby Enterprise. gem install passenger
passenger-install-apache2-module
- Edit your
httpd.conf
according to the instructions provided at the end of the setup script. - Restart Apache:
sudo service apache2 restart
This also works when you previously ran your Passenger using MRI. Just run the setup as described.
Spec "content_for" calls in helpers
This only applies to RSpec below version 1.3.2. The issue has been fixed in RSpec 1.3.2, and most likely RSpec 2 and later versions.
When you have a helper that calls content_for
and want to check its behavior you should probably write a feature instead. If you still want to do it, mind the following.
Consider this helper:
module LayoutHelper
def title(string)
content_for :title, string
string
end
end
Somewhere in the layout we'd then say something like this: `<%= yield :title %...</p>
RubyMine: Disable window animations
Under Settings / Appearance you can uncheck a box Animate windows. This will change your life.
This setting seems to not exist anymore.
Gherkin: Error during installation
When trying to install the gherkin gem, you might encounter an error with the following lines:
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
...
checking for main() in -lc... yes
creating Makefile
...
cc1: all warnings being treated as errors
Makefile:150: recipe for target 'gherkin_lexer_ar.o' failed
make: *** [gherkin_lexer_ar.o] Error 1
...
If upgrading is not an option, configure build options for gherkin
:
bundle config --local build.gherkin --with-cflags=-w
Your .bundle/config
fi...
Debugging Google Analytics
If you need to debug Analytics tracking, consider using this chrome extension. It will replace the tracking code with a debug version that prints debugging info to the JavaScript console.