I just wanted to link you into this video from Etsy. Well worth a watch.
Monthly Archives: February 2012
Backbone patterns
Link
http://ricostacruz.com/backbone-patterns/
A collection of the best patterns to use when developing with Backbone.js
Best way to test email
Featured
One thing that can be difficult to test is email, get it wrong and at worst you can end up sending confusing and misleading emails to your clients. Its easy to get a webserver and a local copy of the database set up, but what about a local email server.
One approach is to create your own mail function, which looks at a system environment to see if it should actually send the mail or not. For instance, if it is a dev machine, ignore the mail function and write the contents of the email to log. This is OK, but it doesn’t actually test the email function until it is on live, which is arguably too late.
I have just come across a package called Dumbster. It is a java application that will sit and respond to SMTP requests, but instead of sending the email on to the recipient it holds on to it in an internal store. Bingo, we are actually testing the mail function, but the email is being contained.
To get up and running you will need Java, and Ant, and a copy of the source code. Extract the files and open up a terminal in the folder you placed the source. Run ant and you should see something like this.
$ ant
Buildfile: /home/ubuntu/rjo1970-dumbster-d20b4e6/build.xml
clean:
[delete] Deleting directory /home/ubuntu/rjo1970-dumbster-d20b4e6/build
init:
[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes
[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test
[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report
compile:
[javac] Compiling 29 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes
jar:
[jar] Building jar: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/dumbster.jar
compile-tests:
[javac] Compiling 6 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test
test:
[cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 29 files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/instrumented
[cobertura-instrument] Cobertura: Saved information on 29 classes.
[cobertura-instrument] Instrument time: 174ms
[junit] Running com.dumbster.smtp.MailMessageTest
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.181 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.RequestTest
[junit] Tests run: 38, Failures: 0, Errors: 0, Time elapsed: 0.079 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.RollingMailStoreTest
[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.049 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.SmtpServerTest
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 1.113 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.SmtpStateTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.038 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junitreport] Processing /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report/TESTS-TestSuites.xml to /tmp/null279172976
[junitreport] Loading stylesheet jar:file:/usr/share/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 701ms
[junitreport] Deleting: /tmp/null279172976
[cobertura-report] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 29 classes.
[cobertura-report] Report time: 237ms
BUILD SUCCESSFUL
Total time: 10 seconds
You have now compiled the Java, and to run it use the following
java -jar build/dumbster.jar [PORT]
and substitute [PORT] for the port you want to run it on, or leave it empty to run it on port 25, the default for SMTP.
Next make sure that your development setup is configured to use Dumbster as its SMTP server and you are good to go.
Once you have run your tests, or done what you need to do, you can have a look at what Dumbster has collected. They easiest way is to telnet into it. Once you have connected you need to be polite and say HELO. You’re then free to inspect your email.
To see how many emails Dumbster has collected simply type LIST into the terminal. You should see something like this.
$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost Dumbster SMTP service ready
HELO
250 OK
LIST
250 There are 2 message(s).
To see an individual message you need to specify the index of the message, with the numbering starting at 0. You should see something like this.
LIST 0
250
-------------------------------------------
Subject: This is a subject
Date: Tue, 14 Feb 2012 09:10:57 +0000
To: blog@ghosty.co.uk
From: blog@ghosty
This is an interesting test message.
There are 2 message(s).
Once you are done, type the QUIT command so that you free the server up to run more tests. The server will only allow a single connection at a time, and so if you leave your connection open, other applications will hang on the connection.
Debugging PHP, with breakpoints!
One thing that I have always disliked about PHP development was the seemingly difficult debugging process that came along with it. The fact that you would save a file, and then have to open it in the browser to see what’s going on – sometimes to random results. There was none of the usual ability to step through the code and create checkpoints – something that Java, .Net, and even JavaScript (since the web inspector came about) have had for a while.
Well it turns out that I was wrong. The ability to do this stuff exists, I was just unaware of it, and because of my willingness to accept the status quo, I never bothered to look for a way.
The missing piece of the puzzle is actually something that I have been using for a while. Xdebug. I have been using it to generate grind files, which allow you to profile your script using tools like WebGrind.
Add the following in your php.ini.
xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
Then, in NetBeans, go to your options window and select the PHP tab. Make sure that the Debugger Port corresponds to the one that you have set in your ini file.
Finally, restart your web server and have fun using breakpoints.
There is also a really useful guide from NetBeans on how to debug PHP using the inbuilt tools available to you.
A look inside mobile design patterns
Link
All change
I just wanted to write a quick post saying that I am starting a new job at Group NBT. I’ve managed, despite the snow, to make it in on public transport fine. I don’t know [yet] what all these people are moaning about. I’m currently sat in a coffee shop opposite, as I don’t start until 10 today.
I spent 5 wonderful years working for The University of Kent, working with some fantastic people. I really will miss the environment of the Uni, but time had come for me to challenge myself.
I don’t challenge myself enough. Something that I hope to change. I have historically opted for the easy option, which is why this is such a big thing.
I hope to do some more blogging on the things I learn, challenges I face, and experience that the outside world brings. I have enough time to on the train, that’s for sure.
Well, here goes nothing….