I watched US President Obama's press conference live this evening and was once again impressed by his sensible, measured words, as well as by how he was keeping command of the room of journalists, who at times would pose rather snarky questions. Here is the video of the whole thing, and here a reasonable summary (in refreshing contrast to the typical repuglican raving madness that I couldn't entirely avoid while searching for a replay for you). Given enough time, I could go on and on... let me just say this:
I agreed with a great lot of his points (including, one of the main topics, his treading very carefully concerning Iran and only applying fierceness when and where appropriate);
I cannot stop being so happy to see an intelligent, thinking, witty and balanced person in this powerful position, and wish we could have more of his kind in politics internationally.
Oh hear ye mortals who pass through this barren land . . . I'm still alive and kicking, and after half a year ready to fill up the blog with a little bit more content.
In this post and probably the next few I will give the computer geek inside myself free reign and delve into programming lore — which may seem utterly boring and/or incomprehensible to you if you aren't very technically minded. If the description applies to you, take my apologies, just be warned and steer clear of posts with "[geek alert]" in the title. Everything has got its time and place: rest assured that I'll write about other stuff as well.
So, with that out of the way — over to you, geek!
I haven't got any one message or motivation for this post, but rather thought I'd just share some of the fun stuff I have learned lately concerning programming. To cite Tom Lehrer: This may prove useful, some day, to some of you, under a somewhat bizarre set of circumstances . . .
Let me start by mentioning, as a background, several programming languages that I have come to appreciate through the years and use extensively today:
Pascal, which I first learned in highschool, is still my compiled language of choice (nowadays in the form of the excellent FreePascal 2, which includes powerful object-oriented programming, GUI capabilities and basically everything one would expect of a modern programming language).
Scripts of the bash shell with related utilities are a great tool for all kinds of computer "chores" like finding, batch altering and sorting files. I don't use it for major projects, but it's part of Linux' attraction on me and no Windows computer I regularly work on stays without an installation of bash and its ilk from the Cygwin suite for long.
Matlab is what I nowadays do 99.9% of my scientific computer work on — calculations, data processing, statistics and plotting. I'll probably spend another post on it one of these days.
I started learning PHP through participation in a nice web-based bibliography project, Aigaion. As we were discussing the transition to an all-new version 2 about two years ago, we got to know the concept of MVC (model-view-controller) frameworks and after a while decided for the simple-yet-powerful framework CodeIgniter (aka CI).
We liked that CI implemented the MVC concept quite flexibly, not forcing a strict "architecture" upon the application programmer as some others did. The only thing one positively needs in CI is a "Controller" class for each category or "sub-application" (say, "blog") with an entry function for each action (e.g. "write", "index", "delete"). That is the core of your program. Beyond that, it is your free choice whether to use a "Model" class for talking to the database (provided that your app uses one) or if you call the DB from your controller. Likewise, while I think that a "View" component (typically an HTML page with just some embedded PHP for including the dynamically generated data) is a very good idea, you are by no means forced to use one.
Then, CI includes lots of libraries and "Helper" components to make it easy to program many common functions, among others components for communicating with databases — with an optional "Active Record" interface —, for internationalisation, also one working transparently in the background and "sanitising" input from the web so that the application is reasonably immune to common security risks like SQL-code injection.
As to databases, some people swear by Active Record patterns, some hate it and want to write their own SQL code... I for one appreciate it because I like to keep code in one language rather free of strings in secondary languages and also for instance because the commands for inserting data simply take associative arrays of data, without me having to loop through the fields and build a lengthy query string myself. Yeah, talk about comfort!
As cool as CI is, I started wondering a few weeks ago if it would be feasible to take it from its use for web applications, and use it in non-web programs/scripts (so that I for instance could continue using the database library). It is clearly written for the former, as it uses the web address to determine what command to run (e.g. http://your.site.com/blog/index calls function index in the Blog controller). But after some googling, I found a very nice solution: The web-address part used by CI is usually found in $_SERVER['REQUEST_URI'] — so as long as you put something of the form "controller/method" into that variable, you're good! Command-line parameters are found in PHP's $argv array (with $argv[0] being the name of the script); you can for instance assign the content of $argv[1] to the REQUEST_URI field, or generate some valid string inside your PHP file depending on different command-line parameters.
Which brings me to my next finding: parsing of the command line. From earlier bash days, I knew "getopts" to work down optional-parameter lists. It works, though not extremely flexibly, and PHP's equivalent "getopt" is even more limited . . . Then I started looking at PEAR, the PHP Extension and Application Repository, and there found the Console_CommandLine package, which allows you to define really powerful sets of command-line options and even automatically builds a help page listing all your options and parameters!
A little while later I wanted to execute an operation (creating a plot of the state of a running process in the lab) about every 30th second, i.e. more often than cron allows. The plotting is currently done upon user request within a PHP/CI web app (using Ploticus), but takes so much time that I'd like the graphs to be prepared in the background. With cron out of the question, a continually looping script is the natural alternative coming to mind — but I wouldn't want to start it by hand and have it rely on some terminal staying open all the time. Is it possible to run a PHP script as a daemon (roughly "service" in Windows parlance)? It turns out, yes, also that is quitepossible!
Last but not least, I wanted to be able to have mathematical transformations saved as strings e.g. in a config file or database and have PHP interpret the formulas on the fly. For kicks I chose not to rely on PHP's eval() but to write my own parser. Parsing infix notation (such as 3+4*2) and interpreting it right away quickly proves to be fiendishly difficult, what with parantheses, the different operator precedences (* and / overrule + and -, etc) and operator associativity (+,-,*,/ are left associative, i.e. 2*3*4 = (2*3)*4, while the exponent ^ is right associative: 2^3^4 = 2^(3^4)). You and the program have to keep track of a lot . . . Then I remembered having heard about RPN (Reverse Polish Notation) in university, a postfix notation (3+4*2 would translate to 3 4 + 2 *, for instance) which circumvents the complexity of infix interpretation and makes do without any brackets at all, and thankfully the wise Wikipedia yielded a very good description of an algorithm for converting infix into postfix, by none less than Edsger Dijkstra, an influential early computer scientist (whose algorithm for calculating the shortest way I also had implemented once upon a time during my studies). Implementing that Shunting-yard algorithm and the RPN calculator was fun and went surprisingly smoothly, so in the end I added several (backward-compatible) bonus functionalities to my code:
Variable data: Give the RPN an associative array with numeric data as a second argument and you can digest that data within the calculation.
Unary minus: All standard RPN operators are binary, so to get -1, as far as I know, you would have to write 0 1 -. So in my RPN calculator I added the unary minus (negation) operator "~", and the infix-to-RPN converter detects lonely minuses in the beginning of the expression, after opening parentheses as well as in function arguments (like in "min(0, -1)").
Variable number of function arguments: The original conversion algorithm already recognised functions like "sin(a)" or "min(2,3)", but there was no way of telling the RPN calculator how many to expect. For standard functions like sin, cos, sqrt etc. that would be a known 1 and no problem, but I'd like to allow syntax like "min(a,b,c)" or "min(a)" (with an array). The code supports that now; in RPN, that looks like, for instance, "a b c {3} min".
Array calculations: Since I work a lot with numbers in arrays (measurement data), I had already developed functions for various operations on arrays, and the mathematical ones I now have the parsers understand, in Matlab's notation with a dot prepended to the respective operator: .+ .- .* ./ and .^ (power, ^ for non-array power is also understood).
Auf der aktuellen Messe Intersolar in München stellt SANYO doppelseitige Silizium-Solarmodule vor. Der Wirkungsgrad bei Bestrahlung von hinten beträgt offenbar ca 2/3 dessen, der bei "normaler" Bestrahlung gilt. Die Idee ist, die Module gewinkelt auf einer hell gestrichenen Fläche, z.B. einem Flachdach aufzustellen, so dass Umgebungslicht auf die Rückseite gestreut wird, und SANYO sagt, dass die Ausbeute dann 20-30% höher liege als bei konventionellen einseitgen Modulen. Ab Oktober 09 soll es die Module in Europa zu kaufen geben. Klingt nach einem interessanten Ansatz. Ich erinnere mich, dass jemand auf der EUPVSEC-Konferenz 2005 doppelseitige CIGS-Solarzellen vorstellte. Das klang damals ein wenig lächerlich, weil er m.E. eine Milchmädchenrechnung machte: "14% von vorne plus 6% von hinten: Schwupps, schon haben wir eine 20%-CIGS-Solarzelle!" Aber so argumentiert wie von SANYO ergibt das mehr Sinn.P
As you may know at least since my September post, I am often a procrastinator nowadays, and not too happy about it. The cause of that has largely been a mystery for me. I would take umbrage at anyone suggesting it was because of plain laziness — after all, as (I think) most human beings, I like being productive and useful and making a difference, and there are areas in my life (music for instance) where I do not procrastinate at all as a rule.
EnterThe Now Habit by Neil Fiore, which I came across by way of an MP3-music and audiobook web shop the other day. According to its subtitle, it's "A Strategic Program for Overcoming Procrastination and Enjoying Guilt-Free Play" and it seems to be just the thing I need. There is a summary with a very good, comprehensive mindmap on Litemind, and another good review on Life Optimizer.
I've been listening to about half the book so far and I'm about to read the book, which I've also bought. Apart from some parts being a bit long-winded (in the verbatim interpretation of "tell them what you're gonna tell them, tell them, tell them what you've told them" frequently encountered in American articles and books), I appreciate it very much. Thanks to Fiore's description, I've found myself able to recognise much of my procrastination as a response to anxiousness caused by my perfectionism. I've been aware of the latter for a very long time, but had not really drawn this very important connection between the two phenomena yet. Very helpful indeed. I'm starting to profit from the book also on the part of handling the issue. The two key ideas that are most present in my mind for now are these:
Stop worrying about the end of the project and how you don't know how to do everything needed on the way — start taking a little, perfectly managable step NOW (and so on).
Stop talking to yourself in terms of "I have to do this or that (although I don't want to)", that just fuels inner resentment against the task and causes procrastination of the second type (or the 1st in Fiore's order), which is "as an indirect way of resisting pressure from authorities" (the authority in this case being part of yourself). Consider the task and make a conscious choice, either wholeheartedly to commit to it — or not to tackle it and to bear the consequences. The words of Yoda in Star Wars come to mind: "Try not. Do, or do not — there is no try."
Finally, on a related website I found this saying, a wonderful antidote to my perfectionism:
"Anything worth doing is worth doing poorly at first."
Here is General Colin Powell's thoughtful endorsement of Barack Obama, which includes very pointed criticism of the Republican party and campaign.
The full NBC Meet The Press program (including more interview with Powell and background talk with political analysts) is available as a video and in transcript.
Ah, how I like the sound of a Repuglican smear-attack dog whining. Here, Obama spokesman Robert Gibbs gives the Republican TV channel FOX News' journalist Sean Hannity a healthy dose of the Republicans' own medicine: When Hannity tries the latest Right-wing guilt-by-association smear on Gibbs, Gibbs counters by attacking Hannity for giving air time to a well-known anti-Semite a few days earlier, driving Hannity into the defense. See or read for yourself:
...
SEAN HANNITY: Why would you sit on a board -- would you sit on a board with a guy who bombed the Pentagon [William Ayers] and wasn't sorry about it?
ROBERT GIBBS: He sat on a charitable board and a board that funded by a conservative Republican and a friend of Ronald Reagan.
HANNITY: Was that poor judgment?
GIBBS: That was Walter Annenberg.
HANNITY: I didn't ask you -- was that poor judgment on Obama's part?
GIBBS: I don't think that was poor judgment at all. I think what Barack Obama has done throughout his career is talk about the big issues that are important to him --
HANNITY: All right, you're giving me spin now. I'm asking you --
GIBBS: Okay -- let me ask you one question.
HANNITY: All right. You ask me a question.
GIBBS: Okay. Are you anti-Semitic?
HANNITY: Not at all.
GIBBS: Okay. On your show on Sunday --
HANNITY: Uh-huh --
GIBBS: You -- the show that is named after you, right? The show with -- the centerpiece of that show was a guy named Andy Martin -- right?
HANNITY: No -- I know you're reading your talking points regarding --
GIBBS: No, no --
HANNITY: When I interviewed -- hang on one second. Let me answer your question.
GIBBS: No, no. I don't have talking points --
HANNITY: When I interviewed Malik Shabazz; when I interviewed Al Sharpton --
GIBBS: Right.
HANNITY: When I interviewed all of these controversial figures -- you see on Fox, we actually interview people of all points of view, whether we agree or disagree.
GIBBS: So --
HANNITY: I -- the statement you're about to read --
GIBBS: Yeah, Andy Martin --
HANNITY: I -- I totally, completely --
GIBBS: Called a judge a crooked, slimy Jew, who has a history of lying and theiving -- comments (unintelligible) --
HANNITY: Here's my answer to you --
GIBBS: Martin went on to write that he understood better why -- better why the Holocaust took place, given that Jews [sic] survivors are operating as a wolf pack (unintelligible) --
HANNITY: Here's my answer to you. I find those comments despicable. But wait a minute --
GIBBS: You put him on your show!
HANNITY: We put Malik Shabazz on the show --
GIBBS: It's the Hannity -- it's the Hannity show!
HANNITY: I put Khalid Muhammad on my show. I put --
GIBSS: Why am I not to believe that you're anti-Semitic?
HANNITY: Let me -- here's the answer --
GIBBS: Why am I not to believe that everyone who works for the network is anti-Semitic --
HANNITY: Here's the -- here's the --
GIBBS: Because Sean Hannity gave a platform to a man who thinks -- who thinks Jews are slimy?
HANNITY: Mr. Gibbs -- Mr. Gibbs -- Mr. Gibbs -- I's a journalist who interviews people that I disagree with all of the time, that give their opinion. Fox has all points of view. We're allowing you on the program, and I do not agree with hardly anything that Obama says.
GIBBS: (Laughs) Well --
HANNITY: So let me answer -- no, no, no --
GIBBS: How can you give a platform to virulent anti-Semites --
HANNITY: Here's -- I will tell you this --
GIBBS: who can't even get a law license in Illinois?
HANNITY: That I -- I'll make a deal with you. If Barack Obama admits that what he did by sitting on a board with -- giving speeches with -- having Ayers -- going over to Ayers' house --
GIBBS: You'll admit you're anti-Semitic?
HANNITY: No, no. I'll admit to you that -- I will tell you that Barack Obama wants to be president. It's poor judgment. It is irresponsible --
GIBBS: (Laughs) Well --
HANNITY: And it's reckless to -- no, let me finish -- to be friends with a guy that bombed our Pentagon, was at war with our country, whose motto was to kill our children and kill your parents.
GIBBS: Well, I think it's deplorable that you had some on TV that's anti-Semitic --
HANNITY: And it's deplorable that your candidate for president has not been honest with the American people.
GIBBS: That calls Jews slimy, and understands the Holocaust better because of the way he views --
HANNITY: I'm explaining --
COLMES: (unintelligible) We have a short time here --
HANNITY: Let me finish first. Let me finish (to Alan Colmes). I'm explaining to you --
GIBBS: I can't believe you would give a platform --
HANNITY: So you do not want to want me to interview anybody I agree, dis[agree] -- I can only -- I can only interview people you disagree with?
GIBBS: You put the whole show around him, Sean!
HANNITY: Barack Obama --
GIBBS: You had to believe only that you agree with each and everything that Andy Martin says.
HANNITY: Listen -- Barack Obama, the president [sic] sat in the pew of Jeremiah Wright for 20 years, a guy who hates America.
GIBBS: I think -- I think you're changing the subject -- will you do me a favor?
HANNITY: Barack Obama -- Barack Obama is friends with William [sic] Pfleger --
GIBBS: Will you do me a favor?
HANNITY: I have one last question.
(Crosstalk)
HANNITY: Did Barack Obama ever sit and meet with Louis Farrakhan? Has he ever met with Louis Farrakhan?
GIBBS: I don't -- I don't know the answer to that.
HANNITY: Will you give us an answer by tomorrow?
GIBBS: Will you get back to me on whether you're anti-Semitic?
HANNITY: Ah, I'm not anti-Semitic. I am the biggest supporter of Israel.
COLMES: (unintelligible)
HANNITY: Benjamin Netanyahu blurbed my book.
GIBBS: Let me tell you -- I don't think -- I don't think your Jewish viewers are going to take it very well when you had someone like that on your show.
HANNITY: Excuse me. Excuse me. I am the biggest supporter of Israel --
GIBBS: I think it's bad that you gave him a platform.
HANNITY: And I've got a 30 year history of -- on the record of it.
GIBBS: Well, ask them and their friends about what Andy Martin said. You used that guest --
HANNITY: And listen -- I am not friends with a guy that bombed the Pentagon. I'm not friends with a guy that bombed the Capitol --
GIBBS: Here, you take this (hands Hannity a card) -- take that.
COLMES: Well, let me jump in for a second, Robert.
HANNITY: Your candidate is friends with him, not me.
GIBBS: You're friends with someone who is a virulent anti-Semite. Ask someone -- ask Benjamin Netanyahu about that!
HANNITY: Your candidate is friends with a terrorist!
GIBBS: That's not true.
COLMES: Hey guys --
HANNITY: He sits on a board with a terrorist.
COLMES: Guys, stop it. First of all, he's not anti-Semitic.
HANNITY: Thank you very much.
GIBBS: Well, well --
COLMES: This game of guilt by association I disagree with, on all fronts. I will defend Sean against anti-Semitism, he's not anti-Semitic. But I also deplore this game of guilt by association.
GIBBS: Sure!
COLMES: The people who've sat on this board were also republicans; on one of these boards there was the former president of North-Western University; Walter Annenberg was a Reagan ambassador who gave his money --
GIBBS: Friend of Ronald Reagan --
COLMES: So this game of guilt by association is ridiculous!
(For a very good friend and fellow procrastinaritis-afflicted one:)
I believe that if anything is worth doing, it would have been done already.
I shall never move quickly, except to avoid more work or find excuses.
I will never rush into a job without a lifetime of consideration.
I shall meet all of my deadlines directly in proportion to the amount of bodily injury I could expect to receive from missing them.
I firmly believe that tomorrow holds the possibility for new technologies, astounding discoveries, and a reprieve from my obligations.
I truly believe that all deadlines are unreasonable regardless of the amount of time given.
I shall never forget that the probability of a miracle, though infinitesmally small, is not exactly zero.
If at first I don't succeed, there is always next year.
I shall always decide not to decide, unless of course I decide to change my mind.
I shall always begin, start, initiate, take the first step, and/or write the first word, when I get around to it.
I obey the law of inverse excuses which demands that the greater the task to be done, the more insignificant the work that must be done prior to beginning the greater task.
I know that the work cycle is not plan/start/finish, but is wait/plan/plan.
I will never put off until tomorrow, what I can forget about forever.
I will become a member of the ancient Order of Two-Headed Turtles (the Procrastinator's Society) if they ever get it organized.
Energizer Bunny arrested -- charged with battery. A pessimist's blood type is always b-negative. Practice safe eating -- always use condiments. A Freudian slip: when you say one thing but mean your mother. Shotgun wedding: A case of wife or death. I used to work in a blanket factory, but it folded. If electricity comes from electrons does that mean that morality comes from morons? A hangover: the wrath of grapes. Corduroy pillows: are making headlines. A book on voyeurism: a peeping tome? Dancing cheek-to-cheek is really a form of floor play. Banning the bra: was a big flop. Sea captains: don't like crew cuts. Does the name Pavlov ring a bell? Successful diet: the triumph of mind over platter. Time flies like an arrow. Fruit flies like a banana. A gossip: someone with a great sense of rumor. Without geometry: life is pointless. When you dream in color: it's a pigment of your imagination. Condoms: should be used on every conceivable occasion. Reading whilst sunbathing makes you: well-red. When two egotists meet: it's an I for an I. Alarms: What an octopus is. Crick: The sound that a Japanese camera makes. Dockyard: A physician's garden. Incongruous: Where bills are passed. Khakis: What you need to start the car in Boston. Oboe: An English tramp. Pasteurize: Too far to see. Propaganda: A gentlemanly goose. Toboggan: Why we go to an auction. and finally, Marriage: the mourning after the knot before.