Blog
Thoughts on programming, systems, robotics, and everything in between, sharing what I learn and build.

Spring MVC MyBatis Integration Tutorial
A while back I built a project on Spring MVC and Hibernate, then wanted to see how MyBatis compares. This article shows how to wire MyBatis into Spring MVC, and how to let Spring manage MyBatis transactions for you. A database transaction is an all-or-nothing unit of work: either every statement in it takes effect, or none of them does. We lean on that property at the very end, where a single bad row makes an entire batch insert roll back.
Use CDN Service in Spring MVC
When I deployed TestZilla on Aliyun Elastic Compute Service, growing traffic made it worth offloading static files (images, CSS, and JavaScript) to a CDN. At the time there was little guidance on wiring a CDN into Spring MVC, so I asked on Stack Overflow and ended up with the setup below. The idea is simple: keep the CDN host in a single property and inject it wherever your JSP views reference static assets.
Create Unit Testing Cases in Zend Framework
A solid unit test suite is essential for ongoing development in large projects, especially those with many people involved. Going back and manually testing every individual component of an application after every change is impractical. Your unit tests will help alleviate that by automatically testing your application’s components and alerting you when something is not working the same way it was when you wrote your tests. The Zend Framework 2 API uses PHPUnit, and so does this tutorial application. A detailed explanation of unit testing is beyond the scope of this tutorial, so we will only provide sample tests for the components in the pages that follow. This tutorial assumes that you already have PHPUnit installed.
Create CDN View Helper in Zend Framework 2
In this article, you will learn how to create a custom view helper in Zend Framework 2. A concrete example will be used; a helper which generates links for a subdomain, intended for storing static files. This is especially useful if you wish to use a Content Delivery Network (CDN). With very little modification, the helper can be made generic to support links to subdomains for all purposes. Note: Zend Framework 2 has reached end of life. In 2019 the project moved to the Linux Foundation and was renamed Laminas, so the Zend\ namespaces below are now Laminas\ (for example Zend\View\Helper\AbstractHelper becomes Laminas\View\Helper\AbstractHelper). The view-helper mechanics are otherwise unchanged, so this post is kept as a historical walkthrough. For a real project, run the namespaces through the Laminas migration guide and follow the current custom view helper docs.
Building and Installing HHVM on CentOS 7
What’s HHVM? HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. Instead of interpreting PHP directly, it uses a just-in-time (JIT) compiler to reach much higher throughput while staying compatible with existing PHP code. Facebook, which created HHVM, reported roughly a 9x gain in web request throughput and a 5x drop in memory use over the old PHP 5.2 + APC engine, and back in 2015 HHVM could run most of the popular PHP frameworks out of the box.
Sending Email with Spring MVC Using Template
This tutorial walks through a small Spring MVC application that sends a templated e-mail, using Thymeleaf to render the message body and Jakarta Mail to deliver it. It assumes you are comfortable with Java EE development and with building Spring MVC applications. Note: This post has been updated for Spring Framework 7 and Thymeleaf 3.1. The original version rendered the message with Apache Velocity, but Spring deprecated its Velocity support in 4.3 and removed it entirely in 5.0; templating is now handled by Thymeleaf, and the mail dependency has moved from javax.mail to Jakarta Mail (jakarta.mail).
Build Tengine, MariaDB and PHP on Ubuntu 14.04
Introduction Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. Tengine is a branch of Nginx which is created by Alibaba Inc. MariaDB is a database server developed by some of the original authors of MySQL and offers drop-in replacement functionality. Note: This guide is from 2014 and builds every component from source on Ubuntu 14.04, which has long since reached end-of-life. On a current system you would install Tengine/Nginx, MariaDB, and PHP from the official APT repositories and manage them with systemd instead of the SysV init.d scripts shown below. It’s kept here as a historical walkthrough.
Difference Between require and include in PHP
One of the most common questions I get from PHP beginners is: why are there four different ways to pull one file into another? There is include, include_once, require, and require_once. They look almost interchangeable, but picking the wrong one can either hide a fatal bug or crash a page that should have kept running. The four are really just combinations of two independent choices: include vs require: what happens when the file is missing. include emits a warning and keeps going; require stops the script with a fatal error. plain vs _once: how many times the file may be loaded. The plain form loads the file on every call; the _once form loads it at most once per request. One note before we start: despite the parentheses you often see, include and require are language constructs, not functions. Both require 'core.php'; and require('core.php'); work, but the manual recommends the parenthesis-free form, which is what I’ll use throughout.