Archive for the ‘Uncategorized’ Category

Cometd and me

Friday, February 8th, 2008

I kind of go on tangents when I do personal projects. First my goal was to make a poker game for bots to play… then somehow it diverged to making an ajax client…. somehow it diverged after that to use comet/cometd to do it… and then finally I decided to rewrite the cometd-twisted for my own evil.

Basically, for games and such, the bayeux protocol is a good place to start, but all the publish/subscribe stuff is superfluous. I basically just wanted to use the heart of the protocol and the ability to use the existing JavaScript libraries.

I think what I did is pretty cool. Basically, I made it so when a client connects it spawns a new client class. Then when they subscribe to a channel it makes a ChannelSubscription class. The messages are routed through this. Each ChannelSubscription behaves as a logical connection to the client such as a Protocol class with Twisted would. In fact, there’s about 3 lines of difference between my TCP layer for my poker client and my comet layer now. It’s pretty cool.

I set it up so that authentication and such would happen one level on top of the Bayeux protocol to allow for more customizations. It doesn’t matter whether or not they connect.

I have half of an ajax poker client written for my server with this, but it’s basically just a proof of concept that this works. I think I’m going to write a blackjack server too to allow for easier testing, and a better demo for when there aren’t people to play against. It’s simpler, and I already have most of the code done in Ruby from a long time ago… I just need to port it over Python.

Anywho… I’m calling my cometd server ucommet. Why? I couldn’t think of anything better.

The source is here for all the stuff (you want ucommet.py and possibly tabled.tac to see how it’s used)

you can do a “svn co http://svn.lolrus.org/dpoker/trunk dpoker” to get my poker tree.

You’ll need twisted.web2. If you have twisted 2.5, actually might have to get the SVN version. The apt-get seemed to get a working version for me in Ubuntu, but on my Gentoo server it was a whole different story :(.

I’m going to be in Prague with some friends for the next three days (my last days in Europe before I come home). Then once I get back to the states, I’m going out to Cali for a day or two for an interview. It’s been too long since I’ve had a burrito or a double-double. So what this means is I probably won’t have time to work on this for the next week or two.

Better Keyword Search for Wikipedia in Firefox

Wednesday, February 6th, 2008

If you’re not aware of the “Add Keyword for this Search” try going to google and right-click on the search box, and click “Add Keyword for this Search” and just put a keyword as “test” for now. Now, hit ctrl+l (or cmd+l on a Mac) and enter “test election” and it will take you to a search page as if you searched google for “election.” Basically, you can do this with any search box. It’s really great, actually. I much prefer this method to the search box because I only like using one hotkey.

Anyways, since I frequent Wikipedia a lot, I have one set up for Wikipedia. Unfortunately, Wikipedia isn’t all that good at catching your typos or knowing where you really want to go like Google does.

Solution: Set up a quicksearch to use google’s are you feeling lucky to search wikipedia.org. Here’s how you do it:

  • Go to Bookmarks->Organize Bookmarks
  • Create new bookmark
  • Add a name and appropriate keyword (I chose “wiki” for mine)
  • For the location use:
    http://www.google.com/search?hl=en&q=site%3Awikipedia.org+%s&btnI=745

I found a nice little tip on what to add to the search to “feel lucky”.

dPoker Progress

Sunday, February 3rd, 2008

So most of my finals here are done.  I have a week before head out to Prague for a few days before flying back to the U.S.  I think I’m going to put on about 10 pounds the first week I am back because I miss all the delicious food.

This means I might get my dPoker server working.  I have a bit of the Twisted stuff in place.  I’m currently working on the gameflow logic right now and trying to engineer a good abstraction for it.  Right now I am just doing a TCP implementation, but since the whole protocol is in JSON it should be easy for me to make an HTTP thing for it too, and be able to hook up to JS.  I’m thinking perhaps a widget?  I’ll keep y’all posted.

simplejson vs. python-cjson

Friday, January 25th, 2008

I needed a package that decodes JSON into dictionaries/lists etc.  I’ve used simplejson in the past and it’s worked fairly well.  I came across another package today that claims to be at least a hundred times faster than the other JSON implementations for python called cjson.  I was a bit skeptical because simplejson has C extensions too.

I decided to run some quick benchmarks.  The code I ran can be found here.

benchmark data:
processor: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
x86_64 Linux.
simplejson 1.7.3 (I assume the c extensions are enabled because I used emerge to get it)
python-cjson 1.0.5
Python 2.5.1

simplejson results:
% time ./simplejsonbench.py
./simplejsonbench.py 38.97s user 0.00s system 99% cpu 38.968 total
% time ./simplejsonbench.py
./simplejsonbench.py 39.17s user 0.01s system 99% cpu 39.187 total

cjson results:
% time ./cjsonbenchmark.py
./cjsonbenchmark.py 0.77s user 0.01s system 99% cpu 0.784 total
% time ./cjsonbenchmark.py
./cjsonbenchmark.py 0.77s user 0.03s system 100% cpu 0.794 total

simplejson average: 39.07s
cjson average: 0.77s

verdict: cjson 50.74x faster in this benchmark

I’d run more, but I don’t really think I have to. Simplejson actually seems to have a more robust interface than cjson, and is more portable because it doesn’t require a C compiler.

The cjson website has some other numbers that measure actual measured throughput of cjson vs. simplejson. The versions of simplejson is older, and it states there’s no C extensions compiled in.

Website Stats

Friday, January 25th, 2008

My blog gets very little traffic.  Actually, about 60% of it is people searching for the word “lolrus”, coming here, and being quickly disappointed then leaving right away.  I’ve been using awstats for a long time now, and recently just tried Google Analytics.  Google Analytics is soooo much more intuitive to use than awstats.  It also seems to have less noise in the data.  For example, /wp-admin is shown as one of the top things visited in awstats.  I don’t really care how many times I visit /wp-admin.  Google Analytics filters that out.  It’s interface is pretty slick too.

Aside from that, the job hunt continues.  Have a phone interview tomorrow.  I’m hoping to find a job before spring quarter starts so I can concentrate on my studies and finish on a good note.  It’s going to be a rough quarter.  I’m pretty psyched though because I’m probably doing an independent study implementing the iCAM image appearance model in Quartz Composer.

New Project: dPoker

Thursday, January 24th, 2008

I started a new project a few days ago. It’s one I’ve been pondering over for a long time, and it’s about time I did something about it. I’m bad at naming projects, so I chose dPoker, the d is for donkey.  Donkeys are cool either in poker, on waffles, or on waffles on VT200s in Sysprog class. Basically, the core of the project is just a poker server. It’s purpose is for bots to play, compete, and learn, not really humans. Of course, humans will be able to play too, once somebody writes a client. I have a few friends interested in working on this too, but I need to get a proof of concept together first.

I set up a trac for it here.

Here’s a few technologies I’ll be using and design decisions (for the proof of concept at least) and why:

  • The server will be written in Python.
    • it’s relatively fast and small in memory (compared to Ruby)
    • good libraries
    • readable
    • native thread support
    • I find it fun to write
  • Probably using Twisted framework.
    • It seems nice and supports a variety of protocols.
    • Eventually want to make a javascript client
    • Don’t want to reinvent the wheel
  • SQLAlchemy for data logging and account
    • I really like it
    • Sadly, there’s no recent updates to Asynchronous wrappers for for like a year, so I will probably have to roll my own :(.

I’ll be using a very simple protocol so people can easily write their own clients/bots in any language.  I’m trying to design it to scale well over multiple processes and servers.  It will also be modular so it can extend to different card games or non-card games.  The primary reason i want it to be scalable is because if computer learning is to be done, it has to either go really fast, or support hundreds of games at once.  There’s latency over the internet, so that would be the bottleneck for how fast a game finishes.  So my solution for networked games would be to have say maybe 10-100 instances of a bot running in that many different game rooms.  Although, there would still be latency, it would still increase the game’s played/time period.

Me or a friend will write a JS or even a flash client  so people can easily play over the internet against bots or each other.  I’d still have to work out a way to get people to try instead of going all-in all the time, but I think this would be important to add a bit of supervised learning to the mix and see how these bots evolve.

Never Seen This One Before

Saturday, November 17th, 2007

…randomly in all my terminals
Message from syslogd@loltop at Sat Nov 17 20:07:51 2007 ...
loltop kernel: [123903.232000] Disabling IRQ #18

And now sound won’t work.

Berlin ‘n Stuff

Sunday, November 4th, 2007

The first day of BarCampBerlin was interesting.  There’s a ton of bloggers, a ton of non-technical people, but that’s cool.  A few people came to my session on Pylons, but stuff broke, so maybe they shouldn’t have :).  I tried to emphasise the awesomeness of SQLAlchemy, which is what the people that came were mainly interested in.

Partying in Berlin is crazy… Clubs don’t close at 2:00 AM like in the states, but that’s when the party starts.  And the techno is amazing.  I was dancing until 6:00 today… and then I had to wake up at 9:00.  So tired.   I’m pissed at the hostel I stayed at too… they didn’t have lockers.

Lates.

Gmail + IMAP + iPhone = Win

Thursday, November 1st, 2007

So, I’ve been using the POP gmail for a while now, since I’ve had my iPhone and it absolutely sucked because I’m subscribed to very active mailing lists such as wine-devel and gcc ones, and I had them automatically filed out of my inbox in Gmail… but when you use POP3 access you get everything in your inbox, so I was flooded with all this crap I didn’t want to see on my iPhone and the iPhone has no sorting facilities.

I finally got IMAP for gmail today and it’s AMAZING.  It does all my tags and everything… They did it perfectly.

Props to the Gmail team.

BarCampBerlin Next Weekend

Tuesday, October 30th, 2007

So, I found out there is a BarCamp in Berlin coming up this weekend… And I decided to go. I want to present so I have to get my shit together. It seems like it will be a little more focused than the BarCampBlock in Palo Alto… So I’m not sure how a session on the impact of lolcats would go over. I don’t think any other low level hackery would fly either.

This leaves me with a couple options. One of them includes iPhone stuff, such as setting up the llvm-gcc crosscompiler in Linux, maybe an intro to UIKit, or something else.

The other idea I have involves pylons. I’m pretty familiar with the basics, but I think it would be nice to shed some light that Rails and Django aren’t the only MVC web frameworks out there.I really hope to get a more global perspective of what’s going on while I’m there an meet a bunch of new people.