• Home
  • About Me
  • Contact

kanorben.net - blog

My personal blog on technology, programming, life, and the random


 

July 2008
M T W T F S S
« Jun    
 123456
78910111213
14151617181920
21222324252627
28293031  

Blogroll

  • Boing Boing
  • BorjaNet
  • Brian Mayer
  • Dean Armstrong’s Blog
  • Ellen Smith’s blog
  • Faraocious
  • Gross or Awesome?
  • Marcus Westin’s Blog
  • Paul Mantz’s Blog
  • Slashdot
  • TechCrunch
  • Tomorrow with Alex Beinstein
  • Valleywag

Personal Sites

  • DOIT Fortune Database
  • My bookmark’s on del.icio.us
  • My CS account page
  • My Facebook Profile
  • My LinkedIn Page
  • My Picasa Albums
  • My Twitter
  • pyXSD
  • The SUCCESS Blog
  • UofC ACM Site

webcomics

  • Questionable Content
  • The Perry Bible Fellowship
  • Welcome To The Future
  • xkcd.com

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Add to Google Add to My Yahoo! Subscribe with Bloglines
Bloggers' Rights at EFF

Twitter Updates

    RSS My Del.icio.us

    • VX32 Virtual Extension Environment
    • Starting Forth's home-page
    • Quick start - The Open Source Backup Wiki (Amanda, MySQL Backup)
    • Telemarketers - Kill the Calls
    • Ian Bicking: a blog :: Python HTML Parser Performance
    • Mac OS X 10.4 Tiger: Page 5 - launchd
    • MidpSSH | SSH and Telnet client for Mobile devices (MIDP/J2ME)

    RSS My Facebook Posted Items

    • Neave Television ...telly without context
    • Cock Puncher: The Game!
    • Clever Squirrel
    • Thurston Moore Interviews Beck and Mike D
    • Ubersite - How I Ruined My Neighbor's Christmas, New Years, and Birthdays for Years to Come...

    Creating Interfaces in Python

    February 9th, 2008 by knorby

    While working on our project for software construction today, my partner and I started to work out an implementation of interfaces in Python. Fortunately, we didn’t end up needing to go to this extreme (it’s a weekend assignment). Interfaces have been proposed for python before, but the changes were never made. Anyway, we worked out a basic strategy to implement interfaces in python. The most common approach for this sort of thing is to just make a base class with methods that raise the NotImplementedError if they should be overridden. For the most basic implementation of an interface, this approach works, but what if we want to put contracts or a docstring test on this method? There is essentially no way to go about such an implementation with standard methods in python. Instead of using the traditional syntax to express inheritance, some function would be needed to implement interfaces. Really, most of we want to get from the interface could be considered “shell” around another function. We just want to put in the guts part of the method, and if the guts are not put in, python should raise an error. The easiest way to implement something like that would be to just maintain two methods. So, for every method foobar(self, arg1, arg2, …), there would also be a function __foobar(self, arg1, arg2, ….). Perhaps a different convention, such as __Interface_foobar(self, arg1, arg2, …), would be appropriate as to not interfere with one’s ability to assign __foobar to something else, but these are points are trivial. Ideally, I will come up with some sort of nice interface metaclass or base class and a set of function decorators that would take care of much of the work involved, but written out if full, it would look like

    class Foobar(Interface):
        #===============================================================================
        def __init__(self):
            raise NotImplementedError, "__init__ must be implemented by a subclass"
        #===============================================================================
        def foobar(self, aArg):
            """
            This is a function is the shell of an interface method
            """
            if not isinstance(aArg, BarType):
                raise TypeError, "aArg must be a BarType"
            return self.__Interface_foobar(aArg)
        #===============================================================================
        def spam(self):
            """
            Just some regular method.
            """
            return 3

    Then after defining some class that implements this interface Foobar, do something like this


    Foobar.implementedBy(eggs)

    I will probably have to make some changes once I start banging away at python. I know python well, but I don’t know every bit of trivia.

    One of the consequences of this setup is that everything is done at runtime, and some external testing procedure would be needed to verify that everything follows the interface. On the plus side, these would be something unique from interfaces as well; these thing really could be used for a whole bunch of things beyond the scope of normal interface. Also, everything needed to implement this sort of thing could be done without any changes to the language itself or use of modules outside of the python standard library. So, I will work on this thing sometime when I have time, which is never…

    Posted in Python, coding, design | No Comments

    Ambigious Signs

    February 5th, 2008 by knorby

    I pass a sign every morning that reads “no trespassing violators will be prosecuted,” only with each word on a new line. I walk through the place as it blocks off my street. I don’t think I should have to walk through a sketch ally turned road that is without a sidewalk just because some construction group bribed some local politicians. The place’s location makes next to no logical sense without considering graft or “patronage.” Back to the point, the place seems like the type that would definitely want to go after trespassers, though I don’t think UofC students are exactly the target audience. I always find this sign curious as it does nothing to separate “no trespassing” and “violators will be prosecuted,” which I assume is what it meant as that message is the norm. Regardless, the full statement clearly says that no one will be prosecuted for trespassing. I don’t know much about what the legal meaning of sign even is, but I would think that if they meant anything, the apartment complex might have a hard time going after trespassers in court if the trespasser just pointed out the sign. Perhaps the usual meaning would win…

    I noticed the same problem on a sign outside the botany pond. The sign read “keep off thin ice.” If there was a separation,  the intended meaning would come through. I of course am assuming that the UofC would generally prefer people to stay of a possible hazard…

    I just don’t get why companies who do nothing but make signs would have gotten the concept of separation down at this point.

    Posted in Chicago, design, rants, uchicago | No Comments

    Playing with userChrome.css and userContent.css in Firefox

    January 25th, 2008 by knorby

    A little while ago, I started playing around with the userChrome.css and userContent.css files in Firefox, and I have been rather pleased with the results. As far as I can tell, few people know about these files (perhaps I am mistaken, but most people I know have never seen them before). The files are located in the chrome folder in a given profile. On Linux at least, the path to that is
    ~/.mozilla/firefox/{weird alphanumerical sequence}.your_profile_name/chrome

    On Macs, the profile directory is in
    ~/Library/Application Support/Firefox/Profiles
    I don’t care about windows…
    The arrangements of profiles is what I consider to be one of the prime examples of why Firefox isn’t a great piece of software. If I ever want to edit my profile, I have to remember the my profile begins with an r, or at least view all the other profiles, when I tab complete on the folder. For some reason, using unique profile names wasn’t enough for Firefox; it attaches an 8 letter alphanumeric sequence before the name of the profile. I really see no reason for this extra bit of crap. Perhaps it allows for profile name changes more easily, but it is not like people really futz around with different profiles too often. Given that there are things that a user might want to edit in the directory, this crap seems unnecessary. The directory structure inside the .mozilla folder doesn’t make too much sense either, but I won’t go into that now. In general, I use Firefox, because I believe it to be the best browser out of a series of really awful software packages. Maybe I am horribly naive, but the browser doesn’t seem like such an achievement in software to warrant the amount of attention Mozilla gets (or the money). That aside, one can do some nice things with Firefox.

    The userChrome.css and userContent.css files allow a user to change the default css for the XUL in browser.xul (I think it applies to all XUL, but I haven’t tested that or bothered to look it up) and the default css used in the browser for sites. These files must go into the chrome/ directory of a user’s profile. There are example files already in there, which just need to renamed to get you started. There is a page on these files on the Mozilla website as well as some additional examples. I haven’t done much to userChrome.css; I got rid of the throbber (thing in the top right corner, which likes to spin) and I set my url bar to have a fixed width font. Those mods are both in the example file. The userContent.css file is a little more fun… As outlined in the example file, you can get rid of annoying tags, like marquee and blink. I added a rule to remove text decoration from links except for hover:

    a { text-decoration: none ! important }
    a:hover { text-decoration: underline ! important }

    The ! important part lets a page’s css override my own. It sometimes tricky to spot out the links, but I appreciate the overall aesthetic it produces. There is also a way to set it to only apply to individual pages. I choose to modify my google search results:

    @-moz-document url-prefix(http://www.google.com/) {
    .g {
    border-bottom: 1px solid grey ! important;
    padding-bottom: 1em;
    }

    }

    As of now, I forgot why I made the url prefix just google.com as opposed to google.com/search, but I must have had a reason. Either way, my experience has shown me that the g class is not used elsewhere on google. Anyway, this snippet adds a line between each search result. Here is a screen shot of the end result:

    Google Search Result CSS Tweak

    Posted in XUL, css, design, firefox, google, internet, mozilla, web design | 1 Comment

    The Oak Ridge Starbucks Hates Sedans

    December 28th, 2007 by knorby

    The car in the front is a sedan, the car behind it is an SUV. Notice the height of the ledge in relation to the car.

    I normally try to avoid Starbucks as much as my love for coffee will allow. I think the coffee is sub-par, their stuff is not exactly fair trade, the prices are too high, and I generally don’t like the overall atmosphere. Even at the drive-thru, they ask you “how can I get you started off today?” or something like that. Is the mere idea of phrases like “can I take your order?” so offensive that they have to act like they are providing in-store service? Anyways, I have been back home on Oak Ridge, TN for the last couple weeks, so I have occasionally gone by to get some coffee. I normally like to minimize my time in or around Starbucks, so I have been choosing to use the drive-thru. Anyways, I noticed that the window was not quite made for those in sedans, more so than most places. If the window was just a little higher than the usually amount, it would just be mildly annoying, but they added in a ledge, which makes it hard to get anything from them. I am fairly tall, so I have no problem as far as reach, but I can easily imagine people struggling with it. It is impossible to access the tips jar while sitting down (don’t know why you would want to. My latte was terrible!). Look at the picture, the top of the tip jar is just a few inches shorter than the roof of the car! Given that they serve hot drinks, I imagine that sooner or later, someone will spill coffee on themselves as a result of the height difference and sue. Sure sounds a hell of a lot more justified than that McDonald’s case a few years back. I am sure the height was determined by market research of some sort; I am sure that a lot of SUVs frequent Starbucks, but that doesn’t seem like justification for supporting those who choose to drive a gas guzzler. Besides, I went around and checked a bunch of other drive-thrus, and most to seemed to be at the same height, which was lower. For comparison, I went to sonic later and noticed that the ledge there was even with the side-view mirror. It seemed like a height ideal to accommodate everyone. I just don’t get what Starbucks has against sedans.

    Posted in Oak Ridge, coffee, design | 1 Comment

    On Writing Human-Only Readable E-mail Addresses in Plain Text

    December 12th, 2007 by knorby

    Since I am not a big fan of spam, I normally do something to obfuscate my e-mail address whenever I put it up on a publicly accessible site in plain text. I usually don’t do anything special; I just do something like name {at} example {dot} net. As far as I am aware, spammers have not started to collect addresses formatted using such methods, but it has always bothered me, because it would be so simple to collect such addresses. Of course, that fear is far greater with any sort of compute-generated obfuscation. For example, mailman has a particularly dumb formatting. Every address is like name at example.net. Since spammers don’t have to worry about false positives, they could collect every address off of a mailman archive just by joining together every word immediately before an ‘at’ with the word that comes immediately after the ‘at’ with an ‘@’. Without reducing the accuracy, the false positive count could be reduced just by checking for a dot in the latter word. Really, the difficultly in extracting such addresses is incredibly minimal. The only reason that it is not an issue yet is that there are still enough people out there who put addresses up without any sort of obfuscation, so the task is still easy. I am think that spammers will have to start collecting such addresses soon enough, if they haven’t started already. So my goal is to determine exactly how I would go about an e-mail extraction system were I a spammer; this way, I can determine what sort of addresses could not be extracted easily. To start, let’s go through the assumptions we are making about spammers:

    • False positives aren’t important. There will be plenty of bad addresses already, so a few more won’t hurt.
    • Want to keep everything simple. The spammer is not looking for the theoretically best system, just something that works and is simple to write.
      • Want to write things for the most global cases. If someone does something unique, then we should expect the system to fail.
    • Keep the system to the level of joining together strings. Don’t look for cyphers or anything like that.

    So of all things, the obfuscation method is least likely to do anything to the actual text in the address. In the name@example.net example, ‘name’, ‘example’, and ‘net’ are never changed. The only constants here are the top level domains such as ‘com’, ‘net’, ‘org’, ‘edu’, etc…. On the web, the most frequent occurrences of these TLDs will be in URIs and e-mail addresses. The first step would be to filter out the URLs from this mix. Any address without a protocol specified would result in a false positive. First thing to do is find all the obvious addresses. With the rest of the TLDs found, if the match is connected by a dot to anything to the left, join the word to the word occurring two positions to the left with an ‘@’. Otherwise, join the word two positions to the left with a ‘.’, and then join that new string with the word two positions to the left of that with an ‘@’. The spammer surely could think of other methods like these I have outlined. This exercise makes it clear that the only way to avoid most trouble is to come up with some sort of encoding method that is human readable, but is obfuscated to these sorts of general extraction methods. With something like an e-mail address on a uchicago system, if it is listed on a uchicago site, it is possible to make abbreviations like uchic.... edu. These sort of obfuscations could still be detected by a sophisticated extraction system, but it would be too much of a hassle for too limited results. There are other tricks one could employ along these same lines; for example, the addresses name..../\7.....example#...#net or USER:(....name....) |AT| ADDY:(....example{dot}net....) . The problem with these is that they are just human-readable, and a means to extraction is not that far off.

    What is the best solution? For all intents and purposes, I consider javascript obfuscation the equivalent to putting addresses in plain text without obfuscation. As I have previously discussed, it is pretty easy to extract the contents of the DOM from firefox. The first method that comes to mind is essentially a series of variations on the barely readable obfuscations. Basically, using php or something else server-side, addresses can be written as normal, and then encoded. The problem with this solution is that these methods are barely human-readable, and the text is still left unaltered. What sort of method could leave everything as human-readable but also modify the text itself? I haven’t been able to think of anything. Perhaps I will think of something soon…..

    Posted in coding, design, internet, web design | No Comments

    Some Local Python Humor

    December 2nd, 2007 by knorby

    I follow the local Python user group’s mailing list (see chipy.org). Though UChicago has prevented me from going to all but one meeting, I can say that it is a fun group. Anyways, someone asked a question that spurred a few hilarious responses. The two best are this one bit of coding absurdity and this one just hilarious response.

    Posted in Chicago, Python, coding, design, humor | No Comments

    Woot Shirt

    November 20th, 2007 by knorby

    shirt.woot! Not to be a shameless fanboy, but I really love Woot Shirt. I am a night owl, so I have no problem whatsoever checking this site all the time. There are at least a few decent ones per week, and $10 for a decent t-shirt with shipping included is hard to argue with. Since all the designs are done by random people, and there are random contests to decide some. I have definitely purchased quite a few of these. Anyways, its worth a look or two if you haven’t already seen it.

    Posted in design, internet, media | No Comments

    Using Firefox to Screen Scrape from the Command-line

    November 6th, 2007 by knorby

    So, here is the problem. I want to be able to get the source for a page after it has been rendered by Firefox (that is, loading javascript manipulations have been made, etc…). In other words, I want to be able to serialize the DOM in Firefox, from the command-line. Essentially, I am trying to write a massive hack. There are few problems that need to be overcome first. For one, Firefox requires some display. Since I only really care about Linux/BSD/Sun systems, I have to go through X11 (speaking of massive hacks…). Basically, I need a dummy X11 session. I don’t care what is displayed, I just want to send it somewhere. VNC, fortunately, provides this interface. It is worth noting at some point that I have not fully written this yet (laziness + hard-ass school = project stagnation), but I have a very good idea of what it will do. Anyways, the display is one small part of the problem; the trick here is getting the DOM out. I had some fun here. Unfortunately, DOM serialization must be done through javascript. Gecko provides a really nice little tool: XMLSerializer. I am not aware of anything like it in another browser, which just further supports my belief that Firefox/anything Gecko-based is simply the lesser of evils (bad design being evil of course). Why Mozilla decided the mix of XUL (an xml format Mozilla came up to design interfaces) and javascript would be sensible things to build a browser around, I don’t know, but it is useful here. The normal browser interface can be found at chrome://browser/content/browser.xul. You can have a lot of fun loading lots of these inside each other (see image). If you load browser.xul with firebug, you can play around with all of Firefox’s standard functions, which is always fun.

    browser.xul window multiload

    If you are creating a tradition extension, I suppose you would want to look at this stuff as well, but it is especially helpful here. Once this set of deep Firefox functions has been revealed, the actual loading of page is rather trivial. The real problem is I/O. I need to be able to pass firefox the link I want to open from the command-line, and write it to a specified location. Fortunately, there is JSLib, which provides things like I/O in javascript. From here, the solution is simple. I just want to make a copy of browser.xul, and add a few scripts into it. I then want to parse GET arguments on this file when loaded, since I can pass these to Firefox from the command-line. I would want one for the url, and one for the output path. Of course, these would have to be escaped before they could actually be passed to Firefox. That’s it! I was planning on calling it FireScraper. Hopefully I can finish it soon.

    Posted in VNC, XUL, coding, design, firebug, firefox, internet, javascript, mozilla, screen scraping | 2 Comments

    « Previous Entries

     
    Add to Technorati Favorites - Creative Commons License - © 2007 Karl Norby