Use this if you want to show or hide part of a form if certain options are selected or boxes are checked.
The triggering input gets an data-selects-visibility
attribute with a selector for the elements to show or hide, like
<%= form.select :advancedness, [['basic', 'basic'], ['advanced', 'advanced'], ['very advanced', 'very_advanced]], {}, :"data-selects-visibility" => ".sub_form" %>
The elements that are shown/hidden look like
<div class="sub_form" data-show-for="basic">
only shown for advancedness = basic
</div>
...
This is an awesome gadget in your toolbox, even if your test coverage is great.
gem install ruby-debug
(Ruby 1.8) or gem install debugger
(Ruby 1.9)script/server --debugger
debugger
anywhere in your codeIf you paste multiple lines of text into a cell, Calc's AutoCorrect will change the first character of the last line to uppercase:
foo => foo
bar bar
baz Baz
To fix this, go to Tools / AutoCorrect Options, choose the Options tab and uncheck every box. You're a programmer, you don't need wimpy AutoCorrect assistance.
Jonas Nicklas, the author of Carrierwave and Capybara, has released Refile, a gem for handling file uploads in Rails. It handles direct uploads (also direct uploads to Amazon S3) better than Carrierwave.
The story and reasoning behind some of the decisions in Refile, and how it's different from Carrierwave, by the author himself, is a good read before deciding which way you'll go.
Big Caveat: Refile only stores the original image and r...
Usage:
Then the "sorted" select should be sorted
But the "unsorted" select should not be sorted
Some insight into how browser rendering engines work. The article shows how the way you manipulate styles (and the DOM) can affect rendering performance by forcing the browser to re-paint large portions of the screens, or re-calculate the dimensions of a large subtree of DOM nodes.
Sequel is an awesome ORM such as ActiveRecord. The linked article describes how easily you can implement and use materialized views with postgres as your underlying database.
Want to find that repo you've starred some time ago again? Here's where to search for it.
An alternative way to browse and search through your starred repos is Astral, where you'll see the Readme for each repo in a split screen.
When navigating back to a page that was received from a POST request, undesired side effects may happen. Therefore, modern browsers try to keep users from doing so, i.e. Firefox 24 displays an error page explaining what's wrong. If the user presses "Try Again", it shows an additional alert asking whether the user is certain.
If you need to circumvent this protection, e.g. to test that your application behaves correctly despite being misused, do this:
page.execute_script 'history.back()'
page.execute_script 'retryThis(this)...
ImageMagick takes a string with several options when cropping an image. See the command line options for how to provide the expected image geometry for details.
Note that ImageMagick tends to preserve the original aspect ratio of the source image automatically.
Examples:
crop 200x200
means Maximum values of height and width given, aspect ratio preserved.
crop 200x200!
means Width and height emphatically given, original aspect ratio ignored.
Use it like this for inline icons:
<span class="flag-icon flag-icon-de"></span> Germany
They also work as block elements:
<div class="flag-wrapper">
<div class="flag flag-icon-background flag-icon-de"></div>
</div>
Addressing is a fertile ground for incorrect assumptions, because everyone's used to dealing with addresses and 99% of the time they seem so simple. Below are some incorrect assumptions I've seen made, or made myself, or had reported to me.
In the tradition of our PostgreSQL cheat sheet for MySQL lamers, here is a cheat sheet for Jasmine when you're used to RSpec.
Note that Jasmine syntax has changed with Jasmine 2, so if you're using Jasmine 1.x you might instead want to use an older cheat sheet.
# RSpec
expect(foo).to.eq("value")
expect(foo).to_not eq("value")
# Jasmine
expect(foo).toBe("value")
expect(...
When testing code that uses pushState / replaceState, your browser will appear to navigate away from http://localhost:3000/specs
(or wherever you run your Jasmine tests). This is inconvenient, since reloading the document will no longer re-run the test suite.
To remedy this, copy the attached file to a place like spec/javascripts/helpers
and #= require
it from your tests. It will store the current location before every test and reset if afterwards (using location.replaceState
).
This jasmine plugin helps with testing DOM manipulation in two ways:
toBeVisible()
or toHaveCss(css)
<body>
and clean up afterwards.Make sure you have libcurl3-dev
installed:
sudo apt-get install libcurl3-dev
gem install typhoeus
When running Selenium features with parallel_tests, some browser-server interaction might take longer than usual and the impatient Capybara will not wait enough to see results.
Put the attached file into features/support/
to make Capybara more patient in scenarios tagged @javascript
.
Run bundle update cucumber capybara cucumber-rails
to update to the newest versions.
Backup your features/support/path.rb
to be able to add your own paths again after the cucumber installation script in step 4.
Backup your features/support/env.rb
file to be able to reintegrate parts like your blueprints setup:
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'spec/support/blueprints'
Run `$ rails generate cucumber:install --capyba...
Build dashboards using ascii/ansi art and javascript
Awesome!
Crazy hack. Might be useful one day.
The code required has since been extracted into a library.
The condition for an if statement has to resolve to a boolean true/false value. However, all facts are strings, and all non-empty strings — including the string "false" — are true. This means that facts that are “false” need to be transformed before Puppet will treat them as false.
Angular 1.3+ has an alternative getter/setter pattern: You can bind ng-model
to an accessor function. This is a function that is either a getter (when it gets no arguments) or a setter (when it gets the new value as an argument):
$scope.name = function(newName) {
return angular.isDefined(newName) ? (_name = newName) : _name;
}
You need to bind this function with ng-model
and `ng-model-options="{ getterSette...
This is a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests.
This setup allows to test focus/blur events in Cucumber tests (using Selenium). For background information, see How to solve Selenium focus issues.
Cucumber step definition:
# This step is needed because in Selenium tests, blur events are not triggered
# when the browser has no focus.
When /^I unfocus the "(.*?)" field to trigger ja...
Responsive Lightbox JavaScript that just works.
You can use it for single images or a gallery. Animations are optional.