The story so far.

This post is the first in a new strand for this blog talking about my life as a coder, and my approaches to and feelings about coding. I’m going to try and stay somewhat abstract and not get too technical. I’m also trying to improve my long form writing.

So here we go, a quick bringing-up-to-speed and the beginning of several pieces on code frameworks. Continue reading

Adding folding to PHP switch case statements in Texmate

I love the code folding in textmate, but was slightly bugged by the fact that it wouldn’t fold the cases in switch statements.
Some old code that I was going back to had some massive sections of code held in cases and I was going a little mad with all the scrolling so I finally got around to changing the PHP bundle.

To get case folding working open up the bundle editor, find the PHP section and click on the language section called php, it should look like a small grey circle with a white L in it, next to the word php

The folding markers are defined with regular expressions for the start and end text to use as a folded area. by default they look like this…


foldingStartMarker = '(/\*|\{\s*$|<<<HTML)';

foldingStopMarker = '(\*/|^\s*\}|^HTML;)';

I’ve not delved a long way into the documentation, but as far as I can tell each match in the StartMarker has a corresponding match in the StopMarker, e.g.  ‘\*’ is the first match, and folding is ended by the first match ‘*/’ in StopMarker, then we have the curly brackets with anything in between, and then the definitions from the HTML language bundle.
all I did was change them to include ‘case’ for the start and ‘break’ for the end


foldingStartMarker = '(/\*|\{\s*$|case|<<<HTML)';

foldingStopMarker = '(\*/|^\s*\}|break|^HTML;)';

and now the cases inside a switch statement fold.

MAMP running slow? One possible cause

So all of a sudden the local development version of my site, run from MAMP on localhost was taking nearly a minute to load any page, despite there being no setup changes since it was ‘last known good’.

It took me a (thankfully) few minutes to find it with a little Google first.
First off someone on the MAMP forum pointed out that you can check if it is Apache as a whole, or perhaps just MySql running slow, by pulling up http://localhost:8888/MAMP/info.php (or your local equivalent, I use port 80 myself). If the info.php script comes up instantly then Apache and php are fine, and you need to look further under the bonnet.

For my case though even the info.php page was taking the same amount of time to load. A quick check in the logs for Apache and PHP showed no errors that could be related to it. So time to stop and think.

My local development environment consists of an iMac and a macbook pro, I bounce between them depending on where I feel like sitting. Each machine has its own copy of MAMP, and I have wildcard virtual hosts mapped to folders in ~/Sites/<tld>/<sitename>/public_html and use dnsmasq on each machine to map a fake tld’s to them, so the sites on the iMac live at http://<sitename>.bmac and the mbp http://<sitename>.dev . This way I can develop against either machine from either machine. The root of each site is also a git repository, so I can easily push and pull changes back and forth between the machines.

I recently rebuilt the iMac, backing up the entire drive, and installing fresh. Then during the install I used the user migration tool to pull across my setup from the MBP. I love the user migration tool, there was almost nothing from my mbp I needed to install on the iMac that wasn’t pulled across. A few small tweaks to references to machine names in a few files, copy the old iMac documents folder and mail settings over from the backup, and voila!

However… I missed one setting in php.ini. That setting was xdebug.remote_host which was still pointing to the macbook and as the macbook was off, instead of a simple knock on it’s door to see if macGDBp  was running or not, there was a massive delay waiting for the connection attempt to time out.

I guess the sensible value for this should actually be localhost, then I would never have encountered the problem. Have double checked the docs ( http://www.xdebug.org/docs/all_settings#remote_host ) I’m not certain why I wasn’t already. As the two machine setup is much newer than the xdebug setup I might try out using xdebug.remote_connect_back as no-one else can access these machines, or at least not anyone scary anyway. xdebug.remote_connect_back will automatically try to create a debug connection with the requesting host, which would probably suit my dev-any-machine host-any-machine setup.

So the moral of the story? Specify localhost when it’s all you need, and save yourself config hassles if the hostname changes.

tl;dr: The culprit? Xdebug.remote_host setting in php.conf pointed to a machine that wasn’t turned on. Massive delay while it tried to check in with an unreachable address.

Using MAMP’s mysql from the command line

Just a brief post on getting mysql to work at the command line with MAMP under OS X

I’d had quite enough of waiting around for phpMyAdmin to import the latest live copy of a database for a project I’m working on at the moment, so I decided to head back to the command line for the first time in ages as import time from there can be measured in seconds rather than minutes.

In order to avoid huge commands like

/Applications/MAMP/Library/bin/mysql -uUSER -pPASSWORD -DDATABASE < somefile.sql

you can either add the MAMP directory to your system path in your .profile file or (my preference) you can symlink to the MAMP version of mysql in /usr/bin which should put it onto the default path.

cd /usr/bin
sudo ln -s /Applications/MAMP/Library/bin/mysql mysql

There’s a slight gotcha here, you might already have a version of mysql kicking about in /usr/bin, if for some reason you really want to use the MAMP version rather than the existing then just rename the existing copy (to keep it as a backup)

mv /usr/bin/mysql /usr/bin/mysql_copy_before_mamp

(I do like to name my backup files something that I’ll understand in 6 months time)

There’s a good chance that running the MAMP copy of mysql via this symlink will result in error like

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql looks by default for the .sock file in /tmp/mysql.sock whoever MAMP’s mysql keeps it elsewhere so all we need is another symlink

sudo ln-s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

and you should be rocking and rolling.

Communicado Ltd – almost incommunicado

UPDATE – It’s been brought to my attention recently that some of the comments below might have been cases of inaccurate investigation on the part of the commenter. I was prompted to take a look at some of the comments below, and after a couple of hours trawling through DNS records, spam reporting newsgroups and various other sources, I’ve realised that some of the commenters have mistaken falsified email addresses in the spam as being related to the spammers, when in fact the owners of the domains used are in fact guilty of nothing.
I’ve removed comments related to one individual and also to Charming Events, as there is nothing actually linking them to these spammers. –
Please see the new note at the end of this post regarding commenting.
END UPDATE

UPDATE – The spam from these guys does appear to have dried up but I wonder if it’s coincidence or not that the only post on this blog that attracts any comment spam, 100-200 messages a day, is this one.
They all originate from obviously exploited machines in the ranges 194.8.75.255 and 194.8.74.255 and all appear to be generated by the same algorithm.
Lets see how a little reCaptcha helps.  – END UPDATE

There’s an apparently well known spamming outfit by the name of Communicado Ltd.

They’ve been sending me a different spam at least once a day, every one coming from a new domain, but in the end when you follow the unsubscribe link you can see that you’re in exactly the same system, and everything has been set up to look like they’re giving you a chance to unsubscribe, but in the end it has no affect.

Well I found the phone number for them in the footer of www.bitesizeseminars.co.uk it’s 01234 481148. Phoning this the phone is answered as Bitesizeseminars, but asking for communicado, and someone that could help remove me from their mailing lists I was told that the person I was talking to could help. She took my domain, typed for a bit, telling me she was searching for it in their lists, and then that she had found it and removed it.

Lets see what happens :)

PLEASE NOTE – Any comments below are not my own, they represent the views of the person making the comment, and I do not have the time to check the veracity of any comments. If you comment on this post, please make sure of your facts, and also note how you came to any conclusions in your comment, from now on any comments not backed up with these notes wont be approved.
If you comment on this post you assume full responsibility for what you say, I will not be held responsible for you.