Evening on Backbone.js/Views w/ Q&A with David Heinemeier Hansson - YouTube
Interesting interview with DHH, where he talks about how they made the new Basecamp feel very fast without using a lot of Javascript (most of Basecamp still lives on the server). The two tricks they used are PJAX and Russian Doll Caching.
defunkt/jquery-pjax
pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades.
pjax enhances the browsing experience - nothing more.
Beware of magic adblocker rules
If a customer calls and tells you that she cannot see some content of her website beware of the following before starting tcpdump or other forensic debugging tools.
Some ad blockers like Adblock are shipped with filters that remove (amongst others)
-
divsnamed'sponsor' - images with a class
"banner"or the filename"banner.png" - images from directories named
'sponsor*' - Image names or class names that begin with
adv_....
Renaming the div to something more specific to your site and renaming...
How to fix gsub on SafeBuffer objects
If you have an html_safe string, you won't be able to call gsub with a block and match reference variables like $1. They will be nil inside the block where you define replacements (as you already know).
This issue applies to both Rails 2 (with rails_xss) as well as Rails 3 applications.
Here is a fix to SafeBuffer#gsub. Note that it will only fix the $1 behavior, not give you a safe string in the end (see below).
Example
def test(input)...
Hack of the day: Find all classes that define a method with a given name
If (for some reason that you don't want to ask yourself) you need to know all classes that define a method with a given name, you can do it like this:
def classes_defining_method(method_name)
method_name = method_name.to_sym
ObjectSpace.each_object(Module).select do |mod|
instance_methods = mod.instance_methods.map(&:to_sym) # strings in old Rubies, symbols in new Rubies
(instance_methods & [method_name]).any? && mod.instance_method(method_name).owner == mod
end
end
So, when we want to know all...
Boolean fields in migrations
If you want to update some records with boolean fields in a migration, always remember to set your values with field=#{quoted_true} and field=#{quoted_false}. The Rails methods quoted_false and quoted_true return the correct boolean representations for your database.
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:
[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\...
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. Note that you can...
Reset mysql root password
This article describes how to reset MySQL's or MariaDB's root password on your workstation. It's meant for local development purposes only, don't do this in production. This article will also help you if you have a fairly recent MariaDB version that uses authentication based on linux users instead of passwords for the root user and you prefer using a password for root.
Solution
Step 1 is getting a root mysql shell that allows us to change user credentials. We need to stop the mysql daemon first and re-start it without authorization c...
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...
Flat Icons & Icon Fonts | CSS-Tricks
Nice list of icon sets that come in the form of fonts.
I recommend Font Awesome.
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à.
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 :)
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...
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...
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...
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, ...
ActiveRecord::SpawnMethods
Methods to remove e.g. order or conditions from an existing scope chain.
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...
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:
- Open up the Preferences.
- Switch to "Content".
- In the "Fonts & Colors" section, click the "Advanced..." button.
- Tick "Allow pages to choose their own fonts, instead of my selection above".
- Confirm by pressing "OK".

So your Cucumber feature sometimes dies with this exception:
Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)
As a seasoned Selenium veteran 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 ...
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.