Prosthetic Conscience

Jason McBrayer's weblog; occasional personal notes and commentary

Wed, 22 Oct 2008

Inspired by xkcd

Oracle’s a well-known dee-bee
But there’s also many freebies.
How should you the choices cull?
Choose one where ” IS NOT NULL.
BURMA SHAVE

Now thank your lucky stars I didn’t post the lines one at a time as article titles to get them to show up one-by-one in Planet Emacsen.

[ Posted: 19:30] | [ Category: ] | Permalink | Comments: 0 ]

Sun, 12 Oct 2008

Wrapper script for emacs using –daemon

For quite a while, I’ve used a variety of scripts for starting emacs, starting with dtemacs from gnuclient, which I modified in various ways to work the way I wanted it with Gnome and from the command line. The new daemon-mode in CVS emacs, combined with multi-tty, makes it a bit simpler to write a script that you can use to edit files from your desktop environment, from a command-line with or without X available, or as an external editor from a mailer, VCS or web-browser. I’ve re-written the latest version of my emacs wrapper in terms of daemon-mode, and present it here. It’s rather shorter than my pre-daemon-mode script, and does rather more. Apologies for my bad shell-scripting style.

#!/bin/sh  

# em: a script for starting emacs as needed.  

EMACSCLIENT=emacsclient  
EMACS=emacs  

if [ -z "$DISPLAY" ]  
then  
    CLIENTARGS='-t'  
    CLIENTNEWARGS='-t'  
else  
    CLIENTNEWARGS='-c -n'  
fi  

function start_daemon() {  
    echo -n "Starting emacs in the background…"  
    $EMACS –daemon  
    while ! $EMACSCLIENT –eval t >/dev/null 2>&1  
    do  
        sleep 1  
    done  
    echo "ok."  
}  

if [ -z "$@" ]  
then  
    if $EMACSCLIENT $CLIENTNEWARGS 
    then  
        exit 0  
    else  
        start_daemon  
        $EMACSCLIENT $CLIENTNEWARGS  
    fi  
else  
    if ! $EMACSCLIENT $CLIENTARGS "$@" 
    then  
        start_daemon  
        $EMACSCLIENT $CLIENTARGS "$@"  
    fi  
fi

[ Posted: 19:00] | [ Category: ] | Permalink | Comments: 1 ]

Wed, 08 Oct 2008

Underappreciated emacs function: just-one-space

I want to very briefly praise the probably-underappreciated emacs command just-one-space. It is on M-SPC by default, and what it does is replace all the spaces and tabs around point with one space (or prefix-arg number of spaces). That’s nothing terribly fancy, but it’s one of those little things that can let you save so many keystrokes when you’re reformatting text. That and transpose-chars are among the little touches that make emacs so much more convenient than a bog-standard text editing control.

[ Posted: 06:10] | [ Category: ] | Permalink | Comments: 1 ]

Thu, 25 Sep 2008

Using Windows Search with anything.el

In a previous post, I said that I wished there were a command-line client for Windows Desktop Search (or Windows Search, or whatever M$ is calling it this week) that would give back filenames in a way useful to anything.el. Well, that comment was not entirely ingenuous, because in the time between when I wrote that article and when I posted it, I wrote one. It’s written in Python, and uses the win32com module, so you’ll need regular w32 Python installed (not Cygwin python).

The script itself is here. I recommend that you install it somewhere on your PYTHONPATH. This is because command-line argument handling is very dodgy on w32, particularly when the program is interpreted, the interpreter is a native w32 program (not cygwin), and you may be calling it from a cygwin program (such as cygwin bash). More details on installing it and its limitations on its own page.

Integrating it into anything: use the following elisp code:

(defvar w32-windows-search-program
  "python.exe -m DesktopSearch"
  "Command to pass a search string to Windows Search.
Will be split on spaces to pass to start-process.")

(defvar anything-c-source-w32-windows-search
  '((name . "Windows Search")
    (candidates . (lambda ()
                    (apply 'start-process "w32-windows-search-process" nil
                           (append
                            (split-string w32-windows-search-program)
                            (list anything-pattern)))))
    (type . file)
    (requires-pattern . 3)
    (delayed))
  "Source for retrieving files matching the current input pattern
with windows desktop search.")

The given value for w32-windows-search-program depends on DesktopSearch.py being in your PYTHONPATH. With the above in your .emacs, you can add the source it provides (anything-c-source-w32-windows-search) to anything-sources just like any other anything source.

This generally works well enough for my needs. Hopefully it will be useful to other people using emacs on w32.

[ Posted: 20:00] | [ Category: ] | Permalink | Comments: 0 ]

Fri, 19 Sep 2008

anything.el and “open with default tool” on w32

My job doesn’t often offer the opportunity to “hack the good hack.” A little while ago during toolsmithing time, I got to make a neat little hack to ‘anything’, an emacs package for locating files (or buffers, or info pages, or … anything) and acting on them. Normally, use of ‘anything’ works like this: C-x C-a to start, then start typing something to search for, arrow down through the matches, and either select the default action (open the file or switch to the buffer) with RET, or hit TAB to switch to a list of actions to select.

Here’s where the hack comes in. One of the actions you can perform on files is ‘open with default command’. The catch: this is not implemented on W32, which I have to use at work. On unix and MacOS, it this action is implemented by calling an external program — ‘xdg-start’ on unix, or ‘open’ on Mac-OS — with the filename as an argument. There is no equivalent command on W32 – the closest is the cmd.exe shell internal ‘start’. But because ‘start’ is a cmd internal, it is hard to call from emacs; the quoting may be badly messed up, for example, depending on whether you use cmd.exe or cygwin sh as your shell, etc. But here’s a better approach: leave it up to emacs. Emacs on W32 has a function ‘w32-shell-execute’ that works like cmd.exe’s ‘start’ internal.

The code to integrate this is now added to anything-config.el, a package of sample configurations for Anything. I’m now co-maintaining anything-config.el.

The practical upshot of this is that I can use ‘anything’ to find my playlist files while in emacs, and start them with Windows Media Player. Now if only Windows Desktop Search let you get text-mode search results back, or if there were a version of Tracker for W32…

[ Posted: 17:30] | [ Category: ] | Permalink | Comments: 0 ]

Thu, 18 Sep 2008

What I’m missing in Google Chrome: fast proxy switching

It’s nice that Chrome has Incognito Mode. But how incognito is it when your network admin can monitor the content of your traffic? Wouldn’t it be nice to be able to switch your network traffic to a secure channel – like an SSH tunnel to an http proxy under your control, or TOR?

Firefox has the ‘Distrust’ extension that provides the same protections as Chrome’s Incognito Mode (other than the v. stylish fedora-wearing spy logo). And it also has your choice of extensions that let you switch proxies without going into the depths of the advanced settings menu: QuickProxy, SwitchProxy, FoxyProxy, and several TOR-specific extensions. Now if only Distrust had a setting that let one turn on their proxy for the duration of the Distrust session…

[ Posted: 18:15] | [ Category: ] | Permalink | Comments: 1 ]

What I’m Missing in Google Chrome: Mouseless browsing

In Firefox, I have the Mouseless Browsing plugin installed, which lets me hit a key to label links with numbers, then type the number to follow the link. But even without MLB, you can browse mouselessly with the typeahead search – type ‘/’, then start typing the text of the link, and when the link you want is highlighted, hit enter. In Chrome, you can only tab between links, not jump directly to the one you want (even with the search function). That is, you can search for link text, and it will highlight it, but you cannot then select the link without tabbing to it from the beginning.

[ Posted: 16:00] | [ Category: ] | Permalink | Comments: 2 ]

Mon, 24 Mar 2008

What a fascinating quote:

From: http://www.mindview.net/WebLog/wiki-0051 (a comment on Bruce Eckel’s weblog)

2004/03/12 10:02 EST (via web):

About the “directing” vs. “enabling” approach, you wrote: “Both approaches are reasonable and neither is wrong. I have been in both situations; for example, trying to prevent interns from ignoring or even actively circumventing coding style guidelines (where more “direction” was required), and on the other hand being frustrated by the loss of productivity that comes from being forced to conform to constraints that I wouldn’t have violated anyway […]?”.

It is interesting that you justified the “directing” approach with an example about directing others, and the “enabling” approach with an example about enabling yourself. Don’t take this as a negative critique - I did the same when I tried to come up with examples of directing/enabling.

I tend to think that others should be directed, and I should be enabled. I worked for teams whose job was developing software methodologies and the relative supporting tools for the rest of their Company. Except that, of course, they flat-out refused to apply the (directing, strict) methodologies that they were developing to their own methodology-building project. To me, that shows how much in software development is about our own relationships and fears. We still have an awful lot to learn from sociology and antropology - and maybe, oriental philosophies.

Paolo Perrotta Bologna, Italy

I prefer “enabling” approaches everywhere, and agree with the statement that if you have someone who can’t handle an enabling approach, they don’t need directing, they need training. But many people (especially in corporate IT) would argue that this places too high a bar on experience and education for programmers. Still, I’d rather see enabling done technologically, and where direction is needed, see it done socially.

[ Posted: 19:00] | [ Category: ] | Permalink | Comments: 0 ]

Tue, 13 Nov 2007

Stockphoto 0.2.1 released

I’ve just released stockphoto 0.2.1. This is a bugfix release and contains no new features relative to 0.2. I would like to thank many people for bug reports on the previous version; plese see the credits in the README file.

I’ll be opening development on stockphoto 0.3 once I decide the best way to host a public version control repository (Google code vs. Savannah, vs self-hosting). The pre-0.3 branch will include new features, some of which are listed as to-dos in the current README.

[ Posted: 15:11] | [ Category: /django] | Permalink | Comments: 0 ]

Thu, 08 Nov 2007

Hushmail: not so hushed, aktuly.

No original reporting or opinions here. Wired has a story on how Hushmail can and will turn over plaintext emails if they receive a Canadian court order. This means that while Hushmail provides good protection against on-the-wire snooping, it doesn’t protect Alice and Bob if Mallory is in law enforcement.

I’ve recommended Hushmail to friends and neighbors in the past, as a way of easing them into the idea of using encrypted email on a regular basis. When I read this news, I felt I had to email people that I had recommended it to, to let them know about the weakness. Hushmail could set up their systems so that they never store a passphrase except in volatile memory, and so that they never store plaintext of messages. But you’d have to trust them on that, and a court order could still mandate that they store them, and not tell you they were doing it.

The best thing would be for everyone to use GNU Privacy Guard on their own computer. But it can be hard to set up, especially for Windows users (though if you’re running Windows, you have bigger security problems), and your correspondents have to all be using GnuPG or OpenPGP, too. This is a big barrier to entry, and even though I’m set up to use it, very little of my total volume of email is routinely encrypted as I’d like it to be. There is also the problem of people without their own computers, who must use shared resources such as public library computers. Hushmail appeared to be the most viable option for them.

If you are interested in using GnuPG, you might look into the Enigmail plugin for Mozilla Thunderbird as a cross-platform solution. If you’re already using Linux, Evolution groupware provides easy-to-use GnuPG support. If you want to send me encrypted email, you can download my public key, the fingerprint of which is C046 0E26 8103 ABA1 68B1 D6E7 A991 E701 91DF 7DDD.

[ Posted: 20:16] | [ Category: ] | Permalink | Comments: 0 ]

Mon, 01 Oct 2007

Apple-induced Stockholm Syndrome

See here for the source of this well-turned phrase. It ought to replace “reality distortion field” in the Mac community’s lexicon.

Basically, I’m amazed by iPhone users’ collective reaction to the bricking of their phones the same way I’m amazed by the reaction on Daily Kos to the Andrew Meyers tasing. In both cases, the affected community is mostly reacting with “hurt us more! We deserve it!”.

Contrast the OpenMoko project. Install whatever you want across a whole range of supported phones. Switch phones keeping the software you installed.

How are you going to hack your life if you can’t even hack your gizmos?

[ Posted: 09:03] | [ Category: ] | Permalink | Comments: 0 ]

Sun, 30 Sep 2007

Quoted for truth

Eclipse is emacs for stupid people ;-)
— John J. Lee-2 on python-list

[ Posted: 13:11] | [ Category: ] | Permalink | Comments: 0 ]

Tue, 24 Jul 2007

Yikes! Stockphoto on Django status update!

The last couple of days I have been seeing a renewed interest in Stockphoto, my basic, minimalist photo gallery application for Django. At the time, I wondered why, since I haven’t updated Stockphoto in the last year, nor made any announcements associated with it. Then, I saw that it had been mentioned in the Django status update on July 22.

This is just a little notice on stockphoto’s status. Stockphoto 0.2 has quite a few known bugs. I have to-do items for all of them in my personal organization system, most of them with contributed patches. I’ve just been too busy in my life to integrate all of these fixes and package them into a release. I want to do better and get two releases out the door soonish.

So here’s the release plan:

  1. Stockphoto 0.2.1, soonish. Will fix all outstanding bugs that I know about.
  2. Stockphoto 0.3, later. Will include changes to the models to allow slug-based rather than id-based URLs, and some conveniences for template designers.

Please bear with me – if you are in desperate need of a full-featured Django photogallery in the very near future, you will probably want to write it yourself, possibly looking at stockphoto’s code for examples if you are not familiar with Django’s file/image upload handling or with PIL.

Thanks for your patience.

[ Posted: 07:30] | [ Category: /django] | Permalink | Comments: 0 ]

Sat, 21 Jul 2007

Web templating systems: be opinionated enough, but no more.

There’s some current discussion in the Django community on templating systems on Jacob Kaplan-Moss’s website and elsewhere.

I agree with the general argument. There is a rather fine line between putting too much power into the templating language, so that it either becomes a programming language in its own right, or simply a means of embedding primary-language code in the templates, and putting in too little, so that you can’t do more than variable substitution. That’s not a big insight in and of itself. I think almost everyone knows this by now.

What I think is significant is this:

  1. Django’s templating system hits the sweet spot for web templating. Through a combination of good taste and (probably) luck, the Django developers have produced a templating system that strongly encourages web developers to put their controller logic and their view logic in the right place.
  2. Django’s templating system is just tightly coupled enough to make people think twice before using something else. You certainly can use other view technologies, and it’s not really hard to do so (just do everything your other template system to produce a string or a file-like object representing the content of the response, and pass it as an argument to the Django response object you’re going to return).

    But neither the documentation nor the code for Django imply anywhere that other templating systems are just as good, just as suitable, or just as well-integrated into Django. The documentation mentions that you can use them, but only gives examples of the Django templating system. The code contains many shortcuts for using the Django templating system (e.g. render_to_response()) that can’t be used with other systems.

I think the latter point should really be emphasized more. The core Django developers like to talk a lot about how Django is loosely-coupled. And that’s sort-of true, and it’s a good thing. You don’t have to buy into everything to use Django. Django applications are just plain python code; they’re written not a special mini-language. But, Django is tightly coupled enough that there is only one obvious way to do it.

Here’s what I mean by that. In my work life, I’ve been learning a more corporate-friendly web development platform, the Spring framework for Java. Mostly Spring is a good thing. It manages to drag corporate web development halfway from J2EE-hell to Django in the same way that Java dragged corporate programmers halfway from C++ to Lisp. Once you get past the Enterprise Architecture Astronautics (not as bad in Spring as in other Java frameworks, because of the extensive use of interfaces rather than inheritance) and reams of XML configuration files (apparently significantly reduced in Spring relative to other Java frameworks!) it’s actually not bad, and developing for Spring MVC is very much like developing for Django while wearing mittens – you use the same patterns, but it takes twice as long to write.

But, the frustrating thing about Spring is that it is completely non-opinionated. How shall you do database access? They don’t care, and not only do they provide wrappers for the top 10 ORM systems as they’ll as plain JDBC, they support multiple completely different styles of using one of them, which require different layers of proxy objects and (of course) different XML configuration. And view technologies? They don’t much care which of those you use, either – pick one and use it. All this may make sense in an environment where the ORM layer and view layer can be mandated by corporate policy, but it’s no way to build a framework developers can be passionate about.

(Side note: for the templating language to use with Spring, I’ve settled on Apache Velocity. It is much like the Django templating language in scope, in that it interpolates variables and their properties, offers conditional constructs and iteration over collections, and so forth, but does not constitute an entire embedded programming language, or make it too easy to drop into the implementation language. Like Django’s templating language, it is a plain text language that is not tied to generating XML output. It doesn’t have two of the nicest features of Django’s template language, template inheritance and block substitution, but these are very easy to implement yourself by following certain conventions. Velocity is much closer to the templating sweet spot than JSP/JSTL.)

Django has been accused by passionate users of other Python web application frameworks of suffering from NIH Syndrome; or to put it another way, of being too opinionated. But the NIH components of Django (the ORM and the template system) provide very good implementations of that functionality for most of the target audience. If your needs are complex enough that you have to use something else, then you probably also have the skills to deal with the consequences (for example, SQLAlchemy can map existing databases that Django’s Models can’t – but if you use it, your app doesn’t get Django’s admin functionality, and probably can’t use generic views). So it goes. But the risks of being not opinionated enough are worse:

So it’s not just that Django’s templating system hits the big bulgy middle of the bell curve, but that the project as a whole does. Opinionated, but not too opinionated. Enough salt to bring out the flavors, not enough to overwhelm them.

[ Posted: 09:56] | [ Category: /django] | Permalink | Comments: 3 ]

Fri, 20 Jul 2007

An older, more primitive world

So, does anyone else have the feeling, upon running ‘cmd.exe’ from a cygwin bash shell, that “you enter what seems to be an older, more primitive world”?

[ Posted: 19:21] | [ Category: ] | Permalink | Comments: 0 ]

Wed, 11 Jul 2007

Zenburn color schemes for Windows, Gnome

I like the Zenburn color theme for the one true editor, GNU Emacs. However, once you’re using it in one thing, you kind of want to have it everywhere. Here are a couple of simple Zenburn-like color schemes for MS-Windows (which I must use at work) and for Gnome (which I am proud to use at home).

It’s a low-contrast, dark theme for working in low-light conditions to avoid eyestrain. It’s not for everyone, and it’s not for all the time, but there are times when I need it.

[ Posted: 07:30] | [ Category: ] | Permalink | Comments: 0 ]

Mon, 11 Jun 2007

Installing Django as CGI

When Django was first released, it was only straightforwardly possible to deploy it using mod_python, for which it was designed. However, it also soon included an adapter for WSGI, the Python standard for web application servers to interface with web servers. The WSGI interface was combined with a WSGI-fastcgi gateway called flup to make it possible to host Django applications on FastCGI, and this support eventually became fully integrated with Django. FastCGI is as fast as mod_python, and is somewhat more commonly deployed, especially on commodity shared web-hosting providers.

It is also capable of running the Django app under a different user identity from the web server, either through a suexec wrapper, or by being explicitly started as a server process by another user.

However, while FastCGI is widely deployed, it is not universally deployed, and many hosting providers that support it do so poorly. This article explains how to use the Django WSGI adapter to run Django as a pure CGI application. Performance with this method is terrible, but it might still be suitable for low volume sites on commodity hosting, and especially given adequate caching. It is also a convenient harness for testing, especially for sites to be deployed as FastCGI, and it provides the same separation of privileges from the web server that Fast CGI provides.

Installing a Django project as CGI is very similar to installing it as FastCGI. These instructions presume the use of Apache 2.x. Put this script in your cgi-bin directory. It is derived from the example cgi-wsgi gateway in PEP 333. There’s a similar implementation in Django’s ticket # 2407, but I didn’t know about this when I started writing this note. (I don’t claim any great originality for this method; I just threw together existing components and banged on them until they worked.) Adjust the paths to match where you have installed your project (outside your document root, hopefully!).

Then, you install an htaccess file like this into your DocumentRoot:

AddHandler cgi-script .cgi
RewriteEngine On
RewriteRule ^media - [L]
RewriteRule ^cgi-bin - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/django.cgi/$1 [QSA,L]

This will redirect all requests under your DocumentRoot except for cgi-bin, media, and files that actually already exist, to your django cgi script. Again, you will probably have to adjust these paths for your own circumstances, and you may even have to add a RewriteBase directive or something as well.

Now test your admin app. Everything should work correctly, but slowly.

[ Posted: 19:30] | [ Category: /django] | Permalink | Comments: 2 ]

Sun, 25 Mar 2007

Lame Blog

Lame Blog is an under-powered, static content, C# and rsync based blog system. I don’t know much about it, as I’m semi-happy with PyBlosxom, and dislike C#, but it seems like a reasonable entry into the simple blogging software realm.

[ Posted: 14:05] | [ Category: ] | Permalink | Comments: 0 ]

Tue, 09 Jan 2007

NSA involved in Windows Vista

For those of you that still need a reason to switch away from Windows, the NSA, better known for warrantless wiretapping, was involved in the development of Windows Vista. NSA’s security expertise is supposed to make us feel more confident in Windows’ security, but, of course, their worrisome involvement in domestic surveillance is liable to make most of us feel the opposite. For those of you not wearing your tinfoil hats, you should immediately suppose that any security facilities in Windows have backdoors installed for NSA surveillance purposes.

(Via Bruce Schneier)

This comes on the heels of a cost analysis of Windows Vista content protection, which describes Vista’s CRAP (Cancellation, Restriction, and Punishment) system as “the longest suicide note in history.” Basically, Microsoft put Hollywood’s interests above those of its customers in a way that promises to be very, very intrusive.

If you want your computer to be working for you, rather than the NSA or Hollywood, you need to be using Free Software. There is no serious alternative. The easiest way for most people to start using Free Software throughout their computer is to download or mail-order Ubuntu Linux. Ubuntu is a user-friendly Linux distribution and will easily replace everything you currently use Windows and other non-free software for.

[ Posted: 20:18] | [ Category: ] | Permalink | Comments: 0 ]

Tue, 21 Nov 2006

SELECT … LIMIT n in Oracle

How to do the equivalent of PostgreSQL or MySQL’s SELECT … LIMIT clause in Oracle:

SELECT * FROM
  (SELECT ROWNUM AS limit, t.* FROM
      (SELECT my actual query with ORDER_BY) t)
WHERE limit <= 10;

No, it’s not very obvious. It should be pretty clear from that example how to do offsets, too.

[ Posted: 08:53] | [ Category: ] | Permalink | Comments: 0 ]

 

Page 0 of 2  >>


Powered by PyBlosxom