Skip to main content

Posts

Showing posts from 2005

Internet Explorer: Bocked!

Internet Explorer's enhanced security configuration just blocked it's own "about:internet" page. No, I'm not making this up, and I didn't Photoshop it ;)

Emacs: The Straw that Broke the Camel's Back

I'm a Vim user, but I try to be pretty open minded. I've used Emacs extensively in the past, and in the interest of being flexible, I decided to revisit the Emacs tutorial. I memorized most of it. I originally switched away from Emacs when I was doing PHP programming, and Vim accomodated me better. Having approached Emacs with an open mind (I really would have liked to try it out for six months), these are the things that dissuaded me:
The syntax highlighting in Emacs cannot compare to that of Vim, especially in multi-mode files such as Cheetah. Here's a screenshot of Vim. Notice that it's able to handle Cheetah, Python, HTML, and JavaScript all in the same file.
I found myself with my pinky permanently glued to the control key when I was editing existing code. Does everyone else ignore the tutorial and use the arrow keys instead of C-[npfb]?
I'm stuck with FreeBSD 4.7 in a certain programming environment, and Emacs there didn't come with Python support at …

Plone: Some Comments

I built a Web site using Plone. I read "The Definitive Guide to Plone" in order to do so. Along the way, I kept a log of my impressions, which I'll relay here. Most of them are complaints, usually because I've done better in Aquarium for that particular item. However, I should mention that Plone did indeed fill my needs, for which I am grateful. Some of the comments refer to TAL, some to Zope, and others to Plone itself.
The lack of elif and else in TAL drove me nuts.
In TAL, try to use conditional logic to toggle between a <b> or a <p> tag. The normal way of changing tag attributes won't help you change the tag itself.
The slot mechanism in Metal isn't as flexible as normal OO inheritance.
Why must the Zope object hierarchy match the inheritance/acquisition hierarchy (which is tied to the URL hierarchy)? I like my URL hiearchy to make sense for users, and for each object, I like to be able to say what it inherits from explicitly. I like for s…

Haskell: Breadth-first Tree Traversal

As an exercise, I implemented breadth-first tree traversal (instead of the much more common depth-first tree traversal) in Haskell. It took me about 3 hours, mainly because I haven't even finished reading the turorial yet. It really struck me how truly lazy Haskell is! My own language, Squeamish, had lazy evaluation, but in Haskell, you have to somewhat bend over backwards with the imperative stuff to say, "Yeah, really, I'm done defining stuff. Uh, can you actually, uh, do some evaluation or something, and, uh, maybe even print the answer?"{- Implement breadth-first tree traversal.

Name: Shannon -jj Behrens
Date: Tue Dec 13 03:18:34 PST 2005 -}

module Main where

-- The main definition of a tree.
data Tree a = Leaf a | Branch a (Tree a) (Tree a)

-- Depth-first tree traversal.
depthFirst :: Tree a -> [a]
depthFirst (Leaf x) = [x]
depthFirst (Branch x left right) = depthFirst left ++ [x] ++
dep…

Fedora: Sanyo PM-8200 under Fedora Core 4

I'm using my Sanyo PM-8200 with Sprint as a wireless modem under Fedora Core 4 to send this post. I used the instructions here, with the exception that I skipped the "teathered" business, and the name of the device was "/dev/ttyACM0".

I'm pleased to say that it only took me 20 minutes to figure out how to get this to work, which is about how long it took me on my Mac.

Off Topic: Which Character are You?

Sorry, I couldn't resist posting this.

GNU screen: A Graphical Replacement

GNU screen is an essential application, yet its learning curve is insanely steep. Even everyday users barely scratch the surface of what it can do due to lack of knowledge. Neither the defaults (e.g. no caption by default) nor the interface (e.g. tons of special key combinations that hopefully don't conflict with your existing applications) make things any easier. I've been thinking a lot about how to improve it.

Imagine what you could do if you were to use a GUI for some cool new version of screen. Now I know that there's a real benefit to the way screen works in that all you need on the client side is a terminal, and I'm sure many a GUI hater will think I'm missing the point of screen. Let's face it though, I do have a graphical desktop. Furthermore, I'm not talking about getting multiple terminals on the local system. Tabbed terminals solve that trivially. I'm talking about multiple terminals running on a remote system that may or may not be p…

Haskell: First Class Types

It's interesting that Haskell makes such a big deal about first class functions but does not have first class types. Python does ;)

(Note, I'm not sure it makes a big difference, but I thought it was a humorous observation.)

Io: A Comparison

I just wrote my first non-trivial program in Io. It felt very comfortable, and I felt productive. I didn't struggle over every square inch like I do in languages like Ocaml. It felt like a weird mix of Lisp and JavaScript. Anyway, the program I wrote is a prime finder--yes, how geeky. Here it is:
#!/usr/local/bin/io

/*
* Find prime numbers. See usage for more information.
*
* Author: JJ Behrens
* Date: Sat Nov 5 19:50:21 PST 2005
* Copyright: (c) JJ Behrens
* Description:
*
* The algorithm used to determine if a given number, n, is prime is to keep a
* list of pairs (p, mc) where each p is a prime less than n and each mc is n
* % p. If n is prime, then no mc is 0. The effeciency of this algorithm is
* wholly determined by how efficiently one can maintain this list. mc does
* not need to be recalculated using a full % operation when moving from n to n
* + 1 (increment and then reset to 0 if mc = p). Furthermore, another
* performance enhancement is to use lazy evaluatio…

Languages: Io

Io

Coroutines, prototype based, asynchronous, futures, minimalistic syntax, 0 keywords, lazy evaluation of function parameters, oh my! This out to keep me entertained for a few days!

As an aside, in this paper, he says:Message arguments are passed as expressions and evaluated by the receiver. Selective evalulation of these arguments is used to implement control flow.Heh, cool, I did the same thing (and was similarly pleased) in my programming language, Squeamish , which I wrote about in Dr. Dobb's Journal :)

Python: Deeply Nested try/finally Statements

"""This is a convenient way to deeply nest try/finally statements."""

__docformat__ = "restructuredtext"

# Created: Tue Oct 11 08:42:23 PDT 2005
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens. All rights reserved.

from traceback import print_exc


def tryFinally(tasks, handleFinallyException=None):

"""This is a convenient way to deeply nest try/finally statements.

It is appropriate for complicated resource initialization and destruction.
For instance, if you have a list of 50 things that need to get intialized
and later destructed via using try/finally (especially if you need to
create the list dynamically) this function is appropriate.

Given::

tasks = [
((f_enter_0, enter_0_args, enter_0_kargs),
(f_exit_0, exit_0_args, exit_0_kargs)),

((f_enter_1, enter_1_args, enter_1_kargs),
(f_exit_1, exit_1_args, exit_1_kar…

JavaScript: Quickies

Concerning MochiKit: It's well written. I like the Pythonic feel. I like the docs, the humor, and the heavy regression testing. I even like the code, which is a huge compliment!

Concerning DojoToolkit: I like the fact that it's a community of people who have each given up their own framework to work together. I like the mailing list. I like the event system and the package system (although I haven't used it yet). I don't like the fact that it doesn't feel quite as polished by a perfectionist as MochiKit. I also hate the part of the style guide that says you should not use a space before "{" in:if (foo){
}I don't know of any other style guide that suggests this.

Does this mean I'm going to pick one over the other? Nope. Both have good parts. Fortunately, they're compatible. It looks like I'm going to have to use them both. Ideally, the guys from MochiKit would take a bunch of their stuff and shove it into DojoToolkit. Then the gu…

AJAX: Humor

Have you ever noticed that some of your best work happens in the bathroom?

The other day I was trying to resolve a particularly sticky user interface problem. I thought I'd try out some AJAX, Asynchronous JavaScript and XML. It wasn't really working out, and although they really aren't the same thing, I tried some CLOROX, Common Language Object Reference Over XML. Displeased with that, I fell back to COMET, Common Object Method External Transport. Next I thought I'd try some old fashioned BLEACH, Binary Language Exports And C Headers; however I made sure to remove all the COMET first because I've heard that mixing COMET and BLEACH can have disastrous side effects. I think I was most satisfied with CLOROX, especially thanks to its BLEACH heritage. I found that all of these options were better than SOAP, Simple Object Access Protocol, which leaves a sticky substance behind that is nearly impossible to get rid of.

JavaScript: JavaScript has Closures

Python has closures:def outer():
print "Enter number:",
num = raw_input()
def inner():
print num
return inner

f = outer()
f()Note that the variable num is available from within inner when outer has already completed.

Did you know that JavaScript has them too?function testSetTimeout() {
var privateVar = 'A string';
function bar() { alert(privateVar); }
window.setTimeout(bar, 1000);
}

testSetTimeout();The function bar makes use of privateVar which a variable in testSetTimeout's local scope even though bar is invoked later by setTimeout, i.e. after testSetTimeout has completed.

Linux: NETGEAR MA52 on Fedora Core 4

For the sake of those using Google to try to figure out how to get this to work, here's how to get the NETGEAR MA52 802.11b wireless card to work under Fedora Core 4 using the NdisWrapper. These are the instructions I followed:
Created /etc/yum.repos.d/livna.repo per the instructions above.
rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY
yum --enablerepo=livna-stable install ndiswrapper kernel-module-ndiswrapper-$(uname -r)
Downloaded the binary driver from here.
unzip ndis5x-8180(173).zip
/usr/sbin/ndiswrapper -i NET8180.INF
/usr/sbin/ndiswrapper -l
/sbin/modprobe ndiswrapper
dmesg
/usr/sbin/ndiswrapper -m
Setup the network settings as usual.

Python: Wrapping Methods Via a Backdoor

Often, when you write a server in Python, you include a backdoor. The backdoor is something that you can telnet to from localhost, and it's basically a Python shell. Within the Python shell, you can snoop around the running program. It's cool. Now, suppose you want to insert some code to debug a problem. Suppose you want to intercept all method calls to a certain class. (If you're a hardcore Python hacker, feel free to stop reading, but many other people will find this interesting.)>>> class C:
... """This is some pre-existing class within the running application."""
... def f(self, num): print "I got called with:", num
...
>>>
>>> def wrap(f):
... """This is a function decorator. inner below is the wrapper itself."""
... def inner(*args, **kargs):
... print "I'm about to call %s with %s %s." % ... (f.__name__, `args[1:]`, `kargs…

Python: Generator Expressions

In one of his talks at PyCon, Alex Martelli said that if you have complicated loop logic, throw it into a generator so that you never have to duplicate it. In the old days, it was common to duplicate loop logic. I like this rule, and I have seen it improve my code. Just in case you haven't seen the syntax yet, it's:>>> def generate():
... yield 1
... yield 79
... yield 26
... for i in range(0, 10):
... yield i
...
>>> for i in generate():
... print i,
...
1 79 26 0 1 2 3 4 5 6 7 8 9In Python 2.4, generator expressions were added. When I saw these, I figured, "Well, yeah, that's pretty natural." It took me a while to realize that just as list comprehensions were taken from Haskell, generator expressions are lazy lists from Haskell. Again, here's an example:>>> import itertools
>>> import random
>>>
>>> numbers = (random.random() for i in itertools.repeat(0))
>>> print "The …

Python: HTMLTemplate

Paul Abrams suggested to me the idea of having 100% pure HTML, and then using some DOM on the server side to splice chunks of HTML together. After talking about it for about two hours, I became excited about the idea, and I wondered if it would be pleasant in practice in contrast to, say, Cheetah. At the very least, it would be an interesting alternative.
It turns out that HTMLTemplate is one such system. I asked the Python web-sig about it, as well as a few other people. Tung Wai Yip said that he really liked HTMLTemplate. I figured my buddy, Donovan Preston, of Nevow fame would like it because he's a fan of getting away from the whole "big chunk of HTML in an amorphous string" idea. Ian Bicking had the following comment, which I feel was very perceptive:If there's no code then it's not a presentation layer. It's an HTML layer, nothing more, just dumb data. Presentation requires logic.Ksenia Marasanova, the newest member added to the Aquarium project,…

Laszlo

laszlo-in-ten-minutesLZX, the Laszlo XML-based language, allows you to develop Rich Internet Applications using industry standards such as XML, JavaScript, and XPath.Interesting stuff. It's too bad Flash isn't an open standard.

MVC: Cargo Cult

Don Hopkins posted this to the Bay Piggies mailing list:
"a lot of the related literature seems to use MVC as the canonical
example of a design pattern"

MVC is the canonical example of the "CargoCult" design pattern of
blindly aping Smalltalk without understanding it or considering if there
are any more appropriate design patterns.

http://en.wikipedia.org/wiki/Cargo_cult

I've never heard a good explanation of what a "controller" is really
supposed to do (other than entangle brittle dependencies between the
view and the model, and allow programmers to bill for more hours
maintaining the code). But people always throw in that extra
"controller" class and its requisite complexity, just because Smalltalk
uses them, and it doesn't feel right imitating Smalltalk without the
whole MVC trifecta.

Just because MVC is a commonly used and cited "pattern" doesn't mean
it's the best one to use in all cases. It's better to have a "purpose&q…

Hyperthreaded Micro Threads for Aspect Oriented Programming

I recently discovered a series of articles written by Jon "Hannibal" Stokes on arstechnica.com. Usually, I stick to learning weird, exotic languages, but I'm really fascinated by his descriptions of modern processors. I'm especially fascinated by the idea of tuning modern day processors and programming techniques so that they take advantage of one another. For instance, C++'s use of automatic variables results in so many function calls, that if these function calls are not inlined, they can play hell on the pipeline, unless branch prediction works well.Having read Hannibal's articles on hyperthreading, SMT, and the Itanium-64, IA-64, I became intriqued by the performance aspects of SMT on aspect oriented programming, AOP. AOP is currently confined mostly to the Java world, so it doesn't have a direct effect on the processor, per se, but I wondered if a natively compiled AOP compiler could better take advantage of an IA-64 processor. It would do this via e…

Hitachi G1000 Pocket PC

I just bought a Hitachi G1000 Pocket PC. I installed Python, Cheetah, Aquarium, and Glass (Aquarium's Web server). I have a simple Web application running in the background, and I can look at it with IE. I can even see the Web application from my laptop over USB from within Linux! There's something intrinsically cool about extremely small Web servers used as an application platform ;)

Python: PyCon 2005 random thoughts

Some people have asked me to provide some comments on PyCon 2005. Here is an informal collection of impressions and opinions. I won't cover the Web topics because I've already done that.

Alex Martelli's talks are a joy. I especially liked his talk on 'Descriptors, Decorators, Metaclasses: Python's "Black Magic"'. I just wish he had more time. 25 minutes is simply not enough time to understand the subjects he is trying to convey unless you already understand them.

PyPy is definitely not what I thought it was. Apparently, it's about type inference. I thought it was an attempt to rewrite the front-end of the Python interpreter in Python so that the front-end could be shared among all the versions of Python. If this were the cases, the front-end could be distributed as .pyc's, and all the versions of Python would only need to write VM's to interpret the .pyc's. :-/

wxPython is a pain to use. PythonCard is a wrapper around wxPython that make…

Web: The Brian Problem

Thinking back to the early days of Aquarium, Chuck Esterbrook and I thought about merging Aquarium and Webware. Unfortunately, I'm a bit of a code nazi, and Webware isn't the most minimal, style-conforming code around (which multiple people have confirmed, so it's not just me). This dissuaded me from joining forces. The fact that I was out of the Web world for about two years gave Webware a big leg up :-/

Moving forward, I'd like:
To work hard on newbie documentation for the PyWebOff's concept of "Brian" (i.e. a Python newbie who knows PHP and is now trying to write Web applications in Python).
To revive Piranha for all the "Ruby on Rails" folk. SQLObject and the Subway project may make some or all of this work unnecessary.
To better integrate with SQLObject and FormEncode.
To write a WebServerAdaptor for Twisted. At IronPort, we use coroutines. I work with Sam Rushing, the author of Medusa. Since coroutines are strictly better than Twisted (same ben…

Web: PyCon 2005

I just finished attending PyCon. Specifically concerning the Web, I'd like to direct your attention to:

http://pyre.third-bit.com/pyweb/index.html
Basically, there are too damned many Web application frameworks, and they all assume you know what you're doing. The PyWebOff is an attempt to figure out which is best from a newbie's perspective. Hopefully the talk will be available in video format later. I just finished reading the blog. She said, "Please, whatever you do, don't try to solve the problem by writing another Web application framework!!!"

http://www.python.org/peps/pep-0333.html
Ian Bicking gave a talk on this. It's an attempt at consolidating some underlying Web application API's. Basically, it's an attempt at making up for lack of a servlet API. It's great in that Web application framework authors may be able to share some code, but it still doesn't address the fact that there are too many choices for the user. Furthermore, it does…

Python: Create a new class on the fly

At PyCon, Alex Martelli mentioned that you could create a class on the fly using the type function. Previously, I probably would have used the exec function. I feel like such a dork:
>>> class Template(object): # Must be a new-style class.
... def bark(self):
... print "woof"
...
>>> Page = type("Page", (Template,), {})
>>> Page().bark()
woof
>>>
>>> def meow(self):
... print `self`
... print "meow"
...
>>> Page.meow = meow
>>>
>>> Page().meow()
<__main__.page>
meow

Welcome to JJinuxLand

Karl Guertin told me, "He who blogs gets his opinion heard." Hence, inspired by the blogs of Anthony Eden, Leon Atkinson, and Ian Bicking, I have created my own. This is a purely technical blog concerning topics such as Python, Linux, FreeBSD, open source software, the Web, and lesser-known programming languages. In the interest of everyone's time, including my own, I hope to keep the volume low, and the technical content high.

Please excuse the fact that I did not write my own blog software. It isn't that I am unable to. It's simply that I hate reinventing the wheel when exceedingly round ones already exist. I chose blogger.com specifically on the recommendation of Krishna Srinivasan, Tung Wai Yip, Anthony Eden, and Google.

I look forward to your comments.