Monday, February 6, 2012

How to get ack to search .txt files

By default, ack (aka ack-grep) doesn't search through text files. To get it to do this, add
--type=text
to the command. If you know you'll always want to search text files, you can create a .ackrc file in your home directory with the same command in it:

--type=text

Ack just adds anything from this file to the command.

Thursday, February 2, 2012

Determine Image Size from Command Line

To get information from the command line about an image, do this:
$ identify filename.png

As an example:
$ identify button.png
button.png PNG 127x34 127x34+0+0 8-bit DirectClass 3.5KiB 0.000u 0:00.000

This shows, among other things, the interpreted filetype, dimensions (width x height), and file size.  You can get way more information by adding -verbose to the command.

Learn more.

Disabling Postgres Pagination

If you query your PostgreSQL DB and the results are too long to fit on one page, the default postgres behavior is to paginate the results with something like `more` or `less`. Sometimes you don't want this. Here's how to disable pagination:

To disable pagination temporarily when you in the postgres command line:
=# \pset pager
This will toggle pagination, so you can use it again to go back to the normal mode. (The "=#" is just the prompt; type the stuff following that)

To disable it when you start up psql:
$ psql -U admin db_name --pset pager=off

And finally, if you always want it to be off, you can add this to your `.bashrc` file:
alias psql='psql --pset pager=off'

Wednesday, January 4, 2012

How to prevent mailto in email client

Recently I was designing an email that gets sent to customers. In it I had an email address, but it wasn't meant to be used to send an actual email, just to copy and paste. Gmail automatically converted it to a mailto link, which made it clickable and thus harder to select the text. Here's what I did to force it back to text.

The problem:

Original HTML of email that I'm sending:

<p>Please add blah@yadda.com to your address book.</p>

HTML of email that I receive:

<p>Please add <a href="mailto:blah@yadda.com" target="_blank">blah@yadda.com</a> to your address book.</p>

What I see:

Please add blah@yadda.com to your address book.

Solution:

<p>Please add blah<span>@</span>yadda<span>.</span>com to your address book.</p>

What I see now:

Please add blah@yadda.com to your address book.

Unfortunately, this will only work for HTML emails, not plaintext emails.