David Xia

Author Archives: David

Turn Mac OS X Lion Into a LAMP Web Server (Without MAMP)

Lots of developers use MAMP for local PHP development. There’s nothing wrong with MAMP. It works. But I wanted to find out how to use the pre-installed Apache and PHP in Lion.

Prerequisites

Ensure these directories exist:

$ sudo mkdir /usr/local/include
$ sudo mkdir /usr/local/bin
$ sudo mkdir /usr/local/lib
$ sudo mkdir -p /usr/local/man/man1

Setup Apache2

$ sudo chmod u+w /etc/apache2/httpd.conf
$ sudo vim httpd.conf

Uncomment #LoadModule php5_module libexec/apache2/libphp5.so.

To enable virtual hosts, uncomment #Include /private/etc/apache2/extra/httpd-vhosts.conf.

Enable .htaccess files by finding Directory… more

Leave a comment

Proof of the Irrationality of √2

The Pythagoreans, a wacky bunch of integer-worshipping Greeks, were so against the notion of irrational numbers that they supposedly murdered the poor soul who leaked their existence. In honor of Hippasus, we’ll prove that \(\sqrt{2}\) is irrational, ie \(\sqrt{2}\) can’t be expressed \(\frac{p}{q}\) for some \(p, q \in \mathbb{Z}\). We’ll do a proof by contradiction.

Let’s assume \(\sqrt{2}\) is rational. Then \(\exists a, b, \in \mathbb{Z}: \sqrt{2} = \frac{a}{b}\). \(a\) and \(b\) have a greatest common divisor and by dividing each by the gcd, we obtain an equivalent fraction \(\frac{p}{q}\) that’s in lowest terms, i.e. \(p, q \in… more

1 Comment

Euclid’s Algorithm

What’s the greatest common divisor (gcd) of X and Y? It turns out there’s a nice algorithm for calculating this – the Euclidean Algorithm.

Common Divisor Divides Integer Combination

Let \((D, +, \cdot)\) be an integral domain.

Let \(c\) be a common divisor of two elements \(a\) and \(b\) of \(D\), i.e.:

$$a, b, c \in D: c|a \wedge c|b$$

Then:

$$\forall p, q \in D: c|(pa + qb)$$

Proof:

\begin{aligned}
c|a \implies & \exists x \in D: a = xc \\
c|b \implies & \exists y \in D: b = yc \\
& \forall p, q \in D: pq + qb = pxc + qyc = (px + qy)c \\
\implies & \exists z \in D: pa + qb = zc \\
\implies & c | pa + qb
\end{aligned} more

Leave a comment

Dieter Rams – Less But Better

I just finished reading the monograph Dieter Rams: As Little Design as Possible. The book covers the life and work of the influential German industrial designer whose hundreds of products are still manufactured and whose principles are still practiced.

This was my first introduction to Rams, but I recognized his work in the 606 Universal Shelving System, Braun shavers, and the SK4 record player. These products were so successful they set the standard design for whole classes of products to follow. For example, I’ve never seen a record… more

Leave a comment

How to Install Vim 7.3 on Ubuntu 10.04 with Ruby and Python Support

I wanted to use Vim’s Command-T plugin (via this awesome Vim config) for fast file navigation. But this plugin needs Vim to be compiled with Ruby support since it’s is written in Ruby. You can check with

vim --version

Unfortunately, I saw “-ruby” which means it lacks Ruby support. I was previously using Vim 7.2 on Ubuntu 10.04 Lucid. First I uninstalled my old Vim and installed dependencies required to compile a new one:

sudo apt-get remove vim-common vim-runtime vim-gtk vim-gui-common
sudo apt-get
Leave a comment

Don’t Call Me Smart

People often tell me, I’m a “smart” guy. I have two beefs with this statement. It implies that there’s one type of intelligence, usually the logical, analytical kind, and that my smarts are an innate quality rather than an achievement.

The prevailing notion of intelligence is a narrow and limiting one that fails to embrace the multitude of human abilities. We define intelligence too often as the ability to analyze rationally and think deductively. Kids are increasingly, in the words of Sir Ken Robinson, educated “from the neck up.” What about… more

1 Comment

David Foster Wallace on American Consumer Culture

I recently watched some interviews of David Foster Wallace. It’s fascinating to hear him speak. He’s a deeply intelligent, neurotic, and sentimental man.

My favorite parts are when DFW talks about American consumer culture. He describes the US as “one enormous engine and temple of self-gratification,” which works very well in growing the economy but doesn’t nourish other parts of people.

For young people in America, there are very mixed messages from the culture. There’s a streak of moralism in American life that extols the virtues… more

Leave a comment

How I Increased My WordPress Site’s Speed

I spent yesterday optimizing the performance of this site. I love fast page loads and have little patience for sluggish performance. Here’s what I did.

1. Leverage browser caching

Tell your web server to set expiration headers for static resources so browsers know to store them in local disk. This will keep requests off the network altogether. I use Apache:

 ExpiresActive On
 ExpiresDefault "access plus 300 seconds"
 ExpiresByType text/css "access plus 1 month"
 ExpiresByType text/javascript "access plus 1 month"
 ExpiresByType application/javascript "access plus 1 month"
 ExpiresByType application/x-javascript "access
Leave a comment

How to Setup HTTPS and Secure WordPress Admin With a Self-Signed Certificate

I got bored so I learned how to setup HTTPS on the admin parts of my WordPress blog. At first I was generating self-signed certificates because I read that buying a third-party verified certificate could cost upwards of $100 per year.

Then I saw this Ars article on getting a legit one for free.

After enabling mod_ssl on Apache and following the Ars guide above, I was ready to secure the admin parts of WordPress. The general idea is to

Leave a comment

How to Deploy Python Web App with Apache’s mod_wsgi

For quite a while I couldn’t figure out how to deploy Python web apps. But with patience and tinkering, I slowly figured it out.

Here were my steps:

1. Setup Domain

I created an A record for python.davidxia.com in my DNS records pointing to the IP of the server on which I developed.

2. Setup Apache VirtualHost

I put this in /etc/apache2/sites-available/davidxia (using Ubuntu 10.04):

 
 ServerName python.davidxia.com 
 
 WSGIDaemonProcess myapp user=www-data group=www-data processes=1 threads=5
 WSGIScriptAlias / /path/to/myapp/myapp.wsgi
 WSGIScriptReloading On 
 
 WSGIProcessGroup myapp
 WSGIApplicationGroup
Leave a comment