UTF-8ify an existing MySQL database
MySQL databases can keep existing data in the wrong encoding unless tables are converted, not just reset to utf8 defaults. ALTER TABLE ... CONVERT TO CHARACTER SET updates stored text.
Count files in a folder
Count the number of files in a folder from the shell with ls -l | wc -l, a quick way to get a directory listing total.
jeremyevans's home_run at master - GitHub
home_run is an implementation of ruby’s Date/DateTime classes in C, with much better performance (20-200x) than the version in the standard library, while being almost completely compatible.
Using CSS3PIE cross-domain
Currently not possible as the linked .htc file contains JavaScript which is not explicitly called.
The developers are working on a pure JavaScript solution which will have some downsides but work across different domains.
Error installing the raspell gem
raspell installation can fail while building the native extension because the Aspell development libraries are missing. Installing libaspell-dev resolves the build error.
Aspell Error - No word lists can be found for the language XY
Aspell reports missing word lists when a language dictionary is not installed. Installing the matching package, such as aspell-de, resolves the error.
Get TinyMCE editor content as HTML
Retrieve TinyMCE content as HTML for storage, preview, or submission with tinyMCE.activeEditor.getContent().
Submit a form with Prototype
For example, to send a form and populate a preview div with the response.
$('content_form').request({
parameters: { 'preview': "1" }, // overrides parameters
onComplete: function(transport){
$('previewContent').update(transport.responseText);
}
});
Autofocus a form field with HTML5 or jQuery
Automatically placing the cursor in a form field improves first interaction and removes an extra click. HTML5 autofocus works in modern browsers; jQuery can provide a fallback.
Fixing Webrat after following an external link
When a Cucumber feature leaves your page through an external Link, Webrat has problems like "Could not find field: "E-mail" (Webrat::NotFoundError)" using your page afterwards. It will also have trouble following redirects.
Fix it with this step:
Given /^I am back on my page$/ do
webrat_session.header("Host", "www.example.com")
end
MySQL replication how-to
Setting up MySQL master-slave replication is error-prone, especially with initial data dumps, binary log positions, and SSH tunnels for remote connectivity.
MySQL Server and UTF-8 Defaults
MySQL defaults can corrupt UTF-8 exports and force manual charset settings for each new database. Setting server and client defaults to utf8mb4 prevents incorrect mysqldump output.
Convert a Subversion repository to Git
Migrating a Subversion repository to Git can preserve full history and branches, but tool quirks may affect the result. A trunk-only import is possible with git svn clone.
Branching and merging in Subversion
Subversion branch workflows avoid commit and merge conflicts when isolating long-running work and later bringing changes back to trunk.
Common Screen Resolutions
Target layouts for common notebook, desktop, netbook and iPad screen sizes to reduce clipping and horizontal scrolling.
Load all models into an Array
Dir.glob(File.join RAILS_ROOT, 'app', 'models', '*.rb').collect{ |path| path[/.+\/(.+).rb/,1] }.collect(&:camelize).collect(&:constantize)
Cucumber Webrat steps
Custom Cucumber step definitions for checking fields, HTML content, regex matches, and table data in Webrat-based tests.
Reprocess only missing images with Paperclip
Adding a new image variant to many Paperclip attachments can trigger costly full reprocessing; patching Paperclip::Attachment skips styles that already exist.
Convert colorspace of images attached with Paperclip
has_attached_file(
:avatar,
:styles => { :large => "300x300", :small => "100x100" },
:convert_options => { all => "-colorspace RGB" }
)
Reprocess Paperclip attachments in one line
script/runner -e development 'Article.all.each { |a| a.image.reprocess! if a.image.exists? }; "done"'
Release gem; Deploy gem; Update a gem created with Jeweler
Publishing an older Jeweler-based gem can require version bumps, gemspec regeneration, tagging, and sometimes a manual gem push to RubyGems.org.
Aggregated RSpec/Cucumber test coverage with RCov
RCov defaults fail to aggregate RSpec and Cucumber coverage cleanly; a custom rake rcov:all task produces a Rails report for app/**/*.rb only.
Better output for Cucumber
cucumber_spinner adds a progress bar for Cucumber features and shows failing scenarios immediately, with optional browser opening for failed pages.