Vim: Always Learning

Vi (or Vim in it’s modern incarnation) is a text editor. It’s a modal text editor. You can switch from insert mode to normal mode. Insert mode is where you type text into your document, and normal mode is where you type commands that do all sorts of functions. It’s incredibly powerful, incredibly complicated and even exiting the editor is not obvious. 🙂

So it’s always great when I dive into learning something new about Vim. There’s always something new to learn about Vim, even after more than twenty years of using it. I think there should be a Duolingo for Vim.

So, when you’re watched that, and watched it again, and again to understand it, have a look at the following presentation showing off the power of Vim without plugins.

When you just want to use Vim faster …

The power of Vim is in the commands. That also means it requires practice to learn those commands because they’re usually keyboard shortcuts. There’s no Edit menu to remind you to use something you just learned. With just a few core concepts and memorized keys or functions you can be very efficient at moving around or manipulating text.

It’s always Vi

Things I learned recently:

  • :set number relativenumber from the last video and this blog post.
  • :sfind is a game changer. I set the base path to my public_html and sfind will open a file in a new split without figuring out the path.
  • I need to install ctags.

And so much more ..

Cannot load mysql extension. Please check your PHP configuration.

A friend recently had a problem configuring a new server. He installed PHP, Apache, MySQL and phpMyAdmin but when he launched it he got the following error:

phpMyAdmin – Error
Cannot load mysql extension. Please check your PHP configuration.

If you’ve installed all of the above more than once you’ll know what is more than likely wrong. The MySQL PHP module isn’t loaded. First of all, you must find your php.ini. It could be anywhere but if you create a small php file with the phpinfo(); command it will tell you where it is. Common places include /etc/apache/, /etc/php4/apache2/php.ini, /etc/php5/apache2/php.ini or even /usr/local/lib/php.ini

Edit your server’s php.ini and look for the following line. Remove the ‘;’ from the start of the line and restart Apache. Things should work fine now!

;extension=mysql.so

should become

extension=mysql.so

InnoDB: Starting shutdown…

Calling all MySQL admins! When you’re working with InnoDB tables you may have noticed that MySQL takes an extraordinary amount of time to shutdown. Don’t panic! It’s normal.
InnoDB has extensive logs that it must run through and if your server is at all busy these logs can be quite big.
After you’ve started the equivalent of “/etc/init.d/mysql stop” it may not return for quite a while. Simply open another terminal and examine the system log. On a Debian or Ubuntu box, look at /var/log/daemon.log and you’ll see the “InnoDB: Starting shutdown…” message.
Now, go off and make a cup of tea because this could take a while. On a fairly large and busy database it might be half an hour or more!
Please, please, please don’t be tempted to killall -9 mysqld because bad things will happen! Even if your boss is looking over your shoulder, and you’ve promised that the company webserver will be online in 2 minutes, don’t do it.
However, cases where it is ok to kill the database with a “kill -9”:

  • International terrorists are planning on robbing the World Bank and you’re the only secret agent who can bring down the database which will stop them.
  • Lassie will be run over by the evil farmer who plagued the local village with his monster cows unless you can corrupt his database in time.
  • Or finally, you like hard work and restoring from backups!

PHP Optimization and Security tips and rant

Andrew van der Stock’s criticism of PHP’s security model. What security? Global request arrays go some way to making applications safer but there are obscure functions and settings which can trip up developers. (via)
PHP Optimization Tricks from Ilia Alshanetsky has one gem I didn’t know about – the ctype extension. It’s somewhat limited but would be faster and less resouce intensive than a regular expression to do simple checks.

While I’m blogging development stuff, here’s mention of a vector drawing library in Javascript!
Yes, newer browsers have SVG support but this will work in older browsers and newer. Cute.

2 for the developers

2 links for the developers around here:

  • Quick Lookup is an online dictionary of PHP,MySQL, Javascript and CSS commands and keywords. As of this moment, “55% ish of MySQL is done, JS is NOT finished yet” but it’s still useful if you haven’t got the PHP manual handy.
  • Regular Expression Checker – regexes are an arcane science. Everyone needs all the help they can get when working with them! (via)

Later.. Here’s another AJAX powered regular expression checker via Matt.

SQL Injection Attacks by Example

Ever wondered how some of your favourite apps get hacked and broken into? This page lists lots of examples of database “injections”.
Like an injection you get off your doctor these bits of code inject database code into your application. The code can do anything – delete all your data, grab your passwords, or anything.

And if it happens to you, a nice doctor isn’t going to give you a lollipop.

How to Use Design Patterns

How to Use Design Patterns

Among developers, design patterns are a popular way to think about design, but what is the proper way to think about design patterns? In this interview, Erich Gamma, co-author of the landmark book, Design Patterns, talks with Bill Venners about the right way to think about and use design patterns.

Ignore details early on

Oh, this is so true!

We’re crazy about the details. We love the details. The space between objects. The perfect type leading. The perfect color. The perfect words. 4 lines of code instead of 7. The perfect flow. 90% vs 89%. 760px vs 750px. $39/month vs. $49/month. Success and satisfaction is in the details.

However, success isn’t the only thing you’ll find in the details. You’ll also find fixation, stagnation, disagreement, meetings, and delays. These poison projects. These are the things that kill morale (and if morale is low, your chance of success is even lower). You want to avoid these at all costs. If you procrastinate, procrastinate the details.