Fork me on GitHub

bill-ingram.com

Programming | Web Design | Photography

Regular Expression for Parsing Phone Numbers

This regular expression will parse most phone numbers into four groups: country code, area code, number, and extension. It works most of the time, see the examples below.

Here’s the expression:

1
^(?:[\+]?[\(]?([\d]{1,3})[\s\-\.\)]+)?(?:[\(]?([\d]{1,3})[\s\-\/\)]+)([2-9][0-9\s\-\.]{6,}[0-9])(?:[\s\D]+([\d]{1,5}))?$

Again, as a Java string:

1
"^(?:[\\+]?[\\(]?([\\d]{1,3})[\\s\\-\\.\\)]+)?(?:[\\(]?([\\d]{1,3})[\\s\\-\\/\\)]+)([2-9][0-9\\s\\-\\.]{6,}[0-9])(?:[\\s\\D]+([\\d]{1,5}))?$"

Results:

Target String matches() group(0) group(1) group(2) group(3) group(4)
011-656-555-1234 Yes 011-656-555-1234 011 656 555-1234
(217)555-1234 Yes (217)555-1234 217 555-1234
(907) 555-1234 Yes (907) 555-1234 907 555-1234
+82-10-5551-2345 Yes +82-10-5551-2345 82 10 5551-2345
+(82) 10-5551-2345 Yes +(82) 10-5551-2345 82 10 5551-2345
+886-2-55512345 Yes +886-2-55512345 886 2 55512345
1-416-555-1234 ext 1234 Yes 1-416-555-1234 ext 1234 1 416 555-1234 1234
714 555 1234 / 1234 Yes 714 555 1234 / 1234 714 555 1234 1234
+1-714-555-1234 Yes +1-714-555-1234 1 714 555-1234
+(82) 10-5326-5760 Yes +(82) 10-5326-5760 82 10 5326-5760

Textmate-like Fuzzy Finder in RubyMine

I just discovered, after months of RubyMine use, that the GoTo functions work like fuzzyfinder in Textmate. There are a lot of useful shortcuts under the GoTo menu; the ones I am finding most useful are Ctrl+Shft+N for finding and opening a file, Ctrl+N for a class, and Alt+Shft+N for jumping to a corresponding Rails object. For instance, if I am in the People controller, I can jump to the Person model, People views, etc, bringing me that much closer to fulfilling my dream of never having to leave the keyboard when developing.

Google+

Yesterday was my birthday, and – what do you know? – I got an invitation to join Google+. Pretty exciting! I was one of the first of my friends to get on, so I had the opportunity to invite a lot of my buddies and colleagues. My inbox stayed full today with notices from Google that another one of my contacts had joined the network, and would I like to add her to one of my circles. Circles, by the way, are what sets Google+ apart from other services in this space. As a friend pointed out today, Google+ is kind of like a combination of Twitter and Facebook. You don’t friend people like in Facebook; you follow them like on Twitter. Come to think of it, all day people have been comparing Google+ to Facebook, but it’s actually a lot more like Twitter than one would think at first glance.

Another feature I really like, related to circles, is the stream. Streams are like the Facebook news feed, except they only contain posts and updates from members of a particular circle. I love that I can separate my feeds that way. When I started putting people into circles, it was based on their role in my life: colleagues, friends, family, &c, &c. But now I am reorganizing my circles based on what kind of streams they will produce. For example, some contacts only posts jokes, funny videos, and whatnot, so I’ve created a new circle called funny for them. For those who generally share information about computers, I’ve created a group called computers. See where I’m going with this?

I just started this evening with sparks. Sparks are lists of topics I am interested in, and streams associated with that topic. I’m not really sure what their importance is yet, but I have a few just in case it’s useful to.

So that’s my first impression of Google+. If you want to connect, visit my profile and add me to a circle. Cheers.

Starting My Blog Over With Jekyll

I started using Wordpress to design my blog because I like the all the free stuff I got out of the box. It is definitely the best turn-key blogging software solution out there – at least it was when I set up my site a year or so ago. What I really liked about Wordpress was the plethora of nice looking, free themes out there. It was really easy to set up a cool looking blog in just a few minutes.

Nowadays I think that all the Wordpress provides is probably overkill for my little blog here. What I want now is simplicity. And I found that with Jekyll. Jekyll is not a blogging software solution like Wordpress. It’s a static HTML generator that allows me to write my posts in textile or markdown, and I can check my code in at GitHub. It’s a workflow I am used to. Super simple. Very clean. I like it.

Thanks to Tom Preston-Werner for sharing.

Removing a Service From All Run Levels on Ubuntu 10.04

If postgres is running, stop it

1
sudo /etc/init.d/postgresql-8.4 stop

Or do it the proper way

1
sudo service postgresql-8.4 stop

Remove it from rc.d

1
2
sudo update-rc.d postgresql-8.4 remove
update-rc.d: /etc/init.d/postgresql-8.4 exists during rc.d purge (use -f to force)

This time with force!

1
2
3
4
5
6
7
8
9
sudo update-rc.d -f postgresql-8.4 remove
Removing any system startup links for /etc/init.d/postgresql-8.4 ...
/etc/rc0.d/K19postgresql-8.4
/etc/rc1.d/K19postgresql-8.4
/etc/rc2.d/S19postgresql-8.4
/etc/rc3.d/S19postgresql-8.4
/etc/rc4.d/S19postgresql-8.4
/etc/rc5.d/S19postgresql-8.4
/etc/rc6.d/K19postgresql-8.4

That’s it.

Installing PostgreSQL-8.2 on Ubuntu 10.04

First, add the Hardy repositories to apt-get sources. If this file does not already exist, create it.

1
sudo vim /etc/apt/sources.list.d/hardy.list

Add the Hardy repos.

1
2
3
deb http://us.archive.ubuntu.com/ubuntu/ hardy universe
deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb http://us.archive.ubuntu.com/ubuntu/ hardy-security universe

Update apt-get, and install.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo apt-get update
sudo apt-get install postgres-8.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
postgresql-8.2: Depends: libkrb53 (>= 1.6.dfsg.2) but it is not installable
E: Broken packages

That’s not good. It turns out libkrb53 has been replaced by libkrb5-3 in Ubuntu 10.04. To make matters worse, the old libkrb53 package was split up into several other packages (libkrb5-3 for libkrb5 itself, but also libgssapi-krb5-2, libk5crypto3, and libkrb5support0).

Here’s the fix (see Bug #462059). Use equivs to generate a fake transitional libkrb53 package.

Create a dummy file called libkrb.txt, with this text:

1
2
3
Package: libkrb53
Version: 1.6.dfsg.2+fake1
Depends: libkrb5-3, libgssapi-krb5-2, libk5crypto3, libkrb5support0

Run equivs-build on the dummy file. (You may have to sudo apt-get install equivs first.)

1
sudo equivs-build krb.txt

This will generate the file libkrb53_1.6.dfsg.2+fake1_all.deb. Install the resulting .deb.

1
sudo dpkg -i libkrb53_1.6.dfsg.2+fake1_all.deb

Now install postgresql-8.2; it’s dependencies are resolved.

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt-get install postgresql-8.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
oidentd ident-server
The following NEW packages will be installed:
postgresql-8.2
...
...
...
Starting PostgreSQL 8.2 database server

Done!

Recursively Delete .svn Directories

Finding all the .svn directories is easy

1
2
3
4
5
6
$ find . -type d -name .svn
./.svn
./sourceA/.svn
./sourceB/.svn
./sourceB/module/.svn
./sourceC/.svn

Now use command substitution with rm -rf.

1
rm -rf `find . -type d -name .svn`

Note the use of the backtick symbol (located under the ~ on the English keyboard)—that is not a single quote.