Uncaught exception in PassengerServer client thread exception: Cannot accept new connection: Too many open files
So you probably see the following error trace within your Passenger log file if you got here:
[ pid=123 thr=1401414 file=ext/nginx/HelperAgent.cpp:964 time=2012-04-27 10:01:49.273 ]: Uncaught exception in PassengerServer client thread:
exception: Cannot accept new connection: Too many open files (24)
backtrace:
in 'Passenger::FileDescriptor Client::acceptConnection()' (HelperAgent.cpp:429)
in 'void Client::threadMain()' (HelperAgent.cpp:953)
You can either
- Lower the maximum number of running Passenge...
CodeMirror
CodeMirror is a JavaScript component that provides a code editor in the browser. When a mode is available for the language you are coding in, it will color your code, and optionally help with indentation.
Move page breaks in LibreOffice Calc
- You can define what will be printed by checking View -> Preview Page Breaks and then moving around the blue borders.
- You can now define the size of the printed content under Format -> Page -> Sheet -> Scale. You can choose between three scaling modes which all suck in their own way.
validates_acceptance_of is skipped when the attribute is nil
validates_acceptance_of :terms
only works if terms
is set to a value. The validation is skipped silently when terms
is nil
.
While this behavior is useful to validate acceptance in the frontend and not the admin backend, it also makes it very easy to unintentionally skip the validation altogether by forgetting to add the checkbox to a form. E.g. validates_acceptance_of :terms_with_typo
will be skipped silently even if there is no column with t...
Tabs in Textarea Plugin for jQuery
This is a demo of the "Tabby" Javascript jQuery plugin to use tabs in regular textareas to make them suitable for in-browser coding of languages like HTML, CSS, Javascript, or your favorite server-side language. The idea is to be able to use a press of the TAB button or SHIFT+TAB to indent or outdent your code.
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...
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...
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.
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>
TodoMVC - A common learning application for popular JavaScript MV* frameworks
Developers these days are spoiled with choice when it comes to selecting an MV* framework for structuring and organizing JavaScript web apps. Backbone, Spine, Ember (SproutCore 2.0), JavaScriptMVC... the list of new and stable solutions goes on and on, but just how do you decide on which to use in a sea of so many options?
To help solve this problem, we created TodoMVC - a project which offers the same Todo application implemented using MV* concepts in most of the popular JavaScript MV* frameworks of today.
Solutions look and feel the same...
ActiveRecord: When aggregating nested children, always exclude children marked for destruction
When your model is using a callback like before_save
or before_validation
to calculate an aggregated value from its children, it needs to skip those children that are #marked_for_destruction?
. Otherwise you will include children that have been ticked for deletion in a nested form.
Wrong way
class Invoice < ApplicationRecord
has_many :invoice_items
accepts_nested_attributes_for :invoice_items, :allow_destroy => true # the critical code 1/2
before_save :calculate_and_store_amount # the crit...
What collapsing margins are, how they work and when margins do not collapse
Imagine you have 2 HTML boxes. The first one has a margin-bottom
of let's say 30px
and the second one a margin-top
of 20px
. After rules of collapsing margins have been applied we have a margin of 30px
(not 50px
) between these two boxes . This is because no addition of both margins takes place but the maximum of both is applied. This behavior is called collapsing margins.
Oftentimes it is a good behavior but collapsing margins can be annoying, too. For example child el...
RestClient sends XML Accept header by default
REST Client is a nice, simple HTTP client library for Ruby.
When you do a simple GET request like that:
RestClient.get 'http://example.com/'
it will result in this request beeing sent to www.example.com:
GET / HTTP/1.1
Accept: */*; q=0.5, application/xml
Accept-Encoding: gzip, deflate
Host: www.example.com
The application/xml
accept header might lead to unexpected results on your server. You can force REST Client to ask the server for default text/html
that way:
RestC...
Auto-generate Cucumber navigation paths
Don't you just hate to write Cucumber path helpers to be able to say this?
When I go to the user form for "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de'))
When I go to the form for the user "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de'))
When I go to the form for the user above" # goes to edit_user_path(User.last)
When I go to the project page for "World Domination" # goes to project_path(Project.find_by_anything!('World Domination')
...
High-level Javascript frameworks: Backbone vs. Ember vs. Knockout
This is a very general introduction to MV* Javascript frameworks. This card won't tell you anything new if you are already familiar with the products mentioned in the title.
As web applications move farther into the client, Javascript frameworks have sprung up that operate on a higher level of abstraction than DOM manipulation frameworks like jQuery and Prototype. Such high-level frameworks typically offer support for client-side view rendering, routing, data bindings, etc. This is useful, and when you write a moderately complex Javascript ...
How to overwrite and reset constants within Cucumber features
In order to save the original value of a constant, set the new value and restore the old value after a scenario was completed, you can use the following helper. It takes care of saving the old constant value, setting the new one without throwing warnings and resets the value with an After
hook.
This module also enables you to introduce new global constants.
Since these newly defined constants do not have any value to be reset to,
they simply are deleted (remove_const
) once the respective Cucumber step finishes.
You can copy the file at...
Cucumber step to test that a tooltip text exists in the HTML
Tooltips that are delivered through HTML attributes are encoded. Decode entities before checking for their presence.
Capybara:
Then /^there should( not)? be a(n encoded)? tooltip "([^"]*)"$/ do |negate, encoded, tooltip|
tooltip = HTMLEntities.new.encode(tooltip) if encoded
Then "I should#{negate} see \"#{tooltip}\" in the HTML"
end
Note
This step uses the htmlentities gem described in another card.
Ma...
nruth/show_me_the_cookies - GitHub
Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
Supports Capybara's bundled drivers (rack-test, Selenium Webdriver), and adapters for other drivers may be added.
Flexible overflow handling with CSS and JavaScript
You can use text-overflow
to truncate a text using CSS but it does not fit fancy requirements.
Here is a hack for the special case where you want to truncate one of two strings in one line that can both vary in length, while fully keeping one of them. See this example screenshot where we never want to show an ellipsis for the distance:
? see a field "([^"]*)"$/ do |negate, name|
expectation = negate ? :should_not : :should
begin
field = find_field(name)
rescue Capybara::ElementNotFound
# In Capybara 0.4+ #find_field raises an error instead of returning nil
end
field.send(expectation, be_present)
end
Note that you might have to adapt the step defi...
Why your javascripts should be executed after the dom has been loaded
Most of the JavaScript snippets have code that manipulates the DOM. For that reason dom manipulating javascript code should have been executed after the DOM has loaded completely. That means when the browser has finished HTML parsing and built the DOM tree. At that time, you can manipualte the DOM although not all resources (like images) are fully loaded.
The following snippets show how you can do this with plain JavaScript, jquery or prototype ([dom ready ...
Using Solr with Sunspot
This describes all the steps you'll need to get Solr up and running for your project using the Sunspot gem.
Prepare Sunspot on your development machine
What you want in your Gemfile:
gem 'sunspot_rails'
gem 'sunspot_solr'
gem 'progress_bar' # for sunspot:solr:reindex
Now define what should be indexed within Solr from your ActiveRecord models, e.g.,
class Article << ActiveRecord::Base
searchable do
text :title
...
Enabling view rendering for controller specs
Views are normally (for good reason) not rendered in controller specs. If you need it to happen, use:
RSpec 1 (Rails 2):
RSpec 2 (Rails 3):
Note that you can't use that inside it
blocks but need to put it in the nesting example group, like this:
describe '#update' do
cont...