Jp Calderone's Journal
[Most Recent Entries]
[Calendar View]
[Friends]
Below are the 20 most recent journal entries recorded in
Jp Calderone's LiveJournal:
[ << Previous 20 ]
| Tuesday, July 1st, 2008 | | 10:03 am |
TCP in the browser? Allen brought to my attention a blog post by Michael Carter about how Orbited now offers a JavaScript API for making TCP connections. I'm not sure how useful this is right now (and I actually mean that I'm not sure, not that I think it's useless and am trying to avoid saying so), though I can see how if, at some future date it's possible to make TCP connections without going through a proxy, apps written this way will suddenly make a lot of sense and be easy to port from apps already based on an API like this.
Anyhow, I thought this would be simple to implement with Athena, but I wanted to see how simple. Five minutes later I had this untested code:
# athenatcp.py
from twisted.internet.protocol import ClientCreator, Protocol
from twisted.internet import reactor
from nevow.athena import LiveElement, expose
class TCPElement(LiveElement):
jsClass = 'Network.TCP'
@expose
def connect(self, host, port):
def connected(proto):
self.proto = proto
self.proto.dataReceived = self.dataReceived
self.proto.connectionLost = self.connectionLost
cc = ClientCreator(reactor, Protocol)
d = cc.connectTCP(host, port)
d.addCallback(connected)
return d
@expose
def write(self, bytes):
self.proto.transport.write(bytes)
def dataReceived(self, data):
self.callRemote('dataReceived', data)
def connectionLost(self, reason):
self.callRemote('connectionLost', reason.getErrorMessage())
// athenatcp.js
// import Nevow.Athena
Network.TCP = Nevow.Athena.Widget.subclass('Network.TCP');
Network.TCP.methods(
function connect(self, host, port) {
return self.callRemote('connect', host, port);
},
function dataReceived(self, bytes) {
// override this
},
function connectionLost(self, reason) {
// override this
});
It'd probably be better if connect were actually a factory function returning TCP instances, but the general idea would be the same. Anyone think this is a really great idea? Anyone want to turn this spike into a real library for Athena? | | Saturday, June 28th, 2008 | | 6:39 pm |
re: inventory meme Glyph tagged me in his Inventory meme several weeks back. At first, I didn't respond because I was too busy. Then, because I forgot. Then, because I decided it would be cheating to wait until I had the maximum number of items possible and then post. Just now I happen to have been reminded of the meme, and I think I can spare the three minutes total this post is going to take, and I'm totally unprepared. So, here it is.
Your hands are empty. You are completely naked.
| | Saturday, April 26th, 2008 | | 1:11 pm |
February through April Reading List - Something Wicked This Way Comes. Ray Bradbury.
- The Eyre Affair. Jasper Fforde.
- The Star Rover. Jack London.
- Travels With Herodotus. Ryszard Kapuściński.
- Omnivore's Dilemma. Michael Pollan.
- Lankhmar. Fritz Leiber.
- Suite Française. Irène Némirovsky.
- Persepolis: The Story of a Childhood. Marjane Satrapi.
- Persepolis 2: The Story of a Return. Marjane Satrapi.
- Maus 1: My Father Bleeds History. Art Spiegelman.
- Maus 2: And Here My Troubles Began. Art Spiegelman.
Current Music: The Velvet Underground - Some Kinda Love | | Friday, April 11th, 2008 | | 12:21 pm |
pyOpenSSL 0.7 final released Alright, it's done. Here are the highlights since 0.6: Bug fixes: - Memory leak in X509.get_pubkey eliminated
- Memory leaks in X509Name.__getattr__ and X509Name.__setattr__ eliminated
- RuntimeWarning from X509Name comparison eliminated
- X509Name reference counting issues resulting in memory corruption eliminated
- Uninitialized PKeys are now rejected by X509Req signature APIs
- Memory leaks in X509Name.__getattr__ and X509Name.__setattr__ eliminated
New features: - SSL_get_shutdown and SSL_set_shutdown exposed as Connection.get_shutdown and Connection.set_shutdown
- SSL_SENT_SHUTDOWN and SSL_RECEIVED_SHUTDOWN exposed as SSL.SENT_SHUTDOWN and SSL.RECEIVED_SHUTDOWN
- X509_verify_cert_error_string exposed as OpenSSL.crypto.X509_verify_cert_error_string
- X509.get_serial_number and X509.set_serial_number now accept long integers
- Expose notBefore and notAfter on X509 certificates for inspection and mutation
- Expose low-level X509Name state with X509Name.get_components
- Expose hashing and DER access on X509Names
Current Music: Kings Of Leon - Velvet Snow | | Saturday, March 22nd, 2008 | | 2:13 pm |
| | Wednesday, February 6th, 2008 | | 2:07 pm |
Ever relevant It is good to re-read Alan Perlis' epigrams in programming from time to time. Some which stand out to me today: 32. Programmers are not to be measured by their ingenuity and their logic but by the completeness of their case analysis. 41. Some programming languages manage to absorb change, but withstand progress. 64. Often it is the means that justify the ends: Goals advance technique and technique survives even when goal structures crumble. 94. Interfaces keep things tidy, but don't accelerate growth: Functions do. One which I don't think has ever stood out to me before: 20. Wherever there is modularity there is the potential for misunderstanding: Hiding information implies a need to check communication. And of course, there are the old favorites: 11. If you have a procedure with ten parameters, you probably missed some. 95. Don't have good ideas if you aren't willing to be responsible for them. 101. Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve. 117. It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical? | | Saturday, February 2nd, 2008 | | 8:14 pm |
October through January Reading List
- Smoke and Mirrors. Neil Gaiman.
- The Long Tomorrow. Leigh Brackett.
- Norstrillia. Cordwainer Smith.
- Nova. Samuel R. Delany.
- Iron Sunrise. Charles Stross.
- The Lies of Locke Lamora. Scott Lynch.
- The Road. Cormac McCarthy.
- Paradise Lost. John Milton.
- Lord of Light. Roger Zelazny.
| | Friday, January 4th, 2008 | | 8:48 am |
notes on netgear support website
-
comments are mangled incorrectly, doubling single quotes, presumably in a confused attempt to prevent SQL injection attacks.
-
page caching behavior is wrong, so after a ticket is updated by netgear support staff, the update will not appear unless the browser is made to disregard its cache.
-
timestamps on comments are wrong, perhaps by roughly (UTC - PST) hours.
-
netgear support staff can't actually fix any problem you have.
Current Mood: pissed offCurrent Music: Fallible, Blues Traveler | | Thursday, January 3rd, 2008 | | 9:18 pm |
One in twenty eight and falling...
Asteroid on near-miss course with Mars
No one taught these guys to label their plots, unfortunately (nice of them to put "mars" and "sun" on there though). To make it clearer, the cyan line is the probable trajectory of 2007 WD5. White dots indicate a possible position at the time it would intercept mars' orbital, if it does.
Will there be a collision? Probably not. One in twenty eight odds, though? Those are most certainly not astronomical odds.
| | Friday, December 21st, 2007 | | 4:58 pm |
Filesystem structure of a Python project Do:
-
name the directory something related to your project. For example, if your project is named "Twisted", name the top-level directory for its source files
Twisted. When you do releases, you should include a version number suffix: Twisted-2.5.
-
create a directory
Twisted/bin and put your executables there, if you have any. Don't give them a .py extension, even if they are Python source files. Don't put any code in them except an import of and call to a main function defined somewhere else in your projects.
-
If your project is expressable as a single Python source file, then put it into the directory and name it something related to your project. For example,
Twisted/twisted.py. If you need multiple source files, create a package instead (Twisted/twisted/, with an empty Twisted/twisted/__init__.py) and place your source files in it. For example, Twisted/twisted/internet.py.
-
put your unit tests in a sub-package of your package (note - this means that the single Python source file option above was a trick - you always need at least one other file for your unit tests). For example,
Twisted/twisted/test/. Of course, make it a package with Twisted/twisted/test/__init__.py. Place tests in files like Twisted/twisted/test/test_internet.py.
-
add
Twisted/README and Twisted/setup.py to explain and install your software, respectively, if you're feeling nice.
Don't:
-
put your source in a directory called
src or lib. This makes it hard to run without installing.
-
-
put your tests outside of your Python package. This makes it hard to run the tests against an installed version.
-
create a package that only has a
__init__.py and then put all your code into __init__.py. Just make a module instead of a package, it's simpler.
-
try to come up with magical hacks to make Python able to import your module or package without having the user add the directory containing it to their import path (either via
PYTHONPATH or some other mechanism). You will not correctly handle all cases and users will get angry at you when your software doesn't work in their environment.
| | Monday, December 3rd, 2007 | | 2:52 pm |
Incompatabilities between classic and new-style Python classes radix asked me if I had a blog post about why changing a class from classic to new-style is a bad idea. After I told him that I didn't he insisted that I should write one. Since doing so will take less work than finding something else to distract his attention, here it is:
-
attribute lookup
Attributes on instances of classic classes override attributes of the same name on their class. For example:
>>> class SimpleDescriptor(object):
... def __get__(self, instance, type):
... print 'getting'
... return instance.__dict__['simple']
... def __set__(self, instance, value):
... print 'setting'
... instance.__dict__['simple'] = value
...
>>> class classic:
... simple = SimpleDescriptor()
...
>>> x = classic()
>>> x.simple = 10
>>> x.simple
10
>>> class newstyle(object):
... simple = SimpleDescriptor()
...
>>> x = newstyle()
>>> x.simple
getting
Traceback (most recent call last):
File "", line 1, in ?
File "", line 4, in __get__
KeyError: 'simple'
>>> x.simple = 10
setting
>>> x.simple
getting
10
As you can see, the descriptor on the new-style class can both handle the setattr and continue to operate after shadowing itself with an instance variable.
-
Special methods
A particularly interesting consequence of the previous point is that the behavior of special methods changes in some cases:
>>> class x:
... def __init__(self):
... self.__eq__ = lambda other: True
...
>>> x() == 10
True
>>> class x(object):
... def __init__(self):
... self.__eq__ = lambda other: True
...
>>> x() == 10
False
>>>
-
MRO
Rules for determining the method resolution forbid new-style classes in places where classic classes are acceptable. Consider:
>>> class x: pass
...
>>> class y(object, x): pass
...
>>> class x(object): pass
...
>>> class y(object, x): pass
...
Traceback (most recent call last):
File "", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, x
>>>
Hopefully that's enough to satisfy radix. Know of other incompatibilities? Please comment.
| | Saturday, November 10th, 2007 | | 12:39 pm |
3.7V li-poly: $7, 1300mAh, 25 grams, 2.5A max$6, 850mAh, 20 grams, 1.75A max$8, 430mAh, 12 grams, 6.5A max$10, 220mAh, 5.4 grams, .44A max$5, 160mAh, 5 grams, 2A max$7, 130mAh, 3.4 grams, 4.6A max | | Tuesday, October 2nd, 2007 | | 7:49 pm |
Hair today... Some pictures of Quechee Gorge up. Including a 360° panorama I assembled. Which took forever with stupid gimp. And it didn't come out very well anyway. Stupid parallax, I'll get you next time. Off to San Antonio tomorrow, back next week. If there's anything worth taking pictures of (other than my brother) maybe those'll show up in a week or so. | | Sunday, September 30th, 2007 | | 8:14 pm |
September Reading List By way of The Book of Jhereg:
- Jhereg Steven Brust.
- Yendi Steven Brust.
- Teckla Steven Brust.
Also some Milton, for class: On the Morning of Christ's Nativity, At a Solemn Music, L'Allegro, Il Penseroso, Lycidas, On the New Forcers of Conscience, To Mr. Cyriack Skinner Upon His Blindness, and sonnets 11, 12, 15, 16, 19. | | Tuesday, September 11th, 2007 | | 10:38 pm |
chevre, pine nut, raisin, onion, garlic, bacon, duck pizza Current Mood: rejuvenated | | Saturday, September 1st, 2007 | | 1:37 pm |
August Reading List Not much going on in August:
- Player Piano. Kurt Vonnegut, Jr..
- The Execution Channel. Ken MacLeod.
- Rainbows End. Vernor Vinge.
| | Tuesday, August 21st, 2007 | | 12:29 pm |
Twisted Trial performance improvements Trial, Twisted's xUnit(-esque) testing package (library, discovery tool, runner, etc), has long inherited its overall testing flow from the Python standard library unittest module. It's quite simple, actually: iterate over a sequence of test cases and invoke each one with the result object. Lately, this has actually led to some noticeable problems with its performance. Creating a test case instance for each test method isn't extremely unreasonable, but in the process of running them all, more and more objects are created and the process balloons to an unreasonable size. The Twisted test suite typically uses about 800MB of RAM by the time the last test method is run.
So, in order to be able to run the Twisted tests on machines without 800MB of free memory, we changed our TestSuite so that it drops each test after it runs it. The suite now takes about one quarter as much memory to run. As an unexpected bonus, it also runs almost 50% faster (66% for trial --force-gc which calls gc.collect in between each test method). I can only explain the speedup as time saved inside the garbage collector itself due there being far fewer objects to examine (this is not a completely satisfying explanation, but I cannot think of a better one).
If you're using trial to run your test suite, you may notice reduced memory requirements and reduced overall runtime, too. :) Current Mood: happyCurrent Music: Led Zeppelin - Custard Pie | | Friday, August 17th, 2007 | | 4:49 pm |
Typespeed v0.4.4
Best score was:
Rank: Computer Score: 1187 Total CPS: 8.492 Correct CPS: 8.352 Typo ratio: 1.6% Typorank: Secretary
exarkun@charm:~$
Current Mood: accomplished | | Thursday, August 16th, 2007 | | 10:09 pm |
Child process improvements in Twisted Thomas Hervé merged his process/pty-process branch into Twisted trunk today. He's been working on integrating the two separate implementations of POSIX child process creation in Twisted, one for child processes connected to a PTY and one for child processes connected to a set of pipes. A long time ago, someone copied an entire class full of code and started twiddling it to support PTYs. This led to a lot of duplication, obviously, and some bugs where the two classes diverged.
With this re-unification, some behavior which was inconsistent between the two variations has been removed, some bugs which were present in one or the other of the two classes have been fixed, and a lot of duplicate code has been completely eliminated. Best of all, there is now some actual unit test coverage for this code (it was originally developed long before Twisted's current high testing requirements) and a test double which will make it easier to write more and better unit tests for this code in the future.
One other piece of fall out is that on Windows, if application code tries to signal an already-exited process, an exception will be raised indicating that it is not possible to do so. This brings Windows process support closer still to POSIX process support. Current Mood: happy | | Thursday, August 9th, 2007 | | 12:12 pm |
|
[ << Previous 20 ]
|