Articles from 2006

 
 

Octal Notation in Regex

I recently needed to replace the non-standard extended characters that ms-word uses for quotes in over 80 pages. The octal notation available in regular expressions proved to be very helpful. To use octal in a regular expression just escape the three number code like \200.
[code lang="php"]
#!/usr/bin/php -q
for($id = 1; $id<82; $id++) {
$text=mysql_result($result,0,"content");
$new_text = ereg_replace("â\200\234","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\235","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\223","-",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\231","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\230","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200","",$text);
$text = $new_text;
$new_text = ereg_replace("â","\"",$text);
$text = $new_text;
$new_text = ereg_replace("\r\n","\n",$text);
$escaped_text = mysql_escape_string($text);
}
?>
[/code]

Fixing broken cups password in Dapper

Today while trying to configure my laptop to print to a network printer, I ran into some issues that I thought others might also have trouble with.

The first issue is that by default, network printer auto-discovery is disabled. Though this is not necessary to be able to add a printer, enabling it makes the process much easier. To enable network printer auto-discovery, run

sudo ln -s ../backend-available/snmp /usr/lib/cups/backend/snmp

Now to see the detected printers use [url]http://localhost:631/admin[/url]. You should see a list of detected printers and be able to add them from there.

The next problem was that the cups admin won’t accept your login. This is supposed to be your root user and password. To work around this just open the cupsd.conf file in your favorite editor.

sudo gedit /etc/cups/cupsd.conf

Then comment any lines that begin with AuthType or Require. I found 6 lines that needed to be commented out. So the following lines in cupsd.conf.


AuthType Basic
Requre user @SYSTEM

Require user @OWNER @SYSTEM

AuthType Basic
Require user @SYSTEM

Require user @OWNER @SYSTEM

Needed to be changed to the following


#AuthType Basic
#Requre user @SYSTEM

#Require user @OWNER @SYSTEM

#AuthType Basic
#Require user @SYSTEM

#Require user @OWNER @SYSTEM

After enabling network printer auto-discovery and disabling the password authentication in the cups manger, I can easily add network printers.

Ubuntu, Inconsistent apt-get State

I recently installed a debian package that left apt-get in a very bad state. Whenever I tried to upgrade or install a package I received the following error.

% sudo apt-get upgrade
Reading package lists… Done
Building dependency tree… Done
E: The package jedit needs to be reinstalled, but I can’t find an archive for it.

If I tried to uninstall the package I would get the following.

% sudo dpkg –remove jedit
dpkg: error processing jedit (–remove):
Package is in a very bad inconsistent state – you should
reinstall it before attempting a removal.
Errors were encountered while processing: jedit

The only way I was able to get the package manager working properly was to run

% sudo dpkg –force-remove-reinstreq –remove jedit
dpkg – warning, overriding problem because –force enabled:
Package is in a very bad inconsistent state – you should
reinstall it before attempting a removal.
(Reading database …
dpkg: serious warning: files list file for package `jedit’ missing, assuming package has no files currently installed.
107365 files and directories currently installed.)
Removing jedit …


Mmm, I am really impressed with NOVO coffee. Very good! Maybe it's just because I've been drinking the Folgers coffee at the office.

Just saved $290 by changing the damn radiator myself

Doh, I ran out of propane halfway through a brew session. That added an extra hour to an already long brew day.

Follow me on Twitter