Archives for: October 2006

10/29/06

Permalink 08:41:43 am, Categories: Linux, 44 words   English (US)

seq

I can't believe in all my syadmin I've never used 'seq'. Pretty cool for bash for loops:

m=`seq -f "host%02g" 1 20`
echo $m
host01 host02 host03 host04 host05 host06 host07 host08
host09 host10 host11 host12 host13 host14 host15 host16
host17 host18 host19 host20

10/28/06

Permalink 10:14:03 pm, Categories: Science, 28 words   English (US)

Brains and electrodes

I find this is both scary and fascinating. The fact that we can create something using brain cells and robotics that follow light seems like an amazing feat.

10/25/06

Permalink 07:29:25 am, Categories: Python, 175 words   English (US)

dictionary fun

Learned some new things about Python dictionaries. Let's say you wanted to create a dictionary with keys given in a list, and a default value for all of them, say None.

>>> somelist=['foo', 'bar', 'baz']
>>> {}.fromkeys(somelist)
{'baz': None, 'foo': None, 'bar': None}

Or some other value, like True:

>>> {}.fromkeys(somelist, True)
{'baz': True, 'foo': True, 'bar': True}

An uglier way to do this is with a list comprehension:

>>> dict([(x, True) for x in somelist])
{'baz': True, 'foo': True, 'bar': True}

Now you can easily see a way to uniq-ize a list:

>>> somelist=['foo', 'bar', 'foo']
>>> {}.fromkeys(somelist).keys()
['foo', 'bar']

But really, there is an even better way to uniq-ize a list in 2.4:

>>> list(set(somelist))
['foo', 'bar']

On another note, let's say I wanted to loop through the keys of a dict in sorted order in Python 2.4:

>>> somelist=['foo', 'bar', 'baz']
>>> somedict={}.fromkeys(somelist)
>>> for key in sorted(somedict):
...   print key
... 
bar
baz
foo

Or, did you know you can create a dict with x=y arguments?

>>> dict(x=1,y=2)
{'y': 2, 'x': 1}

10/22/06

Permalink 08:45:35 pm, Categories: Books, 457 words   English (US)

Static

Some quotes from a good book I just read called Static:

"It's not about embedding. It's about television's refusal to show the truth of war. Many of the worst pictures taken in the invasion of Iraq in 2004 ... never saw the light of day. They couldn't be shown. They could - but they were not: 'Because of sensitivities.' 'Mustn't show this at breakfast time.' 'It's irresponsible to show the dead like this.' 'It's disrespectful.'

"If you saw what I saw when I go to wars when I'm on the front line - with or without soldiers or with civilians or the wounded in hospitals - you would never, ever dream of supporting a war again. Ever in your life. It's a remarkable thing that in the commercial cinema, feature films can now show the bloodiest, goriest themes which are quite similar to what we see in real life - Saving Private Ryan - the guts spilling out. And yet real war cannot be shown without censoring pictures which in many cases are exactly the same as what you see when you go to the cinema.

"If you go to war, you realize it is not primarily about victory or defeat. It is about death and the infliction of death and suffering on as large a scale as you can make it. It is about the total failure of the human spirit. We don't show that because we don't want to. And in this sense, journalists, television reporting, television cameras are lethal. They collude with governments to allow you to have more wars. Because if they showed you the truth, you wouldn't allow any more wars," [Robert Fisk] said.

"I know I'm very soft-spoken. But I have endeavored to live my life by my terms. And that means that I am a renegade. An outlaw. A pagan."

Alice [Walker] continued, "There is no reason not to rebel. I learned that really early.... Rebellion, any way you can manage it, is very healthy. Because unless you want to be a clone of somebody that you don't even like, you have to really wake up. I mean, we all do. We have to wake up. We have to refuse to be a clone."

...

Be nobody's darling;
Be an outcast.
Take the contradictions
Of your life
And wrap around
You like a shawl,
To parry stones
To keep you warm.

Watch the people succumb
To madness
With ample cheer;
Let them look askance at you
And you askance reply.

Be an outcast;
Be pleased to walk alone
(Uncool)
Or line the crowded
River beds
With other impetuous
Fools.

Make a merry gathering
On the bank
Where thousands perished
For brave hurt words
They said.

But be nobody's darling;
Be an outcast
Qualified to live
Among your dead.

Permalink 08:30:19 pm, Categories: Fun, 96 words   English (US)

The Yes Men

I had posted in the past about The Yes Men, probably the most unique activism I've ever seen.

Well, I found the movie on Google Video. Check it out before it gets taken down.

For some highlights, skip to about 38:00 minutes into the film, where they demonstrate the 'Management Leisuresuit'. Some funny CGI :).

And the grand finale at about 1:00:00 (1 hour) into the film, the McDonald's sewage system. "The #1, #2, #3, #4, #5 would no longer refer to combinations of food, but rather just the number of times the product has been recycled." Pure genius.



I think you get the picture :).

Permalink 02:32:35 pm, Categories: Python, 112 words   English (US)

reversing a list

I've always found the reverse() method of a list rather wierd because it reverses the list in place. I just found out about reversing via slicing:

>>> f=['foo', 'bar', 'baz']
>>> f[::-1]
['baz', 'bar', 'foo']
>>> f='hello'
>>> f[::-1]
'olleh'

There is also a new builtin function in 2.4 called reversed(), which returns an iterator, and is more efficient for large lists:

>>> f=['foo', 'bar', 'baz']
>>> for x in reversed(f):
...   print x
... 
baz
bar
foo

And yet another (ugly) method shown to me by a coworker:

>>> f=['foo', 'bar', 'baz']
>>> reduce(lambda x,y: [y] + ((type(x) == type([]))
...        and x or [x]), f)
['baz', 'bar', 'foo']

Hmm, Python seems to be moving towards TMTOWTDI.

10/21/06

Permalink 06:10:00 pm, Categories: Fun, 2 words   English (US)

Indian teacher survey

Funny stuff.

Permalink 04:14:57 pm, Categories: Books, Python, 123 words   English (US)

enumerate

I'm reading Core Python Programming 2nd Ed. I sometimes like reading the basic intro chapters even though I have a bit of familiarity with Python. There is always something that I may have missed, and each author has a different writing style which is entertaining to read.

I just found out about the enumerate() builtin. How many times have you done this?

>>> f=['foo', 'bar', 'baz']
>>> for i in range(len(f)):
...   print f[i]
... 
foo
bar
baz

Well you can use enumerate() to have both the index and the value:

>>> f=['foo','bar','baz']
>>> for i, val in enumerate(f):
...   print i, val
... 
0 foo
1 bar
2 baz

Cleaner and no array indexing needed. Oh and how about the Zen of Python?

>>> import this

10/19/06

Permalink 10:29:44 pm, Categories: Society, 583 words   English (US)

Seymour Hersh talk

I attended a talk by Seymour Hersh tonight at Stanford and it was very good, but also very depressing. He is a Pulitzer winner who reported on the My Lai massacre in Vietnam and its coverup, and then did much of the reporting on Abu Ghraib. He was given firsthand pictures and videos of what went on in the prison by soldiers who came back from Iraq, many of which the news media he worked for refused to print. He described the video of one of the pictures that was released, where an Iraqi was naked with his hands behind his head outside of his cell, blindfolded, and a dog barking. He goes on to say that during the video the man was refused to cover his genitalia, and the dog ordered to bite him there. There was blood everywhere the whole thing was on video.

He described that the things that we have been shown don't even begin to give a glimpse of what truly happened, that we have not even "begun to see the evil" of what went on there and still goes on in secret prisons. He described women being raped, and small children (boys) being sodomized by Iraqi guards on video. These are the things that the American media hides. He said that many women in prison send out letters to their families to kill them once they get out, because the shame is too great. It could even be simply fondling by the guards or seeing them naked. Their culture is just so different. Our American culture clashes so much with what Iraqi culture holds sacred, and this is why alot of the prison torture has to do with sexuality and humiliation.

Alot of what he said brought tears to my eyes because I just couldn't bear some of it. How can anyone do these things to other human beings? One thing he mentioned is that what's coming out now is many American soldiers are coming back mentally ill, schizophrenic, or severely depressed. I think it is natural to be affected if you are forced to treat other people in such demeaning ways. Hell, that even gives some hope that these soldiers deeply feel they've done wrong.

I don't understand the goal. It's like we as people crave violence. My mom used to say the bad things you do become part of your karma and you will have to repay the debt eventually, perhaps even in another lifetime. Hersh was saying that the Iraqis have no trouble postponing revenge until many, many generations later. When I think about these things, it's only common sense that this will come back to us. They won't simply be forgotten. And when it happens, can we really blame them? Imagine if these things were done to Americans instead, how would America react?

I feel very bad that no one was there to stand up for the people being tortured. It's like when someone describes it I imagine I'm there in the cell with them, and guilty for not stopping it. They are people just like you and me, not animals. I think that until we can see all other human beings as if they were our own family, we'll always have violence. Evolution basically says we are all one family descended from a common ancestor, so it's not even religion that should bring people together. I wish that people could move beyond all of this and learn to live without violence someday.

10/15/06

Permalink 09:27:03 pm, Categories: Movies, 26 words   English (US)

Videos 4 You

Just found Who Killed the Electric Car? on Google Video.

Also checkout some other documentaries at throwawayyourtv.com.

Oh, and how about some fine CNN censorship.

Viraj's Weblog

Donate to keep this site going!

Amount USD $

October 2006
Mon Tue Wed Thu Fri Sat Sun
<<  <   >  >>
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Search

Categories


Misc

Syndicate this blog XML

What is RSS?

powered by
b2evolution