Fixed width string formatting in python
by mikez0r on Feb.25, 2009, under Nerd, Uncategorized
I wanted to make a nice, pretty text file from some log info, but python didn’t want to cooperate with string formatting.
I was trying something like this:
f=open(‘file’,'w’)
f.write(‘%-10s’ %string)
At the interactive prompt, the equivalent print command would give the desired result.
I got it to work by replacing f.write() with
print >> f, mystring.ljust(10)
This code has the same net result of printing to the file, but it actually does the spacing properly.
This thread gave me the hint I needed, though it looks like the poor guy never resolved his issue – he should have tried the print suggestion.
http://bytes.com/groups/python/25205-using-string-ljust-try-hold-fixed-width#links
Abstinence failing???
by mikez0r on Jan.13, 2009, under Uncategorized
From today’s school newspaper, an article that made me laugh quite a lot:
A recent study conducted by Janet Elise Rosenbaum yet again compares the sexual behavior between teens who take abstinence pledges and teens who don’t. She found that after five years of taking the pledge, 82 percent of the virginity pledgers deny having ever pledged and ultimately, there was no difference between the two groups in terms of sexual activity or sexually transmitted diseases. However, pledgers were less likely to use contraceptives, such as condoms, and Rosenbaum writes this may be because many abstinence-only programs disparage the effectiveness of contraceptives.
(Article by Helen Zou, available here )
I laughed a lot because I really hate faith-based initiatives, and to see them failing so miserably (indeed, being arguably counterproductive and potentially harmful) brings great joy to my twisted, cold, black heart. I hate them because they are pure nonsense initiated by people with likely good intentions, but absolutely absurd, borderline megalomaniacal obsessions with controlling thought. Of course the easiest targets for such thought control are young people, with the enormous potential for peer pressure in youth-oriented groups. To strive for prevention of disease and unwanted pregnancies is a noble goal, but to try to do so by fighting human nature is folly. I am delighted to see nature prove it as such.
Milk
by mikez0r on Jan.01, 2009, under Uncategorized
If you haven’t already seen this, you really should watch it. It’s a 1985 documentary on Harvey Milk, the subject of the recent Sean Penn movie.
http://www.hulu.com/watch/49577/the-times-of-harvey-milk
It’s worth watching because Harvey Milk exemplified the kind of person that we desperately need – right now and always. He was gentle and compassionate, yet fiery and determined in his push for human rights. I have been forced throughout my life to learn about Christianity at various religious schools and from growing up Catholic. This man, more than anyone in the political history of the United States that I know of, truly exemplifies what it means to be a Christian politician (even though he was Jewish): accepting of others, peaceful, selfless, and relentless in his pursuit of human equality. I only mention Christianity because of the current political skew in that direction. It is irrelevant in understanding Milk’s life, but does provide a widely acknowledged standard of excellence, a standard through which Milk can be evaluated to be a truly praiseworthy man.
The Sean Penn movie is also worth watching, but this documentary is better, in my opinion. It covers the events after the assassination in much greater detail. If you do go to see the Sean Penn movie, please avoid Cinemark theaters, as the owner of that chain donated the maximum personal contribution to the Yes on Prop 8 campaign, and should not be profiting from the memory of such a great leader of the gay community.
Conservative Lesbianism?
by mikez0r on Jan.01, 2009, under Uncategorized
I spent my New Year’s Eve Contra dancing in Sacramento. At some point, I realized that I was being followed/stalked by a woman. She first stood near me, and talked into space at no one in particular, I suppose hoping that I would listen and comment. Since I didn’t hear what she was saying, I paid no heed. Some time later, I got cornered near the snacks, coincidentally by the stack of progressive newspapers. She made sure to shout this time, though no more in my direction than before. I ignored her a couple of times, and started looking at the headlines of the newspapers. She shouted something about gun control. I finally realized she was trying to talk to me. See, I had suspected as much before, but I’m not used to people talking to me. Once she had my attention, she announced her status as a conservative lesbian. I thought it was rather oxymoronic. When I said as much, she said “What, have you been going to college? Who tells you this stuff?” Hmmm… Prop 8, anyone? It’s not news that conservatism and homosexuality do not go hand in hand these days (or ever have). I asked her if she ever wanted equal civil rights to heterosexuals. The conversation went nowhere. Never mind that she’s been following me (a guy) around looking for a dance. I dismissed her as confused, and went on my merry way, talking to other people so that she’d leave me alone. She never got her dance.
Now that I’m home, I decided to search up this funny sounding term, “conservative lesbianism.” There are at least a few things out there, but recent headlines are intermingled with stuff at least as far back as 2001. Mostly it’s the idea that these lesbians adhere to conservatism in the true sense – minimal government, and certainly minimal government interference in personal life. Since when, though, has the conservative element in this country actually adhered to those ideals? Certainly not recently. Why on earth would any lesbian or gay person currently identify with a party that is actively working to deny them civil rights, and whose religious core condemns them as hell-bound? What’s more important to you – your guns, or your dignity?
These people must wake up and get their priorities straight. The Republican party has no respect for them, and the Republicans have clearly shown no intention of minimizing government’s monitoring and control of people’s decisions. Until there is true conservatism in government, without the interference of religion and corporate greed, any conservative gay person would do well to lose that identity and focus on preserving their rights as equals.
Ubuntu photo frame
by mikez0r on Dec.25, 2008, under Nerd
Digital picture frames are neat little gizmos – especially for showing pics to my parents, who are rarely, if ever, inclined to poke around flickr (or anything much beyond their email). I have had various setups for a while using an old laptop. At first, I used Windows, because the wifi drivers for Linux were either missing for my card, or inadequate (non-functional, or locked up computer frequently). I have finally gotten a card that agrees with Linux (the Intel 2200BG MiniPCI), and the computer is now up and running with Xubuntu. Many options are out there for picking particular sets, or photos by interestingness, but I wanted simply a way to download my whole photostream and allow a screensaver to meander the collection. Not all of my photos are interesting, but they have other personal value of interest to parents.
The synopsis of what I do:
- Use flickrfs to mount my photos on the drive
- rsync to copy photos from flickrfs to local drive
- cron to run photo update scripts nightly
To do this yourself,
- Get flickrfs – on Ubuntu/Xubuntu 8.04 and 8.10, this can be accomplished with
apt-get install flickrfs (sudo as necessary) - Make 2 folders – one to mount flickrfs to, and another to store your pictures locally. Make sure you have write access to both of them (obviously)
- Mount the flickrfs filesystem to the folder you created for it. This is as simple as the command
flickrfs /PATH/TO/YOUR/DESIRED/MOUNTPOINTAfter running that command, a web browser will open for you to authorize flickrfs to access your account. Eventually, the command line window will spit out something about updating your sets, and tell you when it’s done.
- You should now have 2 folders in your flickrfs mount point – sets and meta
- If you have the 2 folders, create a folder named “stream” in the flickrfs mountpoint. If you don’t have the 2 folders and you create the stream directory, fuse will complain about a non-empty directory. The flickrfs mount point must be empty until it (flickrfs) puts stuff there.
- Wait 5-10 minutes for flickrfs to populate the stream folder
- rsync to copy files from the flickrfs/stream/ folder to your local pictures folder.
If anyone finds it useful, here’s the script that I have cron run to update my local Pictures directory with the contents of my photostream. There’s also a bit in there to clean up empty files. rsync seems to be not quite perfect with flickrfs, and I accumulated a few empty jpg’s that confused the screensaver.
I display the pictures using GLslideshow, which is standard with xscreensaver. I replaced gnome-screensaver with xscreensaver, as configuration of xscreensaver is easier. To ensure that xscreensaver is always reading a fresh set of photos, I kill it and restart it nightly (cron is really useful!). I did have to tell XFCE to start xscreensaver at startup – it isn’t a completely automatic drop-in replacement for gnome-screensaver. To point xscreensaver at your local pictures directory, check the advanced tab in the upper right, and change the folder where it looks for pictures.
Side note: The Perl installation for Ubuntu 8.10 has a bug with xscreensaver. It dumps yellow text onscreen, something about a constant being changed. I fixed this by adding a debian sid repository to my third party software, and using the Perl version from there, since it’s more up to date. It fixed the yellow text problem for me. The older this post gets, the less likely this will be an issue for you – I imagine the Ubuntu people will update this soon.
Why on earth…
by mikez0r on Nov.01, 2008, under Uncategorized
do people find it necessary to forcefully and loudly inform me that I look like a retard/nerd while riding my bicycle? Honestly, there are better things to shout out your car window or from the driveway of your frat house – even if I really do look like a retarded nerd (which I doubt).
Love and Exclusivity
by mikez0r on Oct.05, 2008, under Needlessly Cerebral, Philosophical musings
“What is our love? In the midst of pain and pleasure, we know it is exclusive, personal: my wife, my children, my country, my God. We know it as a flame in the midst of smoke, we know it through jealousy, we know it through domination, we know it through posession, we know it through loss when the other is gone. So we know love as a sensation, do we not? When we say we love, we know jealous, we know fear, we know anxiety. When you say you love someone, all that is implied: envy, the desire to posess, the desire to own, to dominate, the fear of loss, and so on. All this we call love, and we do not know love without fear, without envy, without posession; we merely verbalize that state of love which is without fear; we call it impersonal, pure, divine or God knows what else, but the fact is that we are jealous, we are dominating, possessive. We shall know that state of love only when jealousy, envy, possessiveness, domination, come to an end; and as long as we possess, we shall never love.”
A passage from On Love and Loneliness, a compilation of some of J. Krishnamurti’s talks on the topic.
It’s easy enough to say, but more difficult to truly embrace. I have been thinking a fair bit about “open” relationships lately. I’m a pretty simple, honestly closed-minded person when it comes to dating. I think it has caused a lot of problems for me, for exactly the reasons K describes. I don’t fully understand a difference between open relationships and polyamory. This idea of posession as a component of relationship is a source of great conflict. It’s a necessary component for easing fear of loss, though – for a general feeling of safety. That’s a hard thing to let go of. I see a lot of value in getting rid of the idea of posession, but I also have a really hard time getting rid of the idea of committing to one person. Can committing be independent of posession? Is committing only another way of seeking the same security?
It goes without saying that I am overthinking this, but why not?
” So we have made of love a thing of the mind. The mind becomes the instrument of love, and the mind is only sensation. Thought is the reaction of memory to sensation. Without the symbol, the word, the image, there is no memory, there is no thought. We know the sensation of so-called love, and we cling to that, and when it fails we want some other expression of that same sensation. So the more we cultivate sensation, the more we cultivate so-called knowledge – which is merely memory – the less there is of love.
As long as we are seeking love, there must be a self-enclosing process. Love implies vulnerability, love implies communion, and there can be no communion, no vulnerability, as long as there is the self-enclosing process of thought. The very process of thought is fear, and how can there be communion with another when there is fear, when we use thought as a means for further stimulation?
There can be love only when you understand the whole process of the mind. Love is not of the mind, and you cannot think about love. When you say, ‘I want love’, you are thinking about it, you are longing for it, which is a sensation, a means to an end. Therefore it is not love that you want, but stimulation; you want a means through which you can fulfill yourself, whether it be a person, a job, or a particular excitement, and so on. Surely, that is not love … Love is a state of being, and in that state, the ‘me’, with its identifications, anxieties, and possessions, is absent.”
Sue’s long lost factory-line buddy
by mikez0r on Sep.29, 2008, under Nerd
Check this out!! I found Sue’s long lost buddy/brother/sister!!
Sue is the better looking bike, obviously… =)
No? Well, fine… She’s the bike with more cool stuff on her. The one that’s obviously loved more.
Math everywhere
by mikez0r on Aug.10, 2008, under Nerd
This is what studying too much math will do to you:
I analyzed the Chinese zodiac while eating out last night. Any of the recommendations that it tells you to avoid marrying are based on 6-year intervals. Strangely, the boar doesn’t follow this pattern. The boar is advised to be wary of itself, rather than its 6-year offset counterpart. Any of the recommendations of who to marry are based on 4-year offsets, which led me to draw a parallel between the zodiac and the photographer’s rule of thirds. For those not familiar with it, it says that most aesthetically pleasing photos can be composed by putting the subject of interest at a position 1/3 into the frame from any given side.
Lately I’ve also been pondering my move out of my apartment, and I’ve come to recognize that moves often are well described by logarithmic functions, with work being the independent variable (the x axis) and progress being the dependent variable (y axis) – your progress starts out very fast for a given amount of work, but pretty quickly degrades until it feels like no matter how much work you do, your overall completion changes little. I think everyone feels this way, but how many people fit functions to their feelings?
Yikes.
Open ideas & progress
by mikez0r on Aug.07, 2008, under Nerd, Philosophical musings
I’ve been at a conference in New Mexico since last Tuesday, and I’ve had lots of interesting encounters and discussions. One today was really frustrating though, so I’m writing about it. I met a seemingly brilliant man who has come up with a new way to reconstruct 3D models from 2D projections. He does it very quickly and with fewer projections than I thought possible, and with very good results. He asked me what I was doing, after I gave him some details on GPU programming. I don’t really have a well-defined plan yet, but I think I’d like to make it easier and more accessible for anyone to do these 3D reconstructions. There are a number of programs, but most of them are variously counterintuitive, incomplete, poorly documented, buggy, etc. I would like to create a framework for doing the image processing and reconstruction, and do it in such a modular way that it would be easy for anyone else to add to it in the future. The best (non-commercial) program that I know of is IMOD, but it is not modular this way.
Well, this guy has developed a fairly complete package for all the steps of reconstruction, but he’s keeping it under wraps. The way that he wants it to work is for people to send him data (2D images), and he’ll reply with their 3D model. That’s a black box. I hate black boxes. They can’t be trusted, especially in science. If you don’t know how someone is doing something, then their result can’t be trusted. I don’t care how good it looks or how well it matches with the 2D data. Open Source software is the obvious opposite of this, but I don’t think that everything has to be open source. It should, however, be completely clear what a program is doing, to ensure that it is scientifically valid. He did present a poster, and he vaguely details his methodology, but he intends to keep the detailed workings secret.
On the other hand, if everything was open source, I’m convinced that progress would be much faster. There would be so much less duplication of work. America’s economic model is obviously not compatible with everyone working together, and I don’t know of any other economy that would be totally compatible. It is a pipe dream, but it sounds nice. In this particular example, if everyone would work together, rather than 15 different labs all creating their own software, then perhaps one or two truly high-quality software packages could have been developed by now. I don’t pretend to know how you’d split up funding or even put in a proposal for that sort of thing, but it seems like a more logical solution to a problem that we all face, and a problem that is far more general than 3D reconstruction software. Linux has proven a lot of things possible, and we’ll see over the course of the next 10-20 years if my ideas of open development speeding beyond closed source actually come true.
