May 22nd, 2010
I like using HTTPS whenever possible. Usually this is as simple as adding a single letter to a URL, but some sites have separate domains for SSL. The Wikimedia sites are a great example of this; they share the domain secure.wikimedia.org and use the first elements of the path to specify the site.
Now, I could have set up a Greasemonkey script to redirect me once I hit an unsecure Wikipedia page, but then it's too late. (I'm usually going directly to the article via web search results.) I could also use Greasemonkey to rewrite URLs in web pages, but that's a mess. Instead, I wanted to intercept any requests to unsecure Wikipedia and redirect them on the fly, before they even left my machine. Here's how I set up my browser to always use SSL for Wikimedia sites:
- Have Apache with virtual hosts and Mozilla Firefox with FoxyProxy
- In my default virtual host:
<Directory /var/www/>
RewriteEngine On
RewriteBase /
RewriteCond ${HTTP_HOST} !.*mycomputername.*
RewriteRule . rewriter.php [L]
</Directory>
- And this file at /var/www/rewriter.php:
<?php
$host = $_SERVER['HTTP_HOST'];
$path = $_SERVER['REQUEST_URI'];
// ensure path is not of form http://...
if(strpos($path, '/') !== 0) {
$start = "http://$host/";
if(strpos($path, $start) === 0) {
$path = substr($path, strlen($start) - 1); // include slash
} else {
die();
}
}
if(preg_match('/([a-z0-9]+)\.wikipedia\.org/', $host, $m_domain)) {
header("Location: https://secure.wikimedia.org/wikipedia/{$m_domain[1]}{$path}");
die();
}
?>
- Then set up a proxy in FoxyProxy, early in the chain, called "rewriter". Set it to a SOCKS 5 proxy at localhost:80, using the whitelist regex
http://[a-z]+\.wikipedia\.org/.*
Obviously, the setup as written here only gets Wikipedia, but it could easily be expanded to Wiktionary, Wikibooks, Wikimedia Commons, and other sister sites.
I'll delete any tech-support questions in the comments area, so don't ask them. This guide is for advanced users only. Discussions of potential improvements are welcome.
1 comment | Posted in -no category-
March 14th, 2010
One of the constant dilemmas I encounter in software development is where to put files. In theory, it doesn't matter; I can set the lookup paths and file references however I want, and the software will compile and run. In practice, I feel it is one of the biggest factors in how comfortable I am developing a project. As a programmer, I need to be able to reload a big ol' wad of context whenever I switch projects, and the directory structure serves in part as external memory. Refactoring, collaboration, permissions, and deployment are all made easier by proper directory structures and naming. Code rot, the scourge of long-running projects, is multiplied by poor initial code management decisions. In short, file management makes a lot of little differences that can make or break a project in the long term.
Usually, the standard hierarchical filesystem model is perfect. I have a project Foo, it contains folders for source, compile info, and binaries, and each of those folders is probably hierarchical as well. The source and binary folders usually have matching subdirectory structures, but that particular duplication of structure is OK, because the binaries folder is generated, not edited; I never have to think about changing both directory structures at the same time.
This standard model fails when I have to work with multiple related projects. If I put the Foo and Bar projects side by side, I notice that both have src and bin directories. Perhaps I should have a src folder and bin folder instead, each subdivided into Foo and Bar directories! Each has advantages and disadvantages that are immediately obvious. This is known as the problem of cross-cutting concerns, where there are strong yet orthogonal organizational principles that compete for priority.
I like to imagine that we would be better off with a new filesystem model, perhaps one based on matrices, tagging, smart searches, filters, or DAGs. I don't know what the right answer is, but I'd like to hear your thoughts on the matter.
No comments | Posted in Challenges in software engineering
August 13th, 2009
As javascript engines increase in speed and efficiency, it is becoming feasible to write compilers and interpreters in javascript to allow webpages to run alternative programming languages not normally supported by browsers. See processing.js, for instance: A graphics library that runs a Java-like language in the browser.
An initial hurdle facing developers of these toolkits is the problem of loading source code. Javascript is loaded and executed natively in the browser environment, and it would be nice to load alternative language sources in a similar manner. So, today I wrote a library to do that.
The library, called LoadForCompile, is invoked with a MIME type and a callback. It searches the DOM for script elements with the given MIME type, loads their sources, and passes them to the callback. There is a very simple demo page with a "compiler" that displays whatever source code it is provided. Following is the documentation for the library.
Description
LoadForCompile will retrieve alternate-language source code and pass it (in order) to onLoad. Any sources that cannot be retrieved will be ignored by default.
If the onFinish argument is provided, it will be called when all sources have been loaded and passed.
If the onError argument is provided, it will be called with (src, k), where src is the offending URL and k is a continuation of the loading process, so the relying client may continue or entirely halt the loading process by calling k or not calling it, respectively.
Usage
- Place script elements in your HTML document with desired MIME type.
- Each script element may have a
src attribute, an inline body between the opening and closing tags, or both. The body is guaranteed to be called immediately after the associated remote source, or not at all.
- Finally, call LoadForCompile with the MIME type and callbacks.
Specification
LoadForCompile searches the DOM for any script nodes bearing the target MIME type. For each one, it records the src attribute and the contents of the text node, if any. It is an error to have non-text elements as children of the script node, and in such a situation the behavior of this library is unspecified.
The library uses asynchronous requests to load any remote resources specified by src attributes. This loading occurs in an unspecified order. If any remote source fails to load, the library will mark that source (and any associated inline body) as invalid. If onError is provided, it will be called with a continuation function that will resume progress. (If the continuation is not called, no additional callbacks will be made.)
Note that if onError is provided and does not call the continuation, onFinish will not be called.
The library is in version 0.2 and is licensed under the LGPL.
No comments | Posted in Software
August 9th, 2009
The "system beep" (or "system bell") can be quite annoying. Instead of disabling it altogether, you may be able to change it to something a little less irritating. Some operating systems will allow you to change it to a visual alert or a sound file of your choice. Today, I'll show you how to change the duration, pitch, and volume to something less grating if you're using X.Org (applies to just about all Unix or GNU/Linux systems.) [via]
I use xset, a command that can set various preferences in the current X display. One of the parameter sets is b, the properties of the system bell. It can be used to set the relative volume, pitch, and duration. Here's an example:
xset b 50 700 5
That example sets the system bell to 50% volume, a pitch of 700 hertz, and a duration of 5 milliseconds.
Experiment by entering that command, then pressing [Backspace] on the next line of your terminal (to generate a system bell.) Your hardware may not support certain combinations, in which the bell is silent.
To have this setting take effect every time you log in, add it to your session startup commands. In Ubuntu, that's System :: Preferences :: Sessions.
No comments | Posted in Solutions
July 15th, 2009
The GWT is a set of programs that allows developers to write Java code and compile it down into Javascript to be run on browsers. This requires you to use the subset of Java that the toolkit can emulate, but the compile-time and runtime error messages it displays are often not very useful.
I was developing a GWT application with Eclipse and ran into a client-server communication issue that manifested at runtime. The client would request an object from the server, the object would properly serialize and deserialize (verified by JS debugger), and then GWT's glue code would throw IncompatibleRemoteServiceException (saying "This application is out of date, please click the refresh button on your browser.")
Read full entry »
No comments | Posted in Solutions