Easily Test Web Sites Locally with Apache VHosts
When developing and testing web sites, I set up temporary fake domains like example.local using /etc/hosts and map them to directories using Apache's Virtual Host feature. This allows each site to have its own root directory rather than being in a subdirectory of localhost, allowing the use of paths relative to / .
Here's a little script to make setting up localhost virtual servers on Apache easier:
#!/bin/bash
# http://blog.kevinmehall.net/2009/apache-local-vhosts
# public domain
echo "127.0.0.1 $1" >> /etc/hosts
cat >> "/etc/apache2/sites-enabled/$1" << EOF
<VirtualHost *>
DocumentRoot $2
ServerName $1
</VirtualHost>
EOF
/etc/init.d/apache2 reload
Put it in /usr/local/bin/add-local-server and sudo chmod +x /usr/local/bin/add-local-server.
Run with sudo add-local-server example.local /path/to/server/root.
It adds an entry in /etc/hosts, sets up a config file for Apache, and then reloads the Apache configuration.
Tested on Ubuntu; may require modification for other distros.
Removing the sites must be done manually:
-
Remove the entry from
/etc/hosts -
Delete the file in
/etc/apache2/sites-enabled
Announcing EquationExplorer
My latest project is now available online: EquationExplorer.
There was a notable lack of tools (especially free ones) capable of graphing implicit functions. So, I decided to build my own. Being a web page and not requiring an install greatly increases its utility. Hopefully it can be a useful resource for teachers, students, or anyone interested in visualizing algebraic equations.
Graphing explicit functions is easy; just scan across the X axis, plotting points. But an algorithm to graph implicit equations is not as obvious or simple. EquationExplorer does it by scanning through each pixel twice, going both left to right and top to bottom. The equation is rewritten as a subtraction (i.e. x^2 + 2 = x becomes x^2 + 2 - x). At each pixel scanned, the value of that expression is evaluated, and compared to the value at the previous pixel. If they differ in sign, it means the expression crossed 0 somewhere in between, and therefore the equation was true somewhere within that pixel. It then does some work to find the the point more precisely (for antialiasing), and plots the pixels.
Amazingly, that is fast enough, even in Javascript, to render in near-real-time as the user is typing. In the most recent releases of the TraceMonkey, V8, and JavascriptKit engines especially so, but it works just fine in SpiderMonkey in Firefox 3.0. You'll need a fairly recent browser, in any case, because it depends on the new HTML5 features like Canvas. Internet Explorer is not supported. (Which was nice, because I had an excuse not to have to work around all the IE bugs that every web developer has come to despise.)
What Web 2.0 Means for Content Production
In the spirit of Web 2.0 (a somewhat nebulous term, but...), this site is now served as 100% static HTML.
"What?", you may ask — "Isn't Web 2.0 all about making sites more dynamic?"
In fact, this site became more dynamic by dropping the server-side code. The dynamic components are simply now moved off my server and into the cloud. Commenting has gone to Disqus, and search has gone to Lijit. These free services provide better tools than my previous Drupal install, and are easier to set up and manage. Users may be already be familiar with these services, or may already have accounts. In the few weeks I've used Disqus, the number of comments has increased dramatically.
Editing is easier for me, using only plain text Markdown files managed with the same tools I use for coding: Gedit and bzr. A custom python script (open source release forthcoming) transforms the markdown files into HTML with templating applied, and bzr's upload plugin pushes the site up to the server. Oh how the site flies when everything is static, cacheable content!
Web 2.0 is almost a return towards the original vision of the creators of the Web, that everyone would have the ability to easily publish. The social content production tools further democratize the production and dissemination of information. No longer do content documents need to be be backed by database-driven behemoths to do the templating and dynamism everyone expects. The web has become a set of URI-identified documents with a set of social tools layered on top for meta-services such as sharing and commenting.
The content sharing services need to be centralized around the users, but the content itself can sit anywhere. Layers form organically around the content with user discussion and linking, providing value by selecting the best content and providing personal opinion. Infrastructure centralizes around the users, rather than around the content. That is really the defining concept of Web 2.0: a focus on the users, on everybody, rather than on the centralized silos of the traditional media and large corporations. The location of the content doesn't matter so much anymore; it gets to the users the same way, whether it's via RSS or because a friend shared it on Facebook. With this shift in infrastructure, the power goes to the people.
What is Web 2.0 to you? Respond to this article in the new, Disqus-powered, comment area.
Dell Studio 15n Review
There are tons of reviews of this laptop, but few cover the Linux version. I'm therefore going to focus more on the Linux-specific things.
I left Ubuntu 8.04 on the machine rather than upgrading to 8.10 Intrepid. I've tried 8.10 and Jaunty Alpha Live CDs, and they seem to work, but aren't quite worth upgrading for. Maybe when the Jaunty 9.04 final is released...
I have the LED backlit display, which is really bright and seems whiter than a CCFL backlight. It also certainly seems to help with battery life.
The battery easily lasts upwards of 4 hours (lowered brightness, but with wireless on). The GNOME power applet reports power usage of about 12.4W idle on battery. A Kill-A-Watt power meter measures about 19W at the outlet at full brightness, and 16W dimmed. Much better than my old desktop (with CRT monitor) at upwards of 400W!
Suspend and hibernate work most of the time out of the box, and I've found a fix (click here) for completely reliable resumes. Before, it would occasionally freeze upon resume. It also wouldn't reconnect to Bluetooth devices upon resume and required a sudo /etc/init.d/bluetooth stop; sleep 1; sudo /etc/init.d/bluetooth start. (The restart action doesn't work; a separate stop and start is necessary, for whatever reason).
Two quirks with suspend still remain: Sometimes it makes a popping noise (from the speakers) when it suspends. Sometimes a suspend/resume cycle changes the text console backgrounds to green, blue, white, orange, or pink, which are seen for a few seconds while resuming, or if you press CTRL-ALT-F1. Weird, but not critical.
The built-in camera works with the Cheese Photo Booth that comes with Ubuntu. Quality is okay for videoconferencing, but significantly grainy, especially in dim light.
Overall, I'm quite happy with this computer, and am glad that Dell offers it with Ubuntu preinstalled.
Do not go where the path may lead, go instead where there is no path and leave a trail.
— Ralph Waldo Emerson
Via a booklet from Olin College
Syncing Rhythmbox with a Portable Player
The default GNOME music player, Rhythmbox, lacks the ability to synchronize with a portable media player. There are some plugins available for the iPod, but I could find none that sync to players, such as mine, that appear as a USB flash drive.
The widely-recommended solution is to use rsync to copy the music folder onto the device. That doesn't work if you want only certain playlists synchronized, or if most of your music is in Ogg Vorbis and your player supports only MP3, however.
So I wrote a python script that grabs the list of songs on a playlist using the Rhythmbox DBUS API, and synchronizes them to the player, re-encoding them to MP3 with LAME. When tracks are removed from the playlist, they also get deleted from the player.
The program reads a configuration file in the root directory of the player that tells it which playlists to sync to which folders, and allows configuring LAME options such as bit rate and quality.
This script, combined with Rhythmbox's Automatic Playlists to filter for rating and limit size, provides a really powerful way to manage music and podcasts on a portable player.
It's probably not currently usable for the average user (it needs a GUI configuration tool, among other things), but it works for me. If you have questions about using it, feel free to post a comment.
Source code is hosted on Launchpad at https://launchpad.net/rhythmbox-playlist-sync
Is God an Accident?
Recently psychologists have discovered two related facts that may account for the existence of religion. One: human beings come into the world with a predisposition to believe in supernatural phenomena. And two: this predisposition is an incidental by-product of cognitive functioning gone awry.
Sorry about yet another link and the paucity of actual original content, but this is another one of those articles that is just too thought provoking to pass up. Paul Bloom explains that religion stems from the same psychology as our ability to see a face in the craters of the moon.
They [U.S. soldiers] are also building schools for the Afghan children so that there is hope and opportunity in our neighboring country of Afghanistan.
- Sarah Palin (via)
Does this mean she can see Afghanistan from Alaska too?
Blender3D Dominoes
My brother and I made this animation of falling dominoes in Blender3D:
See the Blender3D Rigid Body animation tutorial to learn how it was made. We made 200 dominoes instead of the 7 in the tutorial!
The Six Dumbest Ideas in Computer Security
Good engineering is hard. It's too easy to fall into these traps of bad design.
“We welcome you back to our coverage of the 2008 Olympics in Beijing, brought to you by human rights violation in China, makers of the oppression of Tibet”
