Search Results: "dom"

11 November 2005

Joe Wreschnig: More Python

I’m writing a registration database for Anime Detour, our local anime convention. Normally I would hate this kind of work (does anyone actually like SQL?) but SQLObject, which [info]gesten pointed me towards, is really awesome. It basically turns any SQL database (in my case SQLite) into a Python object database, with classes as tables, instances as rows, and Python class methods for queries. People stuck writing database code should definitely check it out. Another Optimization Lesson
Quod Libet stores a library of your music, like most other players. The most common things the library needs to do, and therefore the most efficient things it should do, are 1) get a list of songs in the library, and 2) check to see if a song is in the library (or equivalently, given some handle, retrieve the song with that handle from the library). Anyone familiar with Python will probably think of a dict keyed to something unique, like the filename or URI. That’s what I did, and that’s what I wrote. When QL saves, it serialize the song list using pickle, and dump it to the library: pickle.dump(library.values(), file). When it loads, it does something like for song in pickle.load(library): if song.valid(): library.add(song) where song.valid() reloads the song if its mtime has changed or removes it if the file no longer exists. So what’s the problem with this code? I sure didn’t see one until this morning, when our Italian translator complained about interestingly long cold cache startup times. The answer’s at a lower level than Python programmers usually have to work at: This sucks for disk cache. library.values() dumps the file in Python dict order, which is not only not meaningful, it’s actually semi-random for security reasons. When I reload the dumped file and iterate through the songs in it, I’m stat(2)ing files in an order designed to be as unpredictable as possible. How is the cache supposed to cope with that? The answer is, it doesn’t. Sorting the songs by filename when saving the dict costs almost nothing (Python out-sorts every other language as far as I know), but saves 10% wall clock time for me when starting - it will probably save even more on filesystems that perform poorly on stats of large files (reiser3), and directory trees that go more than 2 levels deep. Lessons learned: First, CPU profiling is good, but doesn’t have all the answers; profile.py insists the program is slower because of the sorting on exit. Second, ideas that work fine for n=100 don’t work well for n=10000 even if the algorithm you chose scales well with regard to complexity theory. Finally, the fundamentals still matter; fixing slow Python code still makes you consider OS/hardware-level cache effects.

Lars Wirzenius: Random thought: Hardcopy fingerprints

Like Andres Salomon I too have had my business cards with a GPG fingerprint be obsoleted. For me, however, it happened because I gave the printers the wrong fingerprint: the one for a special purpose key (comp.os.linux.announce moderation, I think), not my usual key. That was a nice "oops" moment. These days, if I need fingerprints on paper, I print out copies of a little design I did with glabels, not liking the output from various existing key-to-fingerprint scripts I tried. I only print as many as I need, though, which is easy now that I have a working printer again.

10 November 2005

Sam Hocevar: [code] Finding a specific instance of a given day in the month in PHP

Andrew: to work out the fourth Thursday of the month, use this instead:
function nth_day($instance, $dow, $month, $year)

  $first_dom = date("w", mktime(0, 0, 0, $month, 1, $year));
  return 1 + ((7 + $dow - $first_dom) % 7) + 7 * ($instance - 1);
Or, using Zeller s rule and avoiding function calls:
function nth_day($instance, $dow, $month, $year)

  if($month < 3) $year--; $D = $year % 100; $C = (int)($year / 100); $m = 1 + (($month + 9) % 12);
  $f = 1 + (int)((13 * $m - 1) / 5) + $D + (int)($D / 4) + (int)($C / 4) - 2 * $C;
  $first_dom = $f % 7;
  return 1 + ((7 + $dow - $first_dom) % 7) + 7 * ($instance - 1);
Update: thanks to Andrew for spotting the error in the second version. Due to my misunderstanding of a hack in Zeller s rule, I had forgotten to decrease the year when the month was January or February. Also, PHP was not doing proper integer divisions and I had to cast results back to int despite all operands being ints.

Andrew Pollock: [code] Finding a specific instance of a given day in the month in PHP

When I took over organising the CLUG meetings, I managed to replace most of myself with a small shell script (I even have the t-shirt). Now that I'm leaving Canberra, Steve Walsh has kindly taken over the running of the script. So I've done a bit more work on the script, and added a public front end to it, and made an RSS feed (my very first). So until yesterday, to work out the fourth Thursday of the month, I'd been calling a Perl script that used Date::Manip, when I decided to investigate doing it with PHP natively. Tony gave me some initial code, but I ended up with this:
function nth_day($instance, $dow, $month, $year)

    
$first_dom = date("w", mktime(0, 0, 0, $month, 1, $year));
    
    if (
$first_dom <= $dow)
        
$first_instance = date("j", mktime(0, 0, 0, $month, 1 + ($dow - $first_dom), $year));
     else
        
$first_instance = date("j", mktime(0, 0, 0, $month, 8 - ($first_dom - $dow), $year));
    

    
$instance_we_want = $first_instance + (($instance-1) * 7);

    
$date = date("j", mktime(0, 0, 0, $month, $instance_we_want, $year));

    return
$date;

Joey Hess: BBS

Sometime over the years, I've managed to forget, or block out, most of my memories of the time in high school when I used BBSes, before the internet. Even though I still have friends from back then, and even, come to think, host a rack of computers at the house of a guy who was once a sysop. Those couple of years (how many?) are mostly a blank, and not something I think about much. I can't remember the first time I used a BBS. I can remember clearly and crisply the first time I used a unix system. A bit of it came back when I didn't pirate the BBS Documentary, an epic 8 part series of interviews with the people who brought us the likes of XMODEM, fidonet, pcboard, and ansi art. Highly recommended. Amazing how just looking at so many of the people immediatly reminds me of the BBSers I knew at the time. Its producer, Jason Scott, also runs textfiles.com, a huge collection of all sorts of text files from the 60's through 90's, which mostly originate from old BBSes. His historical bent in preserving and documenting this stuff really appeals. I poked around the net today, managed to find some docs about one BBS I remembered using, and nothing about a couple of others. Logged into a telnet BBS or two and remembered just how angry fruit salad and silly to use those systems really were, and also how much they probably contributed to my enduring enjoyment of unix, muds, and email. I thought it would be nice to not forget about this stuff, and so I coded up a reminder, merging the ancient plain text files with what's currently new and spiffy (weblogs natch), and creating this webblog which has a random text file posted to it each day. Of course, the subjects range from anarchy, to programming, to phone phreaking, to porn, so view at your own risk, just as if it were 1992, and you were were dialing a number your war dialer had found while you were away at school. Would you like to play a game?

9 November 2005

Matthew Palmer: Redhat Considered Harmful

I try hard not to hate Redhat, I really do. I don't visibly grimace when someone says "I'm running $REDHAT_DERIVED_DISTRO", and my first solution to "I can't get this to work on $REDHAT_DERIVED_DISTRO" is almost never "just install Debian,Ubuntu ". But Redhat makes it so hard to not beat them with a stick. For instance, I'm working on building a SOE for a client, and so I've got a bunch of scripts (calling random poorly documented and hard-to-find utilities) to help me do that. Naturally, I'm pruning the package list, which requires me to rebuild the list of packages which are on the CD. No problems, I can handle that. Oh, but the tool that builds the package list can't deal with the correct "ordering" of packages in the list. Why is ordering important? Because, and this will make you laugh, the installer can't actually deal with dependencies. Yes, that's right, anaconda will install your packages in any old order you specify, regardless of what is actually needed. Brain-damaged, certainly, but I've dealt with Windows, so this is ultimately a minor setback. The tools for building the packages lists are in a certain package, which I dutifully install. They then proceed to fail horribly. Why, do you ask? Because the script requires python modules from another package. Gee, wouldn't be handy if there was a mechanism by which a package could specify that it needed another package to operate? OH WAIT, THERE IS -- IT'S CALLED DEPENDENCIES, FOR $DEITY'S SAKE! YOU WROTE THE GODDAMN RPM SPECIFICATION, REDHAT, WHY CAN'T YOU ACTUALLY USE SOME OF IT'S FRIGGING FEATURES! But wait, there's more! Installing the package which contains the module doesn't actually make the module accessable to anything else on the system, because the module is installed in some god-forsaken, out of the way location, where Python fears to tread. You need to specify PYTHONPATH to make it work. Apparently someone was sure that specifying absolute paths in scripts (instead of letting the system search it's environment) was a bad idea, but didn't have problem with not putting modules in standard, well-known locations. Then, of course, the (other) tool segfaults. Why? Because it's reading an empty file. Wow. An empty file causes this thing to fall over in a screaming heap. Not "Sorry bub, but your file's empty" just an unceremonious segfault. Wow. Thanks. And that's even before we get around to actually doing an install...

6 November 2005

Andrew Pollock: [code] Obfuscating email addresses with JavaScript

So I got pet peeved by Carlos Laviola in relation to by recent pondering about how MacOS X's SSH agent starts up on login. Perfectly reasonable grounds for complaint. I have had people contact me in relation to blog posts in the past, so it's obviously not impossible. People know I'm a Debian developer and can put two and two together and wind up at db.debian.org. Anyway, I'm the first to admit that my blog probably has too many of the Weblog Usability Top Ten Design Mistakes (something for me to work on). To date, I've been avoiding plastering my email address on my website because I didn't want to get it harvested. I try and use a per-list email address for this reason as well, and I haven't enabled blog comments because of comment spam, and because I haven't been clever enough to implement comments with Blosxom full stop. So I started getting an idea for reversibly encrypting my email address on my blog after reading about Hashcash for Wordpress the other day. I first started playing around with the Vernam cipher in High School, when I wanted to easily reversibly obfuscate some data for something. I'd read about this cipher in a magazine or something and seen it implemented in Pascal (it's not exactly hard). So I happened upon the idea of encrypting my email address with the Vernam cipher. Turns out another chap's already got a page for encrypting and decrypting on the fly with JavaScript. It even generates the JavaScript for putting in your own web pages. I had to use a different key to avoid getting dollar signs in the encrypted string, as this confused the tripe out of Blosxom (and me for a while when I tried to figure out what was going wrong). Then I thought it'd be nice to explain to people who had JavaScript disabled what they might be missing out on, so I fiddled around with some DOM stuff, and had some text get displayed if JavaScript was disabled. When JavaScript is enabled, this text is replaced by the decrypted text. So of course, like the Wordpress Hashcash, this is largely relying on the inability of spam bots to grok JavaScript. Once they can, this obfuscation technique is all for naught. Meanwhile, you can email me bit more easily now if you get the urge. View the source of my blog for an example of the implementation.

4 November 2005

Clint Adams: The social music revolution

I accidentally read one of Adam Kessel's blog posts, and I paused to be annoyed. Neither vux nor randomplay have Audioscrobbler support.

Adam Rosi-Kessel: randomplay 0.48 released

I’ve released randomplay 0.48. randomplay is my command-line ‘itch a scratch’ music player. It is most useful for maintaining a random shuffle over many sessions—for example, I use it to make sure I don’t ever hear the same song in any three month period. The new version fixes a bug that prevented randomplay from advancing to the next track when the player subprocess itself spawned a child process (e.g., with ‘play’ which spawns ‘sox’). I use a bit of a hack to kill the child task and it’s children, but the standard way of doing this in perl—kill HUP => -$$ doesn’t seem to work when randomplay is called from a shell script and the child process’ output is redirected to null. Here’s the code in question (with the fix to kill children and grandchildren recursively):
# KillAll recursively kills the request process ID and all of its children/grandchildren/etc.
# This is a bit of a hack--there should be a better way to do this, but I haven't found one.
# Normally, kill HUP => -$$ should do the job, except this doesn't work when randomplay itself
# is called from a shell script and all output from child processes is redirected to null.
# This subroutine assumes that shelling out to ps is going to work, which may not be totally
# safe--at the very least, it reduces the portability of the script.
# Any suggestions for a better way to do this are welcome.
sub KillAll  
  my $pid = shift;
  local $SIG HUP  = 'IGNORE';   # don't want to kill ourselves here--shouldn't happen, but just in case.
  if (open PS, "ps -o pid,ppid  ")  
     eof PS; # Force ps to run now. Otherwise it would run at the first read operation.
     kill HUP => $pid;
     foreach my $line (<PS>)  
       KillAll($1) if ($line =~ /^\s*(\d+)\s*(\d+)\s*$/ and ($2 eq $pid));
      
     close PS;
    else                  # if we can't read the process table, just try killing the child process group
    kill HUP => -$$;
   
 
Thanks to Christopher Zimmermann for the patch to kill children recursively.

3 November 2005

David Moreno Garza: NKjoom5

In most of the last few days, I've been completely into NKjoom5, a framework for developing web applications for the company I work for. This is based on the lastest version of Joomla, 1.0.3, and it tries to bring more ease of use to the final product, capable of understanding by all the guys working on the Mexico and Colombia local officies of the company.
 
In the meanwhile, I've ported most of the core code of Joomla into mysqli extension of PHP5 and most of the XML functionality is about to be ported with DOM and even XPath, all of this to bring more accessibility to the code and bring future to present :) MySQL 5, for production systems now, is also used, but I haven't played with it yet.
 
In the user management system, more work has to be done. We don't need more Authors, Editors, etc, user groups need to be defined.
 
This project excites me since I'm learning tons of things about PHP5 and Joomla, which happens to be a great framework content system, not only CMS. As soon as I have something releasable, I'll show it to the world.
 

Lars Wirzenius: Random thought: Lisp logos

Just when I thought nothing could save this week from being an utter disaster, I learn about this: the Lisp logo set. Absolutely hilarious!

Joe Wreschnig: GNOME Performance Day + 3 = Python Performance Day

To whoever decided it would be a good idea to make Python’s gettext.ngettext search the filesystem for the domain’s mo files every time it is called (potentially one “J. David Ibanez”), please don’t go near any standard libraries ever again. You are personally responsible for almost 30% of the time spent loading Quod Libet’s album list, and probably a proportional amount of time wasted elsewhere in the program. For people using gettext.py, here is something to replace gettext.install with:
def install(domain, localedir=None, unicode=False):
    import __builtin__
    t = translation(domain, localedir, fallback=True)
    __builtin__.__dict__['_'] = unicode and t.ugettext or t.gettext
    __builtin__.__dict__['ngettext'] = unicode and t.ungettext or t.ngettext
(Python 2.4 users may want to have the codeset kwarg as well. Update: Fixed a thinko where I used “self” and meant “t”. Submitted upstream.) Now with added bonus of not having to import ngettext yourself in every module. (Yeah, using __builtins__ is kind of ugly, but I’m just going for minimum interference with existing code.) Before:
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1851    0.020    0.000    1.070    0.001 gettext.py:475(ngettext)
After:
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1851    0.000    0.000    0.010    0.000 gettext.py:345(ungettext)

1 November 2005

Adeodato Sim : A real real game

I have a simple and fun game for you:
  1. Enter #debian-devel.
  2. Pick a random Spanish developer, e.g. “jordi”.
  3. Write their nick, a colon, a space, and the word “Leonor”.
  4. Watch them explode.
NP: Luis Eduardo Aute, No es en vano

30 October 2005

Steve Kemp: Advogato + Syndication

Advogato
Randomly clicking around Advogato today I accidently tried to login. Rather than seeing “Person not Found” which is all I’ve seen since my account(s) were removed I now get “incorrect password”. It looks like my primary, and replacement accounts at Advogato are back. At the time those accounts were removed I setup this blog so that I could still remain syndicated upon Planet Debian. It would be nice to have the Advogato account(s) back, but I could live without them. (Indeed mailing Raph at his acm.org address bounced so I may will have to)
Syndication
For my own notes. This blog appears at: Stalker-tastic. Of course my daily life goes entirely elsewhere - but that contains rudeness, angst, & etc. As you would expect from LiveJournal ;)

Brett Parker: Hmmm... anyone know of a generic python wiki parser?

I'm looking for a wiki -> html style, generic, parser... It's not that difficult to write one, but I wondered if you fine people out there might already know of one before I set about writing one... I could, in theory at least, use the parser from moinmoin, but that does seem very very tied in to moinmoin. It'd be nice to just use something like...
wikiparser = WikiParser(type="somewikistyle")
html = wikiparser.parse("somewikidocumentasastring").getHTML()
And have the WikiParser first generate an internal structure based on the markup (possibly, in effect, creating a dom tree), which is then returned at the .parse stage, then having different calls on that tree to, say, generate simple HTML, or LaTeX, or PDF etc. Hope that makes sense to people that aren't me.... Thanks, Brett.

28 October 2005

Clint Adams: Plots against plots

Joey, in a hilarious exposition about thread patterns, mentions k00ks, which reminds me of movie adaptations. Every time good books get turned into movies or things one seems to call miniseries even when they aren't, deep, thoughtful critical analysis sparks discussions that I am somehow forced to endure. Oh my god, that was so wrong. The book was very specific about how many steps there were, and Peter Jackson just went and changed it for no reason. There was a book? That was good. It was exactly like the movie. No, it wasn't. The book didn't have Dumbledore crossdressing, Hermione being a dirty little slut, and Harry sodomizing Hagrid and all the animals. Well, it had the same feel. What you have to do is not think of it as having anything to do with the book. Then you might enjoy it. It's a movie. Enjoy the movie. It's a movie. I can't believe they didn't do anything about Sunny's teeth. It's like Even Cowgirls Get The Blues, only botched in the opposite way. Then there's the fun game of sitting around and arguing about which adaptation of Dune is the worst: some version of the movie, or the SCI Fi Channel miniseries. Who ever thought that hats would enter into a discussion like that? Not I. I still have some hope for the 18-hour Italian version featuring Salvador Dali, assuming they can resurrect Dali and start making the movie again. Speaking of the SCI Fi Channel and their high-quality programming, I made the mistake of watching Legend of Earthsea, a miniseries with two whole parts. Don't worry about this movie wrecking the books for you; it bears little resemblance to the Earthsea books by Ursula K. LeGuin. Apparently Ursula noticed this too, because she complained about the adaptation. It looks to me that she's being far too kind. My guess is that they took a a few of the books, ripped out some random pages, shuffled them, and gave them to the people who made the BeastMaster TV show, with instructions that didn't make sense in any language. The best part of this miniseries for me was the point at which I was screaming at the guy on the screen (who was obviously a Hampshire student at some point) to go back and get his hackeysack. Now I read that they're going to take religion out of the His Dark Materials adaptation. As Kaki would say histrionically, Kill me now.

Eric Warmenhoven: More books

Continuing on the reading binge, I’ve read: The Warren Buffet Way by Robert G. Hagstrom: This book got really repetitive after a while. Warren Buffet is a disciple of Benjamin Graham, the original value investor, who is referred to heavily in all three books. According to Graham, the theories of an efficient market don’t apply very well, and it’s occasionally very easy (especially during a recession) to buy companies (or their stocks) for far less than they’re worth. Buffet simply buys the whole company. The best advice is that “the market is only useful as a reference to see if anyone’s offering to do something foolish”. It’s a theme that’s echoed in all three books. One Up On Wall Street by Peter Lynch and John Rothchild: Not as good as I’d hoped, but in some ways better, and worth reading. The title comes from the idea that individual investors are actually better placed to take advantage of the market before institutions, since they often have access to information to assess a company with before analysts even take a look at the company. He then follows this up by saying that you should treat it as a tip, and that you should treat all tips the same: as a reason for investigating a particular company. All of the preceeding didn’t impress me much. But he then tells you how he goes about assessing a company, especially reasons why he won’t buy a company, which I found very helpful. The Intelligent Asset Allocator by William J. Bernstein: The best of the three. This book picks up where Random Walk leaves off; that book encourages diversification, while this one shows you how to do it. Also, Random Walk focuses largely on the stock market, whereas this book discusses lots of asset classes and the correlations between them and how to pick a portfolio designed to maximize return while reducing risk. Also he spends a lot of time on specific details about which mutual funds are good for various asset classes, as well as various tips for really squeezing out as much return as possible through thinks like tax-conscious funds.

27 October 2005

Dirk Eddelbuettel: RQuantLib release 0.2.0

An update of my RQuantLib package with R bindings for QuantLib went to the incoming directories of CRAN and Debian earlier and should progagate to mirrors shortly. This release contains new code interfacing QuantLib curve generation and a BermudanSwaption pricer contributed by Dominick Samperi. Dominick also wrote a new R/C++ interface class which may prove useful in other contexts. More details are at the RQuantLib page.

26 October 2005

Brett Parker: Broken Flowers...

Went to see Broken Flowers with JD and Laura, was a very deliberate (read: slow) film, that leaves a lot of unanswered questions... but that in itself was really quite interesting. Very odd ending, it really does just end, leaving the running question through the film entirely unanswered, which was fantastic :) Anyways - only a few more days then it's off to Norwich for a partay! Should be arriving in Norwich sometime Saturday afternoon (depending on when I leave Brighton, and how well I remember how to get round to Liverpool Street and get the Norwich train. I'm planning on getting in to Norwich sometime ~ 1500 or 1600, which gives me enough time to find stuff before wandering off to find the party at 1830 (ish).

Axel Beckert: No meat today, my game has gone away...

Jick seems to have wrecked the main KoL database and restore doesn’t seem working as expected. So KoL will be down for a while. Which means for me: More time in the evenings. ;-)

Now playing: Hermit Permit -eh- Hermits Herman’s — No Milk Today

Next.

Previous.