Open a MySQL shell using credentials from database.yml
In order to open a MySQL shell without the need to enter user and password, you can say the following in any Rails 2 project:
script/dbconsole -p
In Rails 3 you can say:
rails dbconsole -p
If you'd like to enter a database for an environment other than development
you can say:
script/dbconsole -p staging
Related cards:
Open dialogs from shell scripts
Using the dialog
command you can launch ASCII-art dialogs from your shell scripts.
Check out man dialog
for a list of supported dialog types. Aside from simple text boxes or choice dialogs, it supports mo...
PostgreSQL vs MySQL: How to UPDATE using a JOIN
When you want to UPDATE
a table with information from an associated table, you can JOIN
the associated table into the statement.
Example
Let's say you have a database schema where an Employee belongs_to :department
:
+-----...
Script to open an SSH shell to a Capistrano deployment target
We regularly need to connect to the server in order to e.g. access the production console. Guessing the Capistrano deploy user and then again guessing the right directory on the server is awkward, so we wrote a script that parses config/deploy and...
Request a gzipped response from a web server using Wget
To reduce download time, application servers usually serve content using gzip compression, if the browser supports it.
When using a tool like Wget to explicitly download an application's response, the server r...
jQuery: How to remove classes from elements using a regular expression
jQuery's removeClass
removes the given class string from an element collection. If you want to remove multiple/unknown classes matching a given pattern, you can do that.
For example, consider a DOM node for the following HTML. We'll reference i...
Generate a strong secret from the shell
A good tool to generate strong passwords and secrets is "apg". You can get it with
sudo apt-get install apg
To create a strong secret for sessions, [hashed Paperclip paths](https://makandracards.com/makandra/734-deliver-paperclip-attachments...
How to send a test e-mail from shell
If you want to manually check if e-mail delivery works on a machine by sending an e-mail you can run the following:
mail -s Test someone@example.com < /dev/null
This will send an empty e-mail with "Test" as its subject to `someone@example.com...
Howto transfer a single mysql table between several deployment stages
Example task: Multiply the table holidays
between several stages.
-
Open two terminals:
shell-for stage_1 shell-for stage_2
-
Get the stage1 and stage2 MySQL credentials:
cat /opt/www/the_stage.host.tld/current/config/...
Line wrap text from a Ubuntu Linux terminal
You can use fold
:
fold -sw 60
You can now paste your texts. fold
will echo them back, word-wrapped after 60 columns. Exit with Ctrl+C
or Ctrl+D
.
You can also use files for input and output:
fold -sw 60 input.txt > output.txt
How to load only a subset of a massive MySQL dump
I had a huge MySQL dump that took forever (as in: days) to import, while I actually just wanted to have the full database structure with some data to use on my development machine.
After trying several suggestions on how to speed up slow MySQL du...