Enable PHP autocompletion in Eclipse (Ubuntu 11.04)

Monday, Oct 3, 2011 1:29 pm
William Barnes

For some reason, Eclipse (using PHP Development Tools) doesn’t include built-in PHP functions with a new project. Assuming you downloaded Eclipse from the Ubuntu repository and added PDT through Eclipse’s “Install new software” dialog: in Eclipse, right click on your project in the Explorer pane; choose Include Path, Configure Include Path; select the Libraries tab; click Add External Source Folder. The folder you need may vary depending on the version of Eclipse, it should look something like “~/.eclipse/org.eclipse.platform*/plugins/org.eclipse.php_core*/Resources/language/phpVERSION”.

Python script to fix broken symlinks

Monday, Sep 26, 2011 4:47 pm
William Barnes

I recently added a new hard drive and reorganized my increasingly chaotic and whimsically named storage and backup partitions. In the process, I moved a folder containing hundreds of symlinks to a different drive resulting in hundreds of broken symlinks (I should have used rsync).

This script will repair symlinks after you’ve moved a folder. Change BASEDIR to the current location of your files and OLDBASE to where they used to be. For example, if you moved all your files from /mnt/Backup2 to /mnt/Backup2, then BASEDIR = ‘/mnt/Backup2′ and OLDBASE = ‘/mnt/Backup1′. If you want to test (to make sure it will do what you expect) then change DEBUG to True.

This script will only fix symlinks that point to files/directories within the BASEDIR.

  1. #!/usr/bin/env python
  2.  
  3. import os
  4.  
  5. # Configuration
  6.  
  7. BASEDIR = '/mnt/NewStorage'
  8. OLDBASE = '/mnt/OldStorage'
  9. DEBUG = False # I recommend a test run first
  10.  
  11. def relink(path):
  12. old_target = os.path.realpath(path)
  13. new_target = old_target.replace(OLDBASE,BASEDIR,1)
  14. if DEBUG:
  15. print "Relink: " + path + "\n\tfrom " + old_target + "\n\tto " + new_target
  16. else:
  17. os.remove(path)
  18. os.symlink(new_target,path)
  19.  
  20. for root, dirs, files in os.walk(BASEDIR):
  21. for filename in files:
  22. fullpath = os.path.join(root,filename)
  23. if os.path.islink(fullpath):
  24. relink(fullpath)
  25. for dirname in dirs:
  26. fullpath = os.path.join(root,dirname)
  27. if os.path.islink(fullpath):
  28. relink(fullpath)

If you save the script as ~/link-fix.py then run it with python ~/link-fix.py.

Toggle Gnome screensaver lock on USB key insertion

Sunday, Sep 25, 2011 9:39 am
William Barnes

While I like my computer to lock itself automatically when I leave, it gets annoying when it does it every time I get up for a few minutes. I decided that it would be nice if I could toggle the screen lock only when I’m out of the apartment. I decided that the trigger should be the USB key I have on my keychain. It’s always with me. If it’s plugged in to the computer, then I’m likely home. I apologize for the (lack of) formatting of the code, I will be fixing that when I get my computer back up and running.

Ubuntu uses an event-based system called udev that, among other things, can run a script when a USB device is plugged in or unplugged. Local (ie: user-created) udev rules are stored in /etc/udev/rules.d/. Before you can create a rule, you need to know a little about the device that is going to trigger it. Open a terminal and type:

udevadm monitor --udev --environment

Connect your USB device. It doesn’t have to be a USB key, it could be a phone, for example. A bunch of text will come up. Look for “ID_SERIAL” and “ID_VENDOR_ID”. Write down the values of those. You can use other variables if they suit your device better, just change the rules file accordingly.

Create a file called “/etc/udev/rules.d/85-screen-lock-toggle.rules”. Put the following in it, replacing VALUE with the proper value:

  1. ACTION=="remove", ENV{ID_SERIAL}=="VALUE", ENV{ID_VENDOR_ID}=="VALUE", RUN+="/usr/local/bin/gnome-lock-enable"
  2. ACTION=="add", ENV{ID_SERIAL}=="VALUE", ENV{ID_VENDOR_ID}=="VALUE", RUN+="/usr/local/bin/gnome-lock-disable"

Next create the scripts to actually disable and enable locking:

  1. #!/bin/bash
  2.  
  3. user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
  4.  
  5. if [ -n $user ]; then
  6. GNOME_SCREENSAVER_PROC=`ps xa | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
  7. export `grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GNOME_SCREENSAVER_PROC/environ`
  8. su $user -c "gconftool-2 --set "/apps/gnome-screensaver/lock_enabled" --type bool 1"
  9. fi
  1. #!/bin/bash
  2.  
  3. user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
  4.  
  5. if [ -n $user ]; then
  6. GNOME_SCREENSAVER_PROC=`ps xa | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
  7. export `grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GNOME_SCREENSAVER_PROC/environ`
  8. su $user -c "gconftool-2 --set "/apps/gnome-screensaver/lock_enabled" --type bool 0"
  9. fi

Make the scripts executable:

sudo chmod a+x /usr/local/bin/gnome-lock-enable /usr/local/bin/gnome-lock-disable

Restart udev:

sudo restart udev

Enjoy the convenience.

Move Gnome 2 panel to secondary monitor

Saturday, Sep 24, 2011 5:34 pm
William Barnes

This may be irrelevant with Gnome 3, Gnome Shell and Unity taking over, but if you have dual monitors and want the Gnome panel (e.g., menu bar) to span multiple monitors, you can follow these instructions:

Here’s a step-by-step way of moving a panel to another screen:

  1. Right-click the panel you wish to move and select “Properties”.
  2. Uncheck the “Expand” option under the “General” tab.
  3. Grab one of the edges of the panel by clicking on the left or right end (top or bottom end for vertical panels).
  4. Drag the bar to the desired screen and position.
  5. Check the “Expand” option in the “Panel Properties” window and click “Close”.

From Chris Jean’s blog.

WordPress Settings Form Helper

Monday, Sep 12, 2011 4:36 pm
William Barnes

I am currently writing my first WordPress plugin. I attempted to use the Settings API on my plugin’s settings page, but found it was a little cumbersome. So I wrote a helper to cut down the number of functions I needed to define. My plan was originally to simply automate the API calls, but it quickly outgrew the Settings API and does quite a bit more. I am posting it, hoping that it will be of use to some other plugin developers. The class handles form creation, display of options, security (wpnonce, back-end validation), and storage.

Read the rest of this entry »

+1′d

Saturday, Sep 3, 2011 2:50 pm
William Barnes

I do my best not to criticize other people’s grammar, but if you’re a corporation, you should get it right. I just clicked the +1 button on an article and got told that I “publicly +1′d” the article. Is that correct? Or is like all the signs that say “CD’s”? I’m unsure. The apostrophe means that it is a contraction, i.e., something is missing. Is “+1′d” a contraction of “plus oned”? Or should it have been “+1ed”? Google should have picked a less awkward name for its like button.

Google Circles Revisited

Thursday, Jul 14, 2011 12:51 pm
William Barnes

I’ve been using Google+ for about a week now, and I like it. Why? I’m not sure. Maybe only because it’s like Facebook, but not Facebook. I can share things. I can post comments. I can’t really do anything I couldn’t do on Facebook. I’ve never used Hangouts, I’m not sure I’m likely to do so. My RSS aggregator is more useful than Sparks. The only difference is Circles, but I’m coming to the conclusion that Circles isn’t that great either.

Google Circles is based on the idea that we have different groups (circles) of people in our lives: family, friends, people we met at parties, etc. We don’t treat them equally in real life, why do it online? I think it’s a natural concept, but I’m pretty sure that Circles gets it wrong in subtle ways.

Why groups are better than circles

Difference between friends and people with shared interests

Facebook Groups are like circles that people choose to join. All members can see who is in the group and can talk to everybody in it, even if they aren’t “friends”. This reflects the fact that in plenty of formal groups (clubs, workplaces, etc) there is a shared interest, but your association with the members doesn’t go any further than that.

Let’s say I have an interest in widgets and I join the Toronto Widget Club (TWC). If that club has a group, then I join the group and have access to all the widget news and discussion I want. Updates from the group show up in my feed, but a lot of the discussion is segregated. When I make a fascinating widget discovery, I can post it to my wall for friends, to the group, or both. Contrast this with circles. Under the current system, I would have to obtain a list of people in the TWC and add them all to a circle. They would receive my widget posts, but also all my public posts. Many of them wouldn’t care about my personal life or other interests. Circles miss an important distinction between “friends” and “people with a shared interest”.

You might argue that this blurring is good because it might develop friendships where there was previously only a shared membership in the TWC. However, it may also cause friction where people, who tolerate each other in the pursuit of widgets, have otherwise conflicting (e.g., political) interests.

Difference between active and passive sharing

Oversharing could be addressed by never sharing anything publicly and deselecting the TWC when sharing non-widget information. However, when a member of the TWC takes the time to visit my profile, I think that I’d want them to learn about my other interests. This information would be hidden from them by Google+’s privacy settings. There is a difference between what I want to actively share with (broadcast to) a group of people and what I am comfortable with them having access to if they want to seek it out. I want to broadcast widget news to the TWC, but I want to passively share my other interests as well. Thus, they should be able to see political or other posts if they view my profile, but these shouldn’t show up in their feed unless we are friends outside the TWC.

Related to this point is the noticeable delineation between group posts and wall posts. Google+ doesn’t yet provide really good indicators that posts are just for certain groups. You have to look at the visibility of the post. It’s not clear whether a particular Google+ post is open to other circles or private to the TWC, whereas in a group there is a clear indication.

Difference between choosing and assigning membership

I already hinted at the problem when I said that members would have to obtain lists of group membership. In addition to that, they would each have to maintain their list. Groups are superior because there is a single canonical list. Further, you don’t have to rely on others to acknowledge your interest, you register it yourself. This also means that when you tire of widgets, you can remove yourself.

When are circles better than groups?

There are a few cases in which circles are better for groups. Circles are better when group membership is less defined or, more importantly, a sensitive matter. Groups require either public membership or an administrator who decides membership. This is fine for the TWC, but what about groups of friends. I have separate groups of pretty much non-overlapping friends; there is an unspoken consensus about who is in each one. It would be coarse to require them to join a group to find out what we’re doing on Friday. The additional effort of harmonizing the circles of various members is really just socializing and reflects the addition of a new person to a close group of friends.

Circles are not for privacy

First, a little rant on privacy. People expect miracles from social networks in terms of privacy. Rule number one for using the internet: do not say anything on the internet, except under pseudonym, that would terribly embarrass you if it became public. My favourite tweet regarding Google+ came in the early days when I had an invite, but they were at capacity. Unfortunately, I didn’t save it, but it essentially said “Posts you share with a circle can be reshared. Google+ FAIL“. Everything you say online can be reshared. The real weakest link in your privacy is your friends. They have to understand that you intend something to be private and they have to respect that. Of course, even if you trust your friends, you still have to worry about flaws in the software, so if you want something to stay private, then talk about it in person or at least use a medium that is intended for one-to-one conversation (chat, email, etc). I’m not saying Google should be held blameless for the privacy flaw that will inevitably occur, buy anybody who depends on Circles as a privacy guard is asking for trouble.

But Circles provide a little privacy

So what should you use circles for, then? You should use them only to insulate other circles from things they aren’t interested in. For example, people from work don’t need to read about the party you went to on the weekend. If you have two non-overlapping groups of friends, you may only want to share the photos with friends who were invited to that party.

On the Facebook feed, everybody is shouting in all directions, all the time. Circles lets you direct your voice a little bit better. In that sense, Circles provide a bare minimum of privacy. Think of it more like being at a party and standing with a group of people than being in a cone of silence.

How Google could improve Circles

Google+’s PR says that you have circles of friends and they’re not all the same. So why, then, are all my Google Circles the same? You should have more granular control over circles. Examples: whether you want to see Public or semi-Public (ie: “Your Circles”) posts from members of a circle or just ones that they explicitly share with you; whether people in that circle can see your Public or semi-Public posts.

There should be public circles. These would be just like groups (in fact, they could be Google Groups). Some could have open membership, some could be moderated. It would address the problem of canonical lists. Further, in combination with the above suggestion, it would allow you to communicate with people who only share a particular interest.

You should be able to post something that is broadcast only to particular circles, but is publicly visible on your profile. This is the biggest deal for me. I like to have things be public, but I would happily do a little work to shelter others from my oversharing. Until I can do this, I’ll probably be posting everything publicly and using Google+ just like Facebook. It also reflects the fact that one person is not always the best judge of what other people will find interesting. Maybe someone from elementary school will be interested in my night out, or have an insightful comment on a legal- or computer-related post. Why should I hide things from them?

Topical circles

I think that there is a different type of circle that I can’t quite define at the moment. I’m going to call it a topical circle for now. It is somewhat nebulous, like a circle of friends, but it is based on a shared interest like a public circle. It would be interesting if circles could be formed algorithmically for discussing particular topics. The post could be visible to friends of friends who could get in on the conversation and then be included in similar conversations in the future. Eventually, the circle would probably form into a more or less permanent group. That would be interesting.

Circles

Friday, Jul 1, 2011 11:45 am
William Barnes

In reply to “Google+ Everyone Should Use It“.

I don’t know about Circles as a privacy tool. It’s almost guaranteed that at some point (probably at multiple points), a bug will expose information from one circle to another. So I still wouldn’t say anything to a circle that I wouldn’t want going public.

One could use it to target certain groups with comments. I often make legal comments on Facebook that are only funny to people from school. But, then again, who am I to decide who would be interested in my posts? Let’s say I post a comment about a recent Supreme Court case. Sure, my school friends will probably be interested, but I bet that a number of non-law students would be, too. Coming from a different background, they might say something that nobody from school would have thought of. How am I supposed to know who will be interested in what? Tagging is a better solution to that. Let me say “This post is about ‘Law’” (or “Computers” or “Cake”) and then let my friends say “I don’t want to hear Billy talk about ‘Law’ anymore” and hide all those posts in the future.

Maybe I’m just bitter because they’re at capacity and I can’t sign in.