View

How to deal with strange errors from WEBrick

If you get errors from your development WEBrick that contain unicode salad, you are probably requesting the page via SSL. \
Since WEBrick does not speak SSL, so change the URL in your browser to use http instead of https.

The error looked like this for me:
```text
[2012-09-06 11:19:07] ERROR bad URI \000\026\000\020\000'. [2012-09-06 11:19:07] ERROR bad URI \000\026\000\020\000'.
[2012-09-06 11:19:07] ERROR bad Request-Line \026\003\001\000�\001\000\000\177\003\001PHj�\031\006�L��'. [2012-09-06 11:19:07] ERROR bad URI \000\026\000...

Be careful when using Unicode symbols for graphical elements

There are many fun Unicode characters like ▲ or ☯. You might be tempted to use them for graphical elements in lieu for an image. After all they are so much easier to style and scale than a raster image!

Unfortunately you will discover that these symbols render very differently on Linux, Windows and MacOS. The reason for this is that the font you are using will probably not contain any characters outside the standard Latin-1 set. When browsers encounter a character not included in the current font, they use a fallback font for this one cha…

RSpec and Cucumber: Shorthand syntax to run multiple line numbers in the same file

This works in modern RSpecs (RSpec >= 2.x) and Cucumbers:

rspec spec/models/node_spec.rb:294:322
cucumber features/nodes.feature:543:563:579

Also your features should be shorter than that :)

Git: When committing, check the diff

When committing, you should always check the diff of your changes so you don't include any leftovers or irrelevant/bad changes. Any time spent on that is well invested as it saves you rejected merge requests or any mess you need to clean up later.

While you can just use git diff or git diff --cached (to diff staged changes), you can also have Git include the changes as a comment below the commit message:

git commit -v

That will open up the usual commit "file" in your preferred text editor, but it will include a diff below the s…

External content

ActiveRecord::SpawnMethods

Methods to remove e.g. order or conditions from an existing scope chain.

Rspec shared example group error: ensure_shared_example_group_name_not_taken

Never name your shared example group *_spec.rb. Otherwise rspec will try to load your example group as a spec and you will get the error above.

How to test print stylesheets with Cucumber and Capybara

A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they are quickly forgotten and nobody bothers to check if their change breaks the print stylesheet.

This card describes how to write a simple Cucumber feature that tests some aspects of a print stylesheets. This way, the requirement of having a print stylesheet is manifested in your tests and cannot be inadvertedly removed from the code.

Our example —…

External content

Flat Icons & Icon Fonts | CSS-Tricks

Nice list of icon sets that come in the form of fonts.

I recommend Font Awesome.

Impressumspflicht bei Facebook & Twitter: Schnelle Info und Abhilfe

Jedes nicht rein private Profil auf Social Media Portalen muss ein Impressum haben, das heißt insbesondere Unternehmen und Freiberufler (§ 5 Abs.1 TMG). Wer das Impressum dort nicht unter einem eigene Button mit der Aufschrift “Impressum” oder “Kontakt” unterbringt, bietet eine große Angriffsfläche für Abmahner (Quelle: http://rechtsanwalt-schwenke.de/impressumspflicht-bei-google-plus-und-twitter/).

Hier also in kurzen Schritten, wie man ein Impressum erstellt und wie man es bei Facebook und Twitter einbindet:

#1. Impressum erstellen

Ic…

SSL certificate problem, when trying to install the libyaml package

I was experiencing the following problem:

 It seems your ruby installation is missing psych (for YAML output). 
 To eliminate this warning, please install libyaml and reinstall your ruby

So I tried to install the libyaml package via:

rvm pkg install libyaml

This is when I experienced the SSL certification problem mentioned above. This happens when your RVM certificates have expired. You can fix this by updating them via:

 rvm get stable

After doing that curl could verify the SSL certificate and I w…

Understanding the Selenium error "Modal Dialog Present"

So your Cucumber feature sometimes dies with this exception:

Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)

As a seasoned Selenium vetaran you are used to misleading error messages. Hence you might be surprised that the reason for this particular error is that there is actually a modal dialog present and preventing Selenium from executing commands like click or page.have_css?.

How your code triggers this issue

The reason why a dialog is shown is somewhat fucked …

Reset mysql root password

Stop the MySQL Server.

sudo /etc/init.d/mysql stop

Start the mysqld configuration.

sudo mysqld --skip-grant-tables &

Login to MySQL as root.

mysql -u root mysql

Replace YOURNEWPASSWORD with your new password!

UPDATE mysql.user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;

If this fails (ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)):
Login into the mysql database with the debian-sys-maint user (you find the password in /etc/mysql/d…

How to install GNOME classic desktop in ubuntu 12.04

Run

sudo apt-get install gnome-session-fallback

or (alias)

sudo apt-get install gnome-panel

from a terminal.
Then logout to reach the logon screen and click on the options button next to you name.
Select Gnome Classic, log in et voilà.

Scoping a sunspot solr search by text using a string field

Assuming the following sunspot setup of the post class:

class Post < ActiveRecord::Base
  searchable do
    text :title
    string :state
    integer :category_ids
  end
end

In Sunspot you can scope your search via the with method. It allows you to do stuff like:

Post.search {
  fulltext "your query", :fields => :title
  with(:category_ids).any_of([1,2,3,4,5])
}

If you want to scope your search based on a text field, you have to add another field of the type string (such as the state fi…

How to inspect controller filter chains in specs

Sometimes you need to look at the filter chain in specs. You can do it like that on Rails 2:

controller.class.filter_chain.map(&:method)

Note that we need to look at the controller's class since before_filter and after_filter stuff happens on the class level.

Also mind that the above code will give you all filters, both those run before and after an action. You can query before? and after? on the filter objects to scope down to only some of them:

controller.class.filter_chain.select(&:before?).map(&:method)

For Rails 3, …

How to fix: Firefox uses incorrect fonts on all webpages, regardless of their CSS

If you encounter a Firefox that does not care about your font settings but always uses specific fonts, you can fix that. Usually this should not happen, as it's not a default setting:

  1. Open up the Preferences.
  2. Switch to "Content".
  3. In the "Fonts & Colors" section, click the "Advanced…" button.
  4. Tick "Allow pages to choose their own fonts, instead of my selection above".
  5. Confirm by pressing "OK".
External content

Rails, callbacks, workers, and the race you never expected to lose « Logical Friday

How delayed jobs can make your after_save callbacks execute before the record is saved.

View
3105 cards