Tech Diary
TIL

status.twitter.com is a Tumblr blog.

Today I set up Apache user-level hosting.

Command:

/usr/sbin/httpd -f ~/Library/usr/etc/apache2/httpd.conf

I made this into a LaunchAgent.

~/Library/usr/etc/apache2/httpd.conf:

Apple removed the Web Sharing from the Sharing prefpane, but Apache is still installed and I managed to find /System/Library/LaunchDaemons/org.apache.httpd.plist.

Don’t run as a different user:

# User _www
# Group _www

Write logs to user-owned locations:

ErrorLog "/Users/Me/Library/Logs/apache2/apache2.log"

Same with PidFile and LockFile, although these need to go at the end to prevent being overridden by Include /private/etc/apache2/other/*.conf:

PidFile "/Users/Me/Library/Logs/apache2/apache2.pid"
LockFile "/Users/Me/Library/Logs/apache2/apache2.lock"

Add CGI and .htaccess support:

<Directory "/Users/Me/Library/WebServer">
    AddHandler cgi-script .cgi .pl
    Options Indexes FollowSymLinks MultiViews +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Put virtual host information in a separate file:

Include /Users/Me/Library/usr/etc/apache2/hosts.conf

Not sure if this is good, but I didn’t like the idea of keeping many httpd processes around.

MaxClients 5

~/Library/usr/etc/apache2/hosts.conf:

Listen 1234
<VirtualHost *:1234>
    DocumentRoot "/Users/Me/Library/WebServer/1234"
</VirtualHost>

Not sure if ~-relative paths were allowed, so I kept it absolute.

cat ~/ confidential_information.txt | pbcopy
pbpaste > confidential_information.txt

(via Stack Overflow)

In the beginning there was NCSA Mosaic, and Mosaic called itself NCSA_Mosaic/2.0 (Windows 3.1), and Mosaic displayed pictures along with text, and there was much rejoicing.

And behold, then came a new web browser known as “Mozilla”, being short for “Mosaic Killer,” but Mosaic was not amused, so the public name was changed to Netscape, and Netscape called itself Mozilla/1.0 (Win3.1), and there was more rejoicing. And Netscape supported frames, and frames became popular among the people, but Mosaic did not support frames, and so came “user agent sniffing” and to “Mozilla” webmasters sent frames, but to other browsers they sent not frames.

And Netscape said, let us make fun of Microsoft and refer to Windows as “poorly debugged device drivers,” and Microsoft was angry. And so Microsoft made their own web browser, which they called Internet Explorer, hoping for it to be a “Netscape Killer”. And Internet Explorer supported frames, and yet was not Mozilla, and so was not given frames. And Microsoft grew impatient, and did not wish to wait for webmasters to learn of IE and begin to send it frames, and so Internet Explorer declared that it was “Mozilla compatible” and began to impersonate Netscape, and called itself Mozilla/1.22 (compatible; MSIE 2.0; Windows 95), and Internet Explorer received frames, and all of Microsoft was happy, but webmasters were confused.

And Microsoft sold IE with Windows, and made it better than Netscape, and the first browser war raged upon the face of the land. And behold, Netscape was killed, and there was much rejoicing at Microsoft. But Netscape was reborn as Mozilla, and Mozilla built Gecko, and called itself Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826, and Gecko was the rendering engine, and Gecko was good. And Mozilla became Firefox, and called itself Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.7.5) Gecko/20041108 Firefox/1.0, and Firefox was very good. And Gecko began to multiply, and other browsers were born that used its code, and they called themselves Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.2) Gecko/20040825 Camino/0.8.1 the one, and Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.8) Gecko/20071008 SeaMonkey/1.0 another, each pretending to be Mozilla, and all of them powered by Gecko.

And Gecko was good, and IE was not, and sniffing was reborn, and Gecko was given good web code, and other browsers were not. And the followers of Linux were much sorrowed, because they had built Konqueror, whose engine was KHTML, which they thought was as good as Gecko, but it was not Gecko, and so was not given the good pages, and so Konquerer began to pretend to be “like Gecko” to get the good pages, and called itself Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD) (KHTML, like Gecko) and there was much confusion.

Then cometh Opera and said, “surely we should allow our users to decide which browser we should impersonate,” and so Opera created a menu item, and Opera called itselfMozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.51, or Mozilla/5.0 (Windows NT 6.0; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.51, orOpera/9.51 (Windows NT 5.1; U; en) depending on which option the user selected.

And Apple built Safari, and used KHTML, but added many features, and forked the project, and called it WebKit, but wanted pages written for KHTML, and so Safari called itself Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5, and it got worse.

And Microsoft feared Firefox greatly, and Internet Explorer returned, and called itself Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) and it rendered good code, but only if webmasters commanded it to do so.

And then Google built Chrome, and Chrome used Webkit, and it was like Safari, and wanted pages built for Safari, and so pretended to be Safari. And thus Chrome used WebKit, and pretended to be Safari, and WebKit pretended to be KHTML, and KHTML pretended to be Gecko, and all browsers pretended to be Mozilla, and Chrome called itself Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13, and the user agent string was a complete mess, and near useless, and everyone pretended to be everyone else, and confusion abounded.

/var/folders

Recently, each time I plugged in a flash drive into my Mac, it would slowly freeze app-by-app, dying a slow death that could only be solved by a reboot. But it would do the same thing next time the flash drive (rather, any flash drive) was introduced.

I solved this by deleting /var/folders and rebooting.

Relevant: http://blog.egopoly.com/2009/04/14/varfolders-are-you-kidding-me/

http://arstechnica.com/civis/viewtopic.php?f=19&t=42677

getconf DARWIN_USER_CACHE_DIR

man hier

Aaron Swartz, in a 2009 interview with Ronaldo Lemos:

When I was a kid, I thought a lot about what made me different from the other kids. I don’t think I was smarter than them and I certainly wasn’t more talented. And I definitely can’t claim I was a harder worker — I’ve never worked particularly hard, I’ve always just tried doing things I find fun. Instead, what I concluded was that I was more curious — but not because I had been born that way. If you watch little kids, they are intensely curious, always exploring and trying to figure out how things work. The problem is that school drives all that curiosity out. Instead of letting you explore things for yourself, it tells you that you have to read these particular books and answer these particular questions. And if you try to do something else instead, you’ll get in trouble. Very few people’s curiosity can survive that. But, due to some accident, mine did. I kept being curious and just followed my curiosity.

(via Daring Fireball via Dave Winer.)

Killing appleeventsd

Today I finally found an acceptable solution to a problem I’ve been having for many months now. I’ve learned some things along the way, so I just wanted to write this up now before I forget.

The problem

I’m on Mac OS 10.8.2. Sometimes, when I ⌘-/control-click the document proxy icon in document-based windows and select a parent folder, nothing happens. :/

Why it occurs: I’m actually still not completely sure why, but I know it has to do with Apple Events. Killing the appleeventsd process, which is owned by the user Apple Events User (shortname _eppc, searchable via dscacheutil -q user), will cause appleeventsd to restart and everything will be a-okay.

The sub-optimal, interim solution

Activity Monitor » View: All Processes » Filter: applee » Select: appleeventsd » Quit » Force Quit

Why it’s sub-optimal: too many steps.

The alternate solution that doesn’t work

sudo killall -u _eppc appleeventsd

Why it doesn’t work: I didn’t know, but afterwards, apps that try to send an Apple Event would freeze, and my computer would die a slow death and could only be resurrected with the equivalent of a hard reset. (The ‘nicest’ alternative I found was sudo launchctl shutdown.)

The red flag

I’ve noticed that processes ‘killed’ with kill or killall don’t always respond the same way as when they’re killed with Activity Monitor. I once suspected that Activity Monitor was doing some kind of ‘soft’ kill, sending some signal other than KILL, but I had a feeling I tested that idea and it turned out to be not true. But wait that must mean that…

Epiphany

kill is not actually sending KILL signals! Indeed this turned out to be the case. I haven’t taken the time to find out what it is sending, but I bet it’s something like HUP. This would offer an explanation to why the alternate solution didn’t work: upon receiving the HUP signal from kill, appleeventsd must have freaked out and caused irreversibile mayhem (i.e., preparing for shutdown)

Solution

sudo killall -KILL -u _eppc appleeventsd

More precisely, I have a setuid’d executable compiled from the following:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, const char * argv[])
{
    chdir( "/" );
    setuid( 71 );
    system( "killall -KILL -u _eppc appleeventsd" );
}

The end.

A ranty website from some guys selling UNIX-like tools.

I agree with them, to some extent. The tools are expensive, though.

onethingwell:

GNU Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place.

Originally designed to ease the installation and removal of packages built from source, Stow is also a great way to manage your dotfiles.

First, you need to organise per-application directories in ~/dotfiles so that each one mirrors the intended location of files in ~/. For example:

~/dotfiles/ zsh/ .zshrc .zshrc.pre .zshrc.local 

Now, to install those ZSH configuration files, just do:

cd ~/dotfiles stow zsh 

and stow will symbolically link

~/dotfiles/zsh/.zshrc 

to

~/.zshrc 

and so on.

Removing a batch of configs is just as easy:

stow -D zsh 

And if you’d like to keep your dotfiles in, say, ~/Dropbox/dotfiles instead of ~/dotfiles? No problem:

stow -t ~ zsh 

This might look like overkill for a few files that you could manually symlink or copy into place in a trice, but when it comes to managing more complex configuration setups—e.g. applications which use both $XDG_CONFIG_HOME and $XDG_DATA_HOME—or deploying different sets of files for different platforms, Stow is a real timesaver.

It also has a distinct advantage over other dotfile management utilities: you don’t have to learn a developer’s preferred directory structure or file naming conventions, there’s no fiddling about with metadata, and no extraneous features like file backups or versioning. All you need to know is the proper place to put your configuration files.

 See also

rogerchen:

This kind of inept engineering needs to be exposed and the company, publicly shamed. There are just too many cases where companies in charge of our financial infrastructure implement these ridiculous security policies that put everybody at risk. What other incentive can we use against them to hold them to their responsibilities?

oh gawwwwwd