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

April Fools Pranks with a Squid Proxy Server
Introduction Note: This guide was tested using Ubuntu Server 14.04.4 LTS. This is a HowTo for setting up Upside-Down-Ternet on Ubuntu. Basically, when a user browses the web, all the images are flipped upside-down. While it’s not useful, it’s quite a good April Fool’s prank. The process uses a transparent proxy, web server, and script to flip the images. Web traffic is routed to the proxy, instead of the default gateway, which is intercepted by the proxy which then downloads and modifies the images and then serves them back to the client browser.
Signing commits using GPG in Git
Git is cryptographically secure, but it’s not foolproof. If you take work from others on the internet and want to verify that commits are actually from a trusted source, Git can sign and verify work with GPG. Generate a GPG Key To sign anything, you first need GPG installed and a personal key. Check whether you already have one: gpg --list-keys /home/hzxie/.gnupg/pubring.gpg ------------------------------ pub 4096R/3DBF9592 2016-02-15 uid Haozhe Xie (GPG key for GitHub) <noreply@haozhexie.com> sub 4096R/BFEB9969 2016-02-15 If the list is empty, generate a key. On GPG 2.1 and later, --full-generate-key lets you choose the algorithm and a 4096-bit RSA key, which GitHub recommends:
Random Projection
Introduction In mathematics and statistics, random projection is a technique used to reduce the dimensionality of a set of points which lie in Euclidean space. Random projection methods are known for their simplicity and low error rates compared with other dimensionality-reduction techniques, and experiments show that they preserve pairwise distances well. Consider a problem as follows: We have a set of $n$ points in a high-dimensional Euclidean space $\mathbf{R}^d$. We want to project the points onto a space of low dimension $\mathbf{R}^k$ in such a way that pairwise distances of the points are approximately the same as before.
Decision Tree
What’s a decision tree? A decision tree is a flowchart-like structure in which each internal node represents a “test” on an attribute (e.g. whether Income is below 50K), each branch represents an outcome of that test, and each leaf node holds a prediction: a class label for classification, or a value for regression. A path from the root to a leaf is therefore a chain of conditions that ends in a decision.
Introduction to Java Virtual Machine
Note: This article has been updated for Java 8 and later. The original 2015 version described the Permanent Generation (PermGen), which Java 8 removed and replaced with Metaspace (JEP 122); the garbage-collection section has also been rewritten to cover the modern HotSpot collectors (G1, ZGC, Shenandoah). The behaviors described here are those of HotSpot; other JVM implementations may differ. What is JVM? The Java Virtual Machine is the cornerstone of the Java platform. It is the component responsible for Java’s hardware and operating-system independence, the small size of its compiled code, and its ability to protect users from malicious programs.
Use Server-Sent Events in Spring MVC
Server-Sent Events (SSE) let a server push a continuous stream of updates to the browser over a single long-lived HTTP connection. Spring has supported them since version 4.2 through the SseEmitter class, and the API has been stable ever since. This post is a practical how-to: we start with a bare SseEmitter, then build the setup I actually use in production, streaming events from a message queue to the browser.
Use WebSockets with Spring, SockJS and Stomp
This guide walks you through building a “hello world” application that sends messages back and forth between a browser and the server. WebSocket is a very thin, lightweight layer on top of TCP, which makes it a natural place to run a subprotocol that gives the raw bytes some structure. Here we use STOMP messaging with Spring to create an interactive web application. Note: This post has been updated for Spring 6/7. The WebSocket setup now uses @EnableWebSocketMessageBroker Java configuration and the modern @stomp/stompjs client. The original 2015 version targeted Spring 4.1 with XML <websocket:message-broker> config and the legacy Stomp.over() API; both are obsolete and have been replaced throughout.
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.