Copy a file over SSH
Ubuntu lets you mount an SSH shell into Nautilus from Places -> Connect to server (select "SSH" as server type).
In order to copy a file over SSH from a shell:
scp filename username@remotehost:
The trailing ":" directs the file to username's home directory on the remote host.
You can also copy a file from the remote host to your local machine:
scp remotehost:remotepath localpath
Using screen for long running tasks
Screen is great for long running tasks, where you want to log in every few hours and days and keep your session alive indefinitely.
To create a new screen, do
screen -Rd screenname
This will also reattach an existing screen with that name.
Once you're in the screen, CTRL+A will bring up the menu, d detaches the screen. You can close your shell, screen and all applications running inside of it will remain alive.
Scrolling inside a screen
- Bring up the menu with
CTRL+A - Press
Esc - You can now scr...
Dumping and importing from/to MySQL in an UTF-8 safe way
MySQL dumps can corrupt UTF-8 when shell redirection changes character encoding. Using -r for export and SOURCE for import preserves the dump bytes.
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"'