PHP cheatsheet

This post is for PHP stuff that I needed to use, but couldn’t easily find on the web

‘pass’ in PHP

Maybe it’s bad to start using conventions from other languages, but I find that sometimes the code is more readable if you write an if statement so that nothing happens if the conditon is true and then put the code that will get run often in the else block.  In python, if you don’t want anything to happen in a block, you use the pass statement.  In PHP, you can just leave the block empty:

if ( $condition == true) {
// do nothing. note that other than the comment
// there are no statements in this block
else {
// do stuff


Xubuntu Gutsy Gibbon on Dell Latitude D810

I got Rich’s old notebook from work and installed Xubuntu 7.10 (Gutsy Gibbon) see update below on it. I’m tracking issues I’m having with the distro/platform here.

Spell Checking in OpenOffice Writer – FIXED

After having this machine for a while, I just noticed this issue.  I followed some instructions I found here and tried File > Wizards > Install New Dictionaries.

Update: Volume Control Widget – FIXED

My volume control widget up and disappeared.  This post made the suggestion that instead of clicking the ‘Add’ button from the widget list (accessed by right clicking on the taskbar and choosing ‘Add New Item’), you can drag the volume control widget from the list window onto the taskbar and it works.

Update: Upgraded to 8.04

I upgraded via package updates to 8.04 (Hardy Heron) without any problems.

Can’t lock screen – FIXED

I added the screen locking widget to my top panel, but clicking it didn’t do anything. I fixed this by installing the xlockmore-gl package.

Can’t suspend/hibernate – FIXED

When I try to use the buttons to suspend/hibernate (I think these are from some gnome program), the screen goes blank, but I’m not able to resume.

Link to launchpad bug report about this issue.

Apparently, others with this laptop were able to have success by using the uswsusp package. However, they were running Feisty, not Gutsy.

Link to userspace software suspend home page.

Debian has a newer version of the uswsusp package, so I tried installing that because I found what appeared to be thorough docs on using the 0.7 version. Things still didn’t work.

I found another post on the ubuntu forums that aggregated a bunch of information about this issue. link.

I removed the fglrx video driver (a non-free driver) as this was mentioned as causing problems. After removing this driver, suspend to ram didn’t work, but hibernate did using the default login,shutdown,etc. menu. Using the s2ram program from the command line also worked!

Update: If I want to lock the screen on resuming from suspension, I use

s2ram; xlock&

Trackpad is slow

The trackpad seems to move extremely slowly. I can configure the eraserhead using the Mouse Settings panel, but this doesn’t effect the trackpad.


This was the most straightfoward thing so far. This forum thread helped my get my PC5750 EVDO card working just fine with pppd and wvdial.

Playing Encrypted DVDs

Add the following line to /etc/apt/sources.list

deb gutsy free non-free

Then run

sudo apt-get install libdvdcss2

Function Keys on Keyboard

These are the keys on the keyboard with additional functionality (written in blue on the keys and accessed by holding down the Fn key to the right of the left-hand-side Ctrl key) that do things like switch between CRT/LCD, eject CD media, change volume or brightness, etc.

vim cheatsheet

Extracting from a vimball


Users of a vimball archive simply need to

:vim something.vba
:so %

and the contents of the vimball will be extracted and placed into the proper directories, no matter where the user opened up the vimball. Furthermore, the helptags command will be automatically and transparently used to make any doc/*.txt files’ contents available by the Vim help system.

Getting the filename of the currently edited file


:!echo %:p                        : full path & file name
:!echo %:p:h                      : full path only
:!echo %:t                        : filename only

Removing empty lines

From Vim Tip 72:


Converting select text to lowercase

In visual mode, select text.  Then type the u key.

csv import plugin for wordpress

I want a plugin to import posts from a CSV file.  This is useful for putting in lots of Let’s Go! events all at once.  A good reference for how to do this is looking at the RSS Import plugin in wp-admin/import/rss.php

ssh cheatsheat

Port forwarding


$ ssh -f -L sleep 10

Backing up files over SSH

$ ssh remote_host "tar -zc -C /path/to/parent/directory -f - some_directory" | cat > some_directory-`datestr`.tar.gz

Backing up a postgres database over SSH

$ ssh remote_host "pg_dump --username=db_user db_name" | gzip  > db_name-`datestr`.sql.gz

notes on The Macho Paradox


When men were targeted for prevention efforts, in educational or community settings, they were often sseen as potential perpetrators. The message to them: you need to recognize the triggers for your own bad behaviors so you can interrupt the process before you have the urge to strike your girlfriend/wife. Or, you need to develop better interpersonal communication skills, like good listening, so you do not force yourself on women sexually. Or, if you occasionally or regularly drink alcohol and then behave in a manner you cannot defend when sober, you need to get immediate help with your drinking problem.

The first problem with this approach is that it treats gender violenec as an individual issue that is caused by man’s personality flaws. It presumes that gender violence is a type of dysfunctional behavior that can be cured with therapy or punished by jail time, rather than a specific manifestation of a deeply rooted system of male dominance. As we have seen, people constantly misrepresent gender violence as the behavior of a few bad apples.

p. 118

Men of color are more likely than white men to be held accountable for their crimes, especially if their victims are whire. For example, in the early decades of the twentieth century, thousands of African American men were lynched by vigilante mobs of white men, predominantly in the South, based on trumped up charges that they had raped white women. This racist legacy cannot be overlooked or wished away. But the solution to this disparity is not to ease the pressure on perpetrators; it is to seek fair treatment in the application of justice. If fewer men who assault women got away with it-including wealthy white men-the anticipation of negative consequences would reinforce the need to prevent it from happening in the first place.

p. 121:

Journalist Nathan McCall explains in his essay collection What’s Going On that he and some of his African American male cohorts in the 1960s and 1970s learned a lot about “manhood” from watching gangster films which featured ruthless Italian men who regularly assaulted each other and treated women as little more than property.  Gangsta rap in the late twentieth and early twenty-first century borrowed a lot from these cinematic portrayals.  Ironically, many young suburban white men today are powerfully influenced by black urban gangsta rappers, who in turn learned about how “real men” are supposed to act from white actors in movies that were written and directed by white men.

from the radio: analysis of digital media and a cool sounding college class

This radio piece had interesting statistics on the financial viability of the latest Radiohead album which was also available as a free download.

Adam Greenfield, the person interviewed in the piece teaches a class in Urban Computing at as part of the Interactive Telecommunications Program at NYU.



My friend Peter, had the following to add:

Regarding your recent blog post ( The statistics cited in the NPR story are indeed interesting, but not for the reason most people (even in the “quality” mainstream press) think they are.

As I reported in a recent issue of The Nation (, the stats were gathered by Comscore, an internet marketing firm that gathers data from 2 million poor souls who let their every point and click be monitored in exchange for some free software and sweepstake entries. Their software doesn’t work on macs or in firefox. They provide no detailed information about the type of statistical analysis they use They don’t even publish their relevant sample sizes ( i.e. how many of the folks they monitor actually bought the album – the way they phrase it leaves). Their findings are not accepted by many trade groups, and have been widely (and justly) critiqued across the web. Yet the AP, the NYtimes, NPR, etc. etc. are all regurgitating their Radiohead findings, never once noting that the evidence isn’t there.

Why would they do such a thing?

While reporting my first story (a reported personal essay, also in The Nation) on the Radiohead album, I noticed that all the industry people I talked to were not-so-subtly trying to put down Radiohead’s effort. One exec told me he’d heard they were just demos they were dumping on the public for laughs. When I pressed him, he told me he got the info from a members-only industry message board. I weaseled my way into a membership and guess what? No talk of “demo dumping.” Others told me “just look at the reviews, no one thinks its any good, etc.” It’s aggregating in the high 90s at!

To quote one of my own articles:

“It’s hard to resist some cynical conclusions: Comscore’s client base includes several media conglomerates, media conglomerates want In Rainbows to fail, newspapers want stories, and failure sells.”

Update 2:

I read on my friend Jenny’s blog, Greater Detroit, about a Detroit-based artist who also released his latest album, DETRO!T BE!RUT, as a free or donation-based download.

From the artist’s website:

This music comes from South Lebanon, was born in Lansing and lives in Detroit.  A sound declaration.  This music is rhythm for revolutions, rebellions, empowerment and progression.  Through audio and images, history is projected onto the future, terrorific stereotypes are rejected, a slandered heritage is reclaimed, the ruins of a city are rebuilt.  Sound and visions express the struggles and share the beauty of Detroit, Beirut.

Honestly, I’ve only just started listening to the recording, but it makes me think about refocusing the question of downloadable music.  I think the question is often asked as whether free or donation-based music is viable for the music industry or for artists in the context of the music industry.  I’m not sure if it is viable for the industry, or artists trying to operate within that system.  However, I don’t think that’s problematic.  I think that the Internet and digital music is less interesting as a tool that can be assimilated into the current music industry’s business model, or even as something that will shift the direction of the music industry, and more interesting as something that allows for a completely separate space for the dissemination of music and ideas.

It’s easy to see downloadable music and the social and technological network infrastructure that supports it as something that can be exploited by those who wouldn’t succeed within the confines of the record industry.  This casts those who utilize these networks as failures within the mainstream media market.  However, I see the recording industry and mainstream media as failing to produce media that is multicultural or culturally critical and that speaks to or from those for whom the traversal of these cultural boundaries is personal and important.  Digital media offers an opportunity, not just as reform or critique, for artists to succeed where existing cultural systems has failed.  It offers a tool to create something that is completely new and separate, not a music industry, but, hopefully, music culture.

albio in prague

I’ve had this on an ATM receipt floating around my notebook since this summer.  Chiara and I ate a very good meal at a restaurant in Prague that specialized in vegetarian/organic/local foods:

Truhlarska 20
Praha 1
(accessible via the namesti republiki stop on line b)

notes for the week of 2007-09-24

Tim says to check out Kaati rolls while I’m traveling.

This wiki page has info on how to configure e-mail integration in eventum which Boxcar uses to handle tech trouble tickets. I wanted to turn off auto issue creation because we get a lot of e-mails that don’t neccessarily want to become issues and then there’s the overhead of closing the issue.

The Allied Media Conference is taking proposals for some web development. Josh asked me about Drupal vs. Joomla, and I’m not that familiar with Joomla. This thread seemed to offer some insight.

kdenlive is the software I started using to play around with video editing on linux.

I’ve long wanted to be able to do a substitution or other command on a visual block. It turns out that there is a vim script called vis.vim to help you do this.

I read mail using a lot of different clients. So, I wanted to seperate my mail filtering rules from my mail client. Imapfilter does the trick and though it’s configuration language is daunting at first glance, it’s not too bad.

I was wondering how to drop all tables in a MySQL DB from the command line:

mysqldump -u username -ppassword –add-drop-table –no-data database | grep ^DROP | mysql -u username -ppassword database

worked fine.