Home

Biggest is not best in mosquito mating game

May. 18th, 2008 | 08:00 am
posted by: [info]new_scientist

Being super-sized is not an advantage for a mosquito since they lose out on mates to more average-sized insects (full text available to subscribers)

Link | Leave a comment | Add to Memories | Tell a Friend

James Tauber: Creating Gradients Programmatically in Python

May. 18th, 2008 | 02:38 am
posted by: [info]planet_python

For various sites I often want to create a narrow gradient image. This site has two, for example, the grey background gradient and the purple header gradient.

Rather than having to open up a drawing tool every time I want to create one of these, I thought I'd write a Python script to generate a PNG of a gradient according to declarative specifications.

The result is

http://jtauber.com/2008/05/gradient.py

Only linear gradients are currently supported although you can have any number of them at different vertical offsets and it's easy to modify the code to support other gradient functions.

The code itself is 50 lines long and has no dependencies other than the standard library. I've included some samples based on the gradients on jtauber.com and Pinax.

For example, this gradient:

is produced with the following code:

write_png("test2.png", 50, 90, gradient([
    (0.43, (0xBF, 0x94, 0xC0), (0x4C, 0x26, 0x4C)), # top
    (0.85, (0x4C, 0x26, 0x4C), (0x27, 0x13, 0x27)), # bottom
    (1.0,  (0x66, 0x66, 0x66), (0xFF, 0xFF, 0xFF)), # shadow
]))

The 30-line write_png function could also be used more generally for generating any RGB PNGs.

Link | Leave a comment | Add to Memories | Tell a Friend

hopeforyou

Nice evening

May. 17th, 2008 | 10:15 pm
location: Concord, CA
posted by: [info]hopeforyou

Tonight I went out to Daphne's Greek restaurant with [info]starry_sigh, [info]pure_agnostic, their daughter, and a pile of people from cohousing. Then we went out to the theatre to see The Chronicles of Narnia: Prince Caspian. It was a nice time out with a bunch of friendly people.

The movie? I think it was on par with the first one, really, and this one didn't seem to have as many moments that were slow as in the first film. The pacing was better on this one. The acting was a bit choppy in places or it seemed in one or two places that characters were overly expressive or perhaps schmaltzy.

The battle scenes and one-on-one combat were pretty good, I think, as were the scenery and sets.

There are some things about the way the story unfolds that I don't like, but that's the fault of C.S. Lewis and not the director or producer, so I'm not going to blame them for that.

I think it's worth it on the big screen. I'd go. But I will wait to see the animated Attack of the Clones on DVD, and probably will avoid The Love Guru...

Link | Leave a comment | Add to Memories | Tell a Friend

marnanel

The boy bands have won

May. 17th, 2008 | 10:47 pm
posted by: [info]marnanel

The other day I saw four guys playing Rock Band do a 100% perfect performance of Dani California... well, the computer had told them it was 100%. It is actually technically a difficult thing to do to play Dani California all the way through, but what they were doing was repeating a series of notes in an exact order, which isn't quite the same thing. A few weeks earlier, at a party at a friend's house, we played a karaoke console game, which was a lot of fun. During the evening, someone got a very good score on Me and Bobby McGee; the game was basing it on the Joplin version, and I was struck by the way the game scored you on getting the ad libs right-- it rather breaks my brain to be able to figure out what it means to get an ad lib "right", especially on a song Joplin was covering in the first place!

So what we have is a place where a very few people are the creators,and they get scored on their work, and if the rest of the world produces anything it's scored for fidelity to the creators' work rather than how well it builds on things.

There is a TV programme in the US called Wheel of Fortune where a woman called Vanna White puts big square letter cards on a wall. She is very famous for doing this. Samsung made a commercial based around a robot putting letters on a wall with reference to what she does; she sued them and won. It seems she's the only person allowed to go around putting big square letter cards on a wall. One judge wrote in his dissenting opinion: "Overprotecting intellectual property is as harmful as underprotecting it. Creativity is impossible without a rich public domain. Nothing today, likely nothing since we tamed fire, is genuinely new: Culture, like science and technology, grows by accretion, each new creator building on the works of those who came before. Overprotection stifles the very creative forces it's supposed to nurture". (I hope he won't mind me quoting that.)

Chumbawamba released an album whose title is "The boy bands have won, and all the copyists and the tribute bands and the TV talent show producers have won, if we allow our culture to be shaped by mimicry, whether from lack of ideas or from exaggerated respect. You should never try to freeze culture. What you can do is recycle that culture. Take your older brother’s hand-me-down jacket and re-style it, re-fashion it to the point where it becomes your own. But don’t just regurgitate creative history, or hold art and music and literature as fixed, untouchable and kept under glass. The people who try to ‘guard’ any particular form of music are, like the copyists and manufactured bands, doing it the worst disservice, because the only thing that you can do to music that will damage it is not change it, not make it your own. Because then it dies, then it’s over, then it’s done, and the boy bands have won."

It has often been the same way in the past, with a small elite of creators. But not all subcultures have been this way even in the developed world in the recent past. I'm happy that the free software world means there are more and more creators, and that the licences we use mean that people are encouraged to "restyle it, refashion it to the point where it becomes their own", but we need to find more and more ways to encourage and spread the idea that it's desirable or even possible to do so. Getting free software onto more desktops is an admirable goal, an important first step, but we need to help people understand they can be more than consumers.

(Disclaimer: I have never played Rock Band, and I suck mightily at Guitar Hero; I hope this isn't sour grapes.)

And a last word on this, from XKCD.

Link | Leave a comment {1} | Add to Memories | Tell a Friend

pacotelic

Hmm...

May. 17th, 2008 | 08:27 pm
music: Darondo - Didn't I (yes I am an NPR Whore)
posted by: [info]pacotelic

I just started reading rice-boy.com and wetherobots.com, The odd thing is that thois would mean that my habitual webcomics could start with A, S, D, Q, W, and R. All clustered within 2 square inches on the left side of my keyboard,

Somehow this seems to have a reason and a meaning.

Link | Leave a comment | Add to Memories | Tell a Friend

alienghic

(no subject)

May. 17th, 2008 | 05:13 pm
posted by: [info]alienghic

Apparently I created a monster of rock.

100_0380

Link | Leave a comment {4} | Add to Memories | Tell a Friend

dragonblink

Boom headshot!

May. 17th, 2008 | 03:39 pm
posted by: [info]dragonblink

So I'm wasting away in migraineville. My third day of off-and-on migraineowie and drugs.

At least I've finally figured out what my mystery second trigger is -- these migraines are, shall we say, a monthly occurence.

And I pissed off the monthly migraine gods mightly.

Cut for all you TMI pussies. Haw! I made a pun! )

Blargh.

Link | Leave a comment {4} | Add to Memories | Tell a Friend

theinfamousmom

Saturday ramblings

May. 17th, 2008 | 03:07 pm
mood: hot hot
posted by: [info]theinfamousmom

Back in the days when every head shop in the world smelled like patchouli, I didn't like the scent.  I guess times and olfactory preferences have changed.  Of course, my Lush "Karma" powder is a mixture of patchouli and citrus, but still, it smells good.

Poor Zoe is sick.  This is the worst cold she's had since she arrived here, and she's definitely going to the vet Monday morning.

A few weeks back, I bought some board games as requested by my nieces.  They had a fine old time playing Mousetrap, but we never did open up the Sorry! box.  Our Official Grandson Clark and his parents were due to stop by for a visit today and I thought "I wonder if he'd like to play these games?"  Lo and behold, he arrived with his own Sorry! game.  And believe me, that kid has got the strategy down cold.  I bet he's going to be a grand master if he ever decides to tackle chess.

I also taught him to play Snap, which my grandmother would play with my brothers and me by the hour (the only time my parents would trust us kids with their precious decks of cards).  He got the idea of that game in a flash, too.

I don't know if we had any actual plans for today other than the fun of having [info]aylara and [info]jeffrey and Clark come visit, but since it's already 104o in the back yard, if we had had plans we'd have long since said NEVER MIND.

Link | Leave a comment | Add to Memories | Tell a Friend

aqua_permanens

(no subject)

May. 17th, 2008 | 03:33 pm
mood: tired tired
music: INXS - Live in Brixton 1994
posted by: [info]aqua_permanens

I had a feeling that despite not really having the time for it, today would involve a trip to REI. I was right. I know that I had, at the end of my last camping trip, at least one, possibly two, fuel canisters for my stove. When I started looking through my camping bag, the stove was there, but no fuel. i still have no idea where they went. Did I think it was a bad idea to have them in with my stuff when I moved because of the danger of explosion? Was I worried about the change in elevation between SoCal and Santa Fe doing something to them? Or did I just stick them somewhere other than my camping bag? At any rate, nowhere in Santa Fe has the type that is compatible with my stove, so off to REI I went. It will be really nice when the REI opens up here.

Before that, I went to Albertsons, Trader Joe's, and Wild Oats for various groceries, got Natalie's mail, and stopped by the office. The stuff I forgot only took about ten minutes, fortunately. One thing I've been meaning to check on, since I spent $300+ for a full-sized spare tire, is to make sure my car has the tools for changing a tire, since I've always been lucky enough in the past to get flats in areas where AAA can come change it. I dug around in the compartment under the trunk and could not find a jack! Don't most cars come with jacks? I'm still wondering whether I just wasn't looking in the right place. And as I suspected, I have one of those useless crappy things for getting the lug nuts off. So I stopped by Autozone and got a jack and a T-wrench.

Another thing that has even more mysteriously disappeared from my camping bag is the battery-operated alarm clock I use for camping. So I stopped at Target for one of those, and a phone card. I could not find Yum Yum Mix at Home Depot, which surprised me, but they had it at a specialty garden store. I'm hoping that will help the yellowing tomato plants.

So now, I'm kinda pooped. I still have to finish packing, and I probably should take a shower since I won't get one for the next week. I really dislike showering, especially on weekends. I also need to finish watching A Zed and Two Noughts, which I started last night but didn't have the stamina to finish. Maybe I'll do that and have a cup of coffee, and then I'll feel more energized to finish up what I have to do.

Link | Leave a comment {2} | Add to Memories | Tell a Friend

jeffrey

(no subject)

May. 17th, 2008 | 02:25 pm
mood: hungry hungry
posted by: [info]jeffrey

Last night I worked from 6pm until past midnight on training new directors for Pendant and editing "Calls from the Public", which is thankfully only once a month now but still takes me over three hours to edit. That pisses me off to no end, let me tell you.

But because of that, I was too busy to stop and eat dinner, and didn't think to eat until I was on my way to bed. And I can't very well eat a big dinner and then go right to sleep, I'd be puking in the morning.

So today I've been ridiculously ravenous (even for me). Went to In-N-Out for lunch and ate a 3x3 (three beef patties, three slices of cheese) Animal Style and fries.

And then went back up and ordered another cheeseburger (no onion) and another order of fries.

Ate it all.

Thought to myself... yeah, I could eat more.

RRROWR!

Oh super-metabolism, how do I love thee?

Link | Leave a comment {5} | Add to Memories | Tell a Friend

Voidspace: Programming with Silverlight: Bugs and Missing Features

May. 17th, 2008 | 08:48 pm
posted by: [info]planet_python

I've spent the last week writing a chapter on programming Silverlight with IronPython (which is how I managed a whole week without blogging!). Despite the title of this blog entry it's actually great fun. ... [449 words]


Link | Leave a comment | Add to Memories | Tell a Friend

sam_malfoy

(no subject)

May. 17th, 2008 | 03:02 pm
location: My brother's room
mood: apathetic apathetic
music: Sister playing GH Hard Mode and failing
posted by: [info]sam_malfoy

So, first day of the new term.
Same teachers, same people. I did hope one or two disappeared but, meh, sometimes you can't have it all.

We have a project that must be completed before the end of the term. The tricky part is, we need to work as a group. I do not see a good result about this.

Don't get me wrong, I know that people are capable of doing his/her part of the job, but I still keep on thinking that, at the end, we'll be 5, maybe 6 people programming and the rest will be... there. I hate depending on others (heck, I was alone on the first term and did all my projects alone and never depended on anyone) and I hate bossing around people. If I can put some time apart specifically for my work, shouldn't everyone else do it too? But as I've watched my classmates, I don't think this will be happening anytime soon.

I do hope I am being a pessimistic (hurray!) and I'll be proved wrong, but 60% don't know how to code.

It's gonna be one of those semesters.

Anyway.

David is thinking of moving back to here.
I say 'thinking' and not 'trying'. Sometimes he infuriates me xD.
I do want him here, there's so much we haven't done as a couple and I miss him dearly, but I don't want to be a decisive factor of his decision. But he already said I was. I don't want to be a part of a problem, I know he hates here 'cos of the heat, but at the same time, he says he wants to come back, for me, and he'll endure everything he needs to endure.

We already discussed everything (moving back with his mom, maybe earning a lot less, the heat) but he says it's cool and it's not the first time he's done it. I do hope this is for the better and not for the worst.

Oh well, only time will tell.

Btw
Too hot.
And it's not summer!
Going to an anime convention, I'll bring pictures later =D

Ps. Hurray, spell check!
Ps2. Spell check, you fool!
Tags: ,

Link | Leave a comment {3} | Add to Memories | Tell a Friend

istgut

A possible idea for decent human interaction

May. 17th, 2008 | 12:58 pm
posted by: [info]istgut

Assume that everyone is packing heat and in a bad mood.

Link | Leave a comment {10} | Add to Memories | Tell a Friend

joedecker

Don't Panic!!: An analysis of the CA marriage decision on the 2008 Presidential Election

May. 17th, 2008 | 11:05 am
posted by: [info]joedecker

On several mailing lists I'm on (darbnet, babn-chat, ...), on LJ, and in person, I've had several allegedly pro-same-sex-marriage folks express significant concern, sometimes even mild panic, at the ruling and/or the timing of the ruling. After some time to think about it, I've concluded that it's going to be a negligible influence. Below, I'll outline the lines of argument I've used to come to this conclusion.

(Before I do, one note. The analysis below is moot. The die is cast, the decision is made. Moreover, claims that "this was bad strategy" on the part of (whom?) are ludicrous, the timing of this decision is very unlikely to have been planned, by ANYONE to coincide with the 2008 presidential elections, the justice system spent unpredictable numbers of years getting this case tried. What's done is done in any case, so chill out, okay? Good.)

Okay, here're the arguments:

First, and more generally, the same-sex marriage issue is just less new, and less news, than it was four years ago. Part of this is the success the pro-same-sex marriage camp has had already in Massachusetts, as well as civil unions in VT, CT, NJ and NH. The addition of California is less of a trigger, I think, that the Massachusetts was. If you don't doubt that this is just "not as big a deal" in the news, go ahead and check your favorite big news sources, the issue is already out of the headlines.

I think the "this isn't as big a change emotionally" sense would likely be particularly true outside of California.

Now, within California, one might imagine that the influence of the law would be greater, and yes, I might, just might, concede (although you should read the rest of this argument) that this raises GOP voter turnout for the November 2008 election (when an anti-same-sex-marriage constitutional amendment will likely be on the ballot). However, even if that's true, California is unlikely to go McCain, I don't think the Dems will have to work hard to hold California in the election (barring any big mistakes they might make going forward), and so, within California, CA's delegates will almost certainly vote Blue in the electoral college.

I'll add, in addition to this not being "new", the timing is not perfect for influencing the presidential election. It's still six months until the presidential election, I think that distance will leave other issues looking old and boring compared to whatever new stuff the parties dig up in the months to come.

I've seen the backlash arguments, and have often found them, in the fullness of time, to be overly played. Salon took this on recently, but that's not the only case, the 2004 "Valentine's Day Marriage Revolution in SF" was the cause of panic for some local Dems on my f'list, concerned that the backlash of that would spill onto the then-fragile progress of marriage in Massachusetts. That worked out okay, too.

Finally, we turn to our good friend, the data. The smart money was unmoved by the California decision. The leading for-money presidential betting line in the country is the Iowa Electronic Markets. Below I include data I've consolidated from their web site. (I'd provide a direct link to the data, but a direct link isn't possible with their site design.)


DateComb. VolumeDemRep
5/13/082290.5830.419
5/14/085560.6010.402
5/15/0817330.5950.420
5/16/082740.6000.406




These are the "last trades" for the day in each case, so the 5/15 data represents the first day of trading with the decision. Note the increase in volume, but also notice that the fluctuations in the predicted probabilities a Democratic victory are, right now, *higher* than they were two days before the decision, and that any effect of the decision on price is hidden within the entirely normal day-to-day fluctuations of that market.

In short, people betting their own money on the 2008 presidential race are, as a whole, entirely unconcerned about the impact of the California decision on the US Presidential race. I conclude, for all these reasons, that you should be unconcerned as well.

Link | Leave a comment {9} | Add to Memories | Tell a Friend

pacotelic

Synergy (I'll proactively invoice you in a forward timeframe)

May. 17th, 2008 | 02:35 pm
posted by: [info]pacotelic

“Synergy”. It is such a twee, loaded word. By using it I veer into a land of invoices and proactivity. Yet its concept is sound: the idea that the sum can be greater than the parts.
For an analogy that should make sense to 95% of Americans, imagine if you have a car. A very nice car, say a Lexus, or a Bentley, or even a Maybach. Take it, its yours. What are you going to do with it? Drive it, of course, enjoy all those horses and plush appointments. Not so fast, Jones. I’ve put this free, very nice car, in the middle of a hillside of switchgrass and ragweed, with no gas in the tank, and with one flat tire, no jack and no tire wrench. If you had 1) a road, or some kind of pavement 2) a gas station, with gas and pumps dispensing gas of the correct distillation from crude drilled from elsewhere (its about 40% likely this gas was drilled from somewhere in the US, you Patriot) 3) a tire, of the right size, with a machine to put the tire on the rim (This is no mountain bike tire, you’ve got to overcome a lot of tension to get this thing onto the rim). You’re going to need a way to get the tire off, just to get started. This will require a tire wrench, obviously. Jacking the car up will require pavement, at least a square foot. For that pavement not to sink under the ton of weight you’re about to put on it, it probably should be attached to a lot more pavement. Maybe you could use a log, if you weren’t in a field. The car’s on a hillside, remember? So when you jack it up, be sure it doesn’t roll off the jack. You’ll have to get another jack and you’ll throw out your back reflexively trying to hold onto the car when it does start to roll.
Or I could give you a 1995 Chevy S-10 with four full tires, a half full gas tank, and on your driveway. Much more useful than the luxury car, under these contrived circumstances.

Link | Leave a comment | Add to Memories | Tell a Friend

democritus

(no subject)

May. 17th, 2008 | 10:54 am
posted by: [info]democritus

Yay! I just went for my first bike ride of the season. I rode out to Ace Cider Pub. Boo! They were closed! Yay! I'm going to go to a pub in a little bit! And then maybe to the river.

As you can see, I wasn't able to do a Yay/Boo/Yay/Boo/etc post, so that is a good thing. It's probably yay that Ace wasn't open anyway, because I would have stuffed myself and got drunk and had a slow ass ride home. ;)

Link | Leave a comment {1} | Add to Memories | Tell a Friend

hopeforyou

Seen elsewhere...

May. 17th, 2008 | 10:54 am
location: San Francisco, CA
posted by: [info]hopeforyou

"Polyfuckery is like serial monogamy on steroids."

Link | Leave a comment {4} | Add to Memories | Tell a Friend

joedecker

(no subject)

May. 17th, 2008 | 09:00 am
posted by: [info]joedecker

This Saturday and Sunday I’ll be participating in Silicon Valley Open Studios at 1733 Hudson Drive, San Jose, CA. 11am-5pm each day. Drop by if you get a chance!

Link | Leave a comment {1} | Add to Memories | Tell a Friend

Paul Bissex: Pocket Django

May. 17th, 2008 | 08:23 am
posted by: [info]planet_python

At the Western Mass. Developers Group meeting this week I showed a few people some of the unixy fun you can have with a (jailbroken) iPod touch and the Cydia package manager. Cydia is a port of Debian's APT system to the iPhone platform -- i.e. it's a real package manager. It made it a snap to install Python, Mobile Terminal, Mobile Text Edit, Subversion, etc.

This is the toolset that has allowed me to even do some work on the book as I mentioned in my last post.

And while it has its limitations as a development environment, of course I did get Django running on it. Below are a couple screenshots of an example application from the book.

This is my kind of portable computer!

pastebin app


pastebin admin


Link | Leave a comment | Add to Memories | Tell a Friend

Ned Batchelder: Max: stop-motion for french, and Apple boston

May. 17th, 2008 | 01:15 pm
posted by: [info]planet_python

Two cool posts this week on my son Max's blog.

The first was a stop-motion animated movie he made as an assignment for French class with his friend Alice. It highlights the oppression of women in Algeria, and I think it is wonderful, both in its compassion and its technical skill. He made it with iStopMotion, a clever Mac tool that overlays successive frames with the current live view from the camera so that you can carefully animate your models.

On Thursday, he was at the Boston Apple store opening, getting a green monster t-shirt and special edition iPod sock. He's got lots of pictures of the event in his gallery.

Link | Leave a comment | Add to Memories | Tell a Friend

bald_ruminant

Amelia's Obsession, or Fairy Tales: Threat or Menace?

May. 17th, 2008 | 08:36 am
posted by: [info]bald_ruminant

My sister tells me that her daughter (age 4 and almost a half) can't understand why I'm not married. Uncles should be married. Aunts should be married. My brother-in-law's sister isn't married either, so my niece thinks we should be married to each other. (No, thank you. Not a good match at all.)

I'm blaming all those fairy tales that end with the hero marrying the princess and living "happily ever after" for this phenomenon. Come to think of it, I think they might be behind the widespread grammatical problem of people ending sentences with prepositions, as well. Damn, but those things warp children's minds.

Link | Leave a comment {2} | Add to Memories | Tell a Friend

Cosmic dust gives water a helping hand

May. 17th, 2008 | 11:43 am
posted by: [info]new_scientist

A lab test shows that frozen grains of dust in interstellar clouds are a likely site for the formation of water

Link | Leave a comment | Add to Memories | Tell a Friend

Bird migration at mercy of weather patterns

May. 17th, 2008 | 10:19 am
posted by: [info]new_scientist

Severe weather conditions as a result of climate change could make it impossible for migratory birds to complete their long-distance flights

Link | Leave a comment | Add to Memories | Tell a Friend

Ali Afshar: Blogger Comment Spam - Deleting it

May. 17th, 2008 | 09:01 am
posted by: [info]planet_python

It seems over recent months that my blog gets comment spam. I imagine any bloggers out there experience the same thing and it is a bit of a pain.

I have three immediate problems with this and blogger.com.

1. Blogger doesn't notify me of all comments at the time they are posted. It notifies me of some, and I have of course configured it to notify me of all comments, but it seems to miss off about 70%. So not only do I not notice the spam, I also miss a bunch of legitimate comments. Please get it together Blogger! Ajax panel configuration is nice, but only if the core functions work.

2. Blogger should/could/might try to stop this spam before it happens. I am not guessing how, but then the company that runs Blogger.com are much brighter than me, and I am sure they have a solution.

3. The interface for browsing comments and deleting many at a time simply does not exist. This would make the task of sifting through, identifying, and delting spam much easier.

Now that I have had my grumble about it, I will offer my small solution. In praise of Google, they do provide a nice API and Python bindings to access all of their services and blogger is one of them. So I wrote a small script to go through all the comments, do a little bit of flagging on dodgy looking ones and offer you a chance of deleting them.

The script is uncommented, has no tests, and I don't plan in any way to maintain it or release it, but for those people suffering the same problems, I provide it here.

It is worth noting that the spam detection is really pathetic, and it could be vastly improved. I targetted it at my particular spam.


Full script available here



"""
(c) Ali Afshar 2008
MIT License
"""

import sys, getpass

from gdata import service


def get_details():
email = raw_input('email: ').strip()
password = getpass.getpass()
return email, password


def create_service(email, password):
blogger_service = service.GDataService(email, password)
blogger_service.source = 'blogger_spam_killer'
blogger_service.service = 'blogger'
blogger_service.server = 'www.blogger.com'
blogger_service.ProgrammaticLogin()
return blogger_service


def get_all_blog_ids(svc):
query = service.Query()
query.feed = '/feeds/default/blogs'
feed = svc.Get(query.ToUri())
for entry in feed.entry:
blog_id = entry.GetSelfLink().href.split("/")[-1]
yield blog_id


def get_blog_comments(svc, blog_id):
query = service.Query()
query.feed = '/feeds/%s/comments/default' % blog_id
query.max_results = sys.maxint
feed = svc.Get(query.ToUri())
for entry in feed.entry:
yield entry


def get_all_comments(svc):
for blog_id in get_all_blog_ids(svc):
for comment in get_blog_comments(svc, blog_id):
yield comment


def rank_comment(comment):
words = 0
for word in spamwords:
words += comment.content.text.count(word)

author = comment.author[0]
has_uri = (author.uri is not None and
# I figure no one who puts a URI would link to a blogger
# profile. They would link to whatever they are spamming.
'http://www.blogger.com/profile/' not in author.uri.text)
print 'Spam words: %s' % words
print 'Dodgy author uri: %s' % has_uri
return bool(words) or has_uri


def delete_comment(svc, comment):
svc.Delete(comment.GetEditLink().href)


def filter_all_comments(svc):
for comment in get_all_comments(svc):
print '--'
t = comment.content.text
print t[:70] + '...'
print '...' + t[-70:]
a = comment.author[0]
print 'Author Info: ', a.name.text
if rank_comment(comment):
print '**** LOOKS DODGY'
else:
print '==== OK'
s = raw_input('Delete? (y/N) ').strip()
if s == 'y':
print 'Deleting.'
delete_comment(svc, comment)
else:
print 'Not deleting.'


# http://codex.wordpress.org/Spam_Words
spamwords = """
4u
adipex
advicer
...
""".strip().splitlines()


if __name__ == '__main__':
em, pw = get_details()
svc = create_service(em, pw)
filter_all_comments(svc)

Link | Leave a comment | Add to Memories | Tell a Friend

Isotoma: Some thoughts on concurrency

May. 17th, 2008 | 08:39 am
posted by: [info]planet_python

In an earlier post Over on the Twisted blog, Duncan McGreggor has asked us to expand a bit on where we think Twisted may be lacking in it’s support for concurrency. I’m afraid this has turned into a meandering essay, since I needed to reference so much background. It does come to the point eventually…

An unsolved problem

To many people it must seem as though “computers” are a solved problem. They seem to improve constantly, they do many remarkable things and the Internet, for example, is a wonder of the modern world. Of course there are screw ups, especially in large IT projects, and these are generally blamed on incompetent officials and greedy consulting firms and so on.

Although undoubtedly officials are incompetent and consultants are greedy, these projects are often crippled by the failure of industry to recognise that some of the core problems of systems design are an unsolved problem. Concurrency is one of the major areas where they fall down. Building an IT system to service a single person is straightforward. Rolling that same system out to service hundreds of thousands is not.

It may seem odd to people outside the world of software, but concurrency (“doing several things at once”) is still one of the hot topics in software architecture and language design. Not only is it not a solved problem, there’s still a lot of disagreement on what the problem even is.

Here’s a typical scenario in IT systems rollout. Every experienced engineer will have been involved in this. A project where it seemed to be going ok, the software was substantially complete and people were talking about live dates. So the developers chuck it over the wall to the systems guys, so they can run some tests to work out how much hardware they’ll need.

And the answer comes back something like “we’re going to need one server per user” or “it falls over with four simultaneous users”. And I can tell you, if you get that far and discover this, the best option is to flee. Run for the hills and don’t look back.

Two worlds

There has always been a distinction between the worlds of academia and industry. Academics frame problems in levels of theoretical purity, and then address them in the abstract. Industry is there to solve immediate problems on the ground, using the tools that are available.

Academics have come up with a thousand ways to address concurrency, and a lot of these were dreamt up in the early days of computing. All the things I’m going to talk about here were substantially understood in the eighties. But these days it takes twenty years for something to make it from academia to something industry can use, and that time lag is increasing.

Industry only really cares about it’s tooling. The fact that academics have dreamt up some magic language that does really cool stuff is of no interest if there isn’t an ecosystem big enough to use. That ecosystem needs trained developers, books, training courses, compilers, interpreters, debuggers, profilers and of course huge systems libraries to support all the random crap every project needs (oh, it’s just like the last project except we need to write iCalendar files and access a remote MIDI music device). It also needs actual physical “tin” on which to run the code, and the characteristics of the tin make a lot of difference.

Toy academic languages are no use, as far as most of industry is concerned, for solving their problems. If you can’t go and get five hundred contractors with it on their CV, then you’re stuck.

The multicore bombshell

So, all industry has these days, really, is C++ and Java. C++ is still very widely used, but Java is gaining ground rapidly, and one of the reasons for this is it’s support for concurrency. I’ll quote Steve Yegge:

But it’s interesting because C++ is obviously faster for, you know, the short-running [programs], but Java cheated very recently. With multicore! This is actually becoming a huge thorn in the side of all the C++ programmers, including my colleagues at Google, who’ve written vast amounts of C++ code that doesn’t take advantage of multicore. And so the extent to which the cores, you know, the processors become parallel, C++ is gonna fall behind.

But for now, Java programs are getting amazing throughput because they can parallelize and they can take advantage of it. They cheated! Right? But threads aside, the JVM has gotten really really fast, and at Google it’s now widely admitted on the Java side that Java’s just as fast as C++.

His point here is vitally important. The reason Java is gaining is not an abstract language reason, it’s because of a change in the architecture of computers. Most new computers these days are multicore. They have more than one CPU on the processor die. Java has fundamental support for threading, which is one approach to concurrency, and so some programs can take advantage of the extra cores. On a quad-core machine, with the right program, Java will run four times faster than C++. A win, right?

Well here’s a comment from the master himself, Don Knuth:

I might as well flame a bit about my personal unhappiness with the current trend toward multicore architecture. To me, it looks more or less like the hardware designers have run out of ideas, and that they’re trying to pass the blame for the future demise of Moore’s Law to the software writers by giving us machines that work faster only on a few key benchmarks! I won’t be surprised at all if the whole multithreading idea turns out to be a flop, worse than the “Itanium” approach that was supposed to be so terrific—until it turned out that the wished-for compilers were basically impossible to write.

Let me put it this way: During the past 50 years, I’ve written well over a thousand programs, many of which have substantial size. I can’t think of even five of those programs that would have been enhanced noticeably by parallelism or multithreading. Surely, for example, multiple processors are no help to TeX….

I know that important applications for parallelism exist—rendering graphics, breaking codes, scanning images, simulating physical and biological processes, etc. But all these applications require dedicated code and special-purpose techniques, which will need to be changed substantially every few years. (via Ted Tso)

Hardware designers are threatening to increase the numbers of cores massively. Right now you get two, four maybe eight core systems. But soon maybe hundreds of cores. This is important.

The problems with threading

Until recently, if you’d said to pretty much any developer that concurrency was an unsolved problem, they’d look at you like you were insane. Threading was the answer - everyone knew that. It’s supported in all kernels in all major Operating Systems. Any serious software used threads widely to handle all sorts of concurrency, and hey it was easy - Java, for example, provides primitives in the language itself to manage synchronisation and all the other stuff you need.

But then some people started realising that it wasn’t quite so good as it seemed. Steve Yegge again:

I do know that I did write a half a million lines of Java code for this game, this multi-threaded game I wrote. And a lot of weird stuff would happen. You’d get NullPointerExceptions in situations where, you know, you thought you had gone through and done a more or less rigorous proof that it shouldn’t have happened, right?

And so you throw in an “if null”, right? And I’ve got “if null”s all over. I’ve got error recovery threaded through this half-million line code base. It’s contributing to the half million lines, I tell ya. But it’s a very robust system.

You can actually engineer these things, as long as you engineer them with the certain knowledge that you’re using threads wrong, and they’re going to bite you. And even if you’re using them right, the implementation probably got it wrong somewhere.

It’s really scary, man. I don’t… I can’t talk about it anymore. I’ll start crying.

This is a pretty typical experience of anyone who has coded something serious with threads. Weird stuff happens. You get deadlocks and breakage and just utterly confusing random stuff.

And you know, all those times your Windows system just goes weird, and stuff hangs and crashes and all sorts. I’m willing to bet a good proportion of those are due to errors in threading.

In reality threads are hard. It’s sort of accepted wisdom these days (at least amongst some of the community) that threads are actually too hard. Too hard for most programmers anyhow.

Python

We’re Python coders, so Python is obviously of particular interest to us. We also write concurrent systems. Python’s creator (Guido van Rossem) took an approach to threading, which has become pretty standard in most modern “dynamic” languages. Rather than ensure the whole Python core is “thread-safe” he introduced a Global Interpreter Lock. This means that in practice when one thread is doing something it’s often impossible for the interpreter to context switch to other threads, because the whole interpreter is locked.

It certainly means threads in Python are massively less useful than they are in, say, Java. For a lot of people this has doomed Python - “what no threads!?” they cry, and then move on. Which is a shame, because threads are not the only answer, and as I’ve said I don’t even think they are a good answer.

Enter Twisted. Twisted is single-threaded, so it avoids all of the problems of threads. Concurrency is handled cooperatively, with separate subsytems within your program yielding control, either voluntarily or when they would block (i.e. when they are waiting for input).

This model fits a large proportion of programming problems very effectively, and it’s much more efficient than threads. So how does this handle multicore? Pretty effectively right now. We design our software in such a way that core parts can be run separately and scaled by adding more of them (“horizontal” scaling in the parlance). Our soon-to-be-released CMS, Exotypes, works this way, using multiple processes to exploit multiple cores.

This is a really effective approach. We can run say six processes, load balance between them and it takes great advantage of the hardware. Because we’ve designed it to work this way, we can even scale across multiple physical computers, giving us a lot of potential scale.

But what of machines of the future? Over a hundred cores, run a hundred processes? Over a thousand? At large numbers of cores the multi-process model breaks down too. In fact I don’t think any commonly deployed OS will handle this sort of hardware well at all, except for specialised applications. This is where I think Twisted falls down, through no fault of it’s own. I just suspect, like Don Knuth, that the hardware environment of the future is one that’s going to be extremely challenging for us to work in.

Two worlds, reprise

Of course, these issues have been addressed in academia, and I think, to finally answer Duncan’s question, that the long term solution to concurrency has to be addressed as part of the language. The only architecture that I think will handle it is the sort of thing represented in Erlang - lightweight processes that share no state.

Erlang addresses the challenge of multicore computer fantastically well, but as a language for writing real programs it suffers some huge lacks. I don’t think it’s Erlang that’s going to win, but it’s going to be a language with many of it’s features.

First, Erlang is purely functional, with no object-oriented structures. Pretty much every coder in the world has been trained, and is familiar with, the OO paradigm. For a language to gain traction it’s going to need to support this. This is quite compatible with Erlang’s concurrency model, and shouldn’t be too hard to support.

It also needs a decent library. Right now, the Erlang library ecosystem is, well, sparse.

Finally it needs wide adoption.

So, gods of the machines, I want something that’s got OCaml’s functional OO, Erlang’s concurrency and distribution, Python’s syntax and Python’s standard library. And I want you to bribe people to use it.

If you can do all this, not only will we be able to support multicore, but we might also, finally, be able to actually build a large IT system that actually works.

Link | Leave a comment | Add to Memories | Tell a Friend