Posts for: #programming

Load pull request (branch diff) files in PhpStorm

Stick this in your .bash_profile or .bashrc file: function diffopen() { git diff --name-only "$1" | xargs -d '\n' pstorm; } Then in your project folder, say you want to open all files that differ from your master branch: diffopen master Note, on OSX you’ll need the GNU version of xargs for this to work, as I discovered the hard way..
[Read more]

PHP: Replacing short open tags with proper ones recursively in a big code base

We recently took on a horrible code base at work, with lots of open tags in the code like this: <? calculateVat(123.. As far as I know this way of opening PHP code is deprecated and soon won’t be supported at all so I thought I’d just use sed to fix this but it wasn’t quite that simple. Sed has no way of doing look-aheads with regular expressions meaning we can’t tell it to not turn <?
[Read more]

Stopping bots spamming your forms

No doubt many others have thought of this already, but today I had a brainwave.. You have forms that use the dreaded captcha, which just sucks. Better forms use a honey pot trap but it’s still a bit weird. What if we checked to see how long a user had spent filling out a form - a bot will take (not much time) to complete the form where as a human being will take slightly longer, say anything over 5s.
[Read more]

PHP frameworks… a serious issue

Several years ago a new framework called CakePHP was released and I was quick to jump on the band wagon. The promise of having base code that does 90% of the work for you was too tempting and we quickly got burned trying to perform more complex SQL queries - hitting the boundaries of what was possible and having to hack our way around it. Ugh. Still, when you go back to writing an MVC style web app from the ground up you quickly realise that life would be much easier with a framework.
[Read more]

Copying mysql tables with keys / extras

A lot of sites will tell you to do this: CREATE TABLE t2 SELECT * FROM t1; Problem is that you’ll lost your auto_increment, primary key and any other indexes you have (and any other extra meta data like that.) This might not be the best solution, but hey it worked for me: CREATE TABLE t2 LIKE t1; INSERT INTO t2 SELECT * FROM t1; Hope that helps somebody.. I only noticed I’d lost all my primary keys after copying a load of tables using the old method.
[Read more]

Accessing get vars with ActionScript 3

I’ve just started to learn a bit of ActionScript for a new project I’m working on. The first thing I needed to do was integrate a message from the source html (and eventually a php file.) Turns out there’s pretty much no clear documentation out there on the web, so I decided to write this. First thing’s first, create a text object in your flash file and set the instance name to something you can easily remember, in this example I set it to message.
[Read more]

BigDump

Recently I’ve started having to work with sites hosted on shared hosting with phpMyAdmin and a measly 2MB upload limit for database imports. To get around this issue, I found a great little tool called bigdump which can just import a mysqldump file (even if gzipped) - just upload via ftp and import! Pretty sweet. http://www.ozerov.de/bigdump.php
[Read more]

MySQL 5 and old clients (like php4)

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in /blah/somepage.php on line 123 The reason for this warning is because PHP4 can’t communicate with a MySQL5 server unless it’s using old passwords (set by using the OLD_PASSWORD() function below.) There are two simple ways to fix this. The first would be to upgrade your version of php. Unless you *really* need php4 (or below?
[Read more]

Auto_increment fun!

Discovered some fun things in MySQL today.. Set the variable @id to 0: SET @id = 0; Update the column id to be id + 1 - this will re-index your id column in one fell swoop. Very nice: UPDATE tblname SET id = (@id := @id + 1); Set the first value for an auto_increment column: ALTER TABLE tblname AUTO_INCREMENT = 196; (this won’t work if there are rows with a higher value already in the table)
[Read more]