Test PHP Mail Without an SMTP Server
One major annoyance I have encountered when developing PHP (or any language for that matter) is testing email notifications. This is mainly due to the fact that in order to send email from your computer you need to either have an SMTP server running or have access to one that you can utilize for testing purposes.
In my case, I had no immediate access to an SMTP server (and didn’t feel like scouring the Internet looking for some sort of free solution) and installing one on my computer was complete overkill. So, I came up with a simple solution that works for PHP.
All I did was write a simple class called NoSmtp that reads the contents of the sent email and creates a file on your local machine which can then be opened in the mail client of your choice (for me that would be mutt). The class is designed for use with PHP’s mail function, which when called, sends the mail contents to the command specified by the sendmail_path directive in your php.ini file, which by default is
sendmail -t -i. So, all you need to do is change that directive to point to the location of
NoSmtp.php and, voila!, you now have pseudo email functionality.
You can pull the code from my Bitbucket repo, bitbucket.org/jonyamo/nosmtp. And be sure the read the comments in the code for various config options.
Custom MySQL Prompts and Pagers
I prefer to perform all MySQL related tasks from the command line, and because of that there are two customizations that I couldn’t live without:
1. Custom prompts
Not only do I perform all tasks from the command line but I also on occasion have multiple connections open to different servers. So, instead of looking a boring prompt like this
I prefer something a bit more informative such as
You can set that by editing you
my.cnf file like so
#---------------------------------- # file: ~/.my.cnf #---------------------------------- [mysql] prompt='\u@\h:\d> '
More options are available at http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html#id549417.
2. Custom pager
less as my default pager when viewing files and whatever else on my Linux boxes. I’ve got it set with all my favorite options by setting these two environment variables in my .bashrc
export LESS="-AFiRsX" export PAGER="less"
And, now I can use it inside of MySQL when running queries by simply passing
--pager when invoking
mysql. This not only allows me to page through the results but also run searches if need be.
Code generation tools which pretend to abstract out something, like all abstractions, leak, and the only way to deal with the leaks competently is to learn about how the abstractions work and what they are abstracting. So the abstractions save us time working, but they don’t save us time learning.
PHP Automatic Error Detection in Vim
Syntastic is a syntax checking plugin that runs buffers through external syntax checkers as they are saved and opened. If syntax errors are detected, the user is notified and is happy because they didn’t have to compile their code or execute their script to find them.
PHP is currently my main programming language, hence the title, however, Syntastic supports many others.
Context-sensitive Documentation in Vim
Pressing K while in normal mode in Vim will, by default, look up documentation using the
man utility for the keyword underneath the cursor. This is excellent for quickly researching builtin Linux utilities as well as functions from the Standard C Library.
Pretty awesome. What makes it more awesome is the ability to extend it to use whatever utility or script you want. And what makes it super awesome is the ability to change that utility based on the context of the current buffer. That means you can use pman for PHP, ri for Ruby, and perldoc for Perl without ever leaving Vim.
Simply add the following lines to your vimrc:
autocmd FileType php setlocal keywordprg=pman autocmd FileType perl setlocal keywordprg=perldoc\ -f autocmd FileType ruby setlocal keywordprg=ri
You can also use custom scripts like this one:
#!/bin/bash #---------------------------------- # file: ~/Scripts/javadocs #---------------------------------- elinks http://javadocs.org/$1
Just simply change the
keywordprg variable to use the script name:
autocmd FileType java setlocal keywordprg=~/Scripts/javadocs