Screensavers in Ubuntu 9.10
I used to do some incredible tweaking for my screensaver in Ubuntu, especially because gnome-screensaver wouldn’t allow for editing the particular screensaver options like xscreensaver would (see: https://wiki.ubuntu.com/ScreenSaver). These days, I don’t want to tweak… I just want the thing to shut off when I am watching fullscreen flash video, so that I don’t have to wiggle the mouse every ten minutes.
So I made a simple toggle script and created a launcher for the script on the desktop. Gonna watch video? Double-click the icon. Done watching video, double-click the icon.
PID=`pidof gnome-screensaver`
if [ "$PID" != "" ]; then
#gnome-screensaver is running shut it down
killall -9 gnome-screensaver
else
#gnome-screensaver is not running, start it up
gnome-screensaver
fi
Posted by Karl Herrick on March 12th, 2010 in Linux, Bash | No Comments »
Post via script
I just whipped up some PHP and threw it in the root of a brand new Wordpress 2.9.2 install:
include_once('wp-config.php');
include_once('wp-load.php');
include_once('wp-includes/wp-db.php');
$my_post = array();
$my_post['post_title'] = 'My post';
$my_post['post_content'] = 'This is my post.';
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
wp_insert_post( $my_post );
?>
Voila. The post appeared when navigating to the .php file.
See: http://codex.wordpress.org/Function_Reference/wp_insert_post.
For more creativity, get into the database: http://codex.wordpress.org/Function_Reference/wpdb_Class
Posted by Karl Herrick on March 11th, 2010 in Wordpress, PHP, Web Development | No Comments »
Google Buzz
I heard about Google Buzz on CBC Radio yesterday… came home and tried to connect but it wasn’t activated. What’s all this Buzz about? Today, while using Gmail, I noticed the icon for it, opened it up, and added some “connected sites”. I’ve already had two conversations about a picture of a turtle I took a few years back. Awesome.
Seems easier to use than Facebook too.
Posted by Karl Herrick on February 10th, 2010 in Google, Culture | No Comments »
Recursive find and replace
From time to time I find myself wanting to replace a bit of text, in multiple files, throughout a huge directory tree (particularly in the case of a Wordpress migration).
Here’s a method I frequently use (other examples I’ve seen out there make use of perl, xargs, grep, etc.):
user@host:~$ find . -type f -exec sed -i 's/Text_To_Find/Replacement_Text/g' {} \;
The find command will return a list of all the files in the directory tree and execute the sed command on each one it locates. In the example below, I added the “-name” option to the find command to allow for working only on files with the .js extension:
user@host:~$ find . -type f -name "*.js" -exec sed -i 's/var pageName="example page";/var pageName="Final Page";/g' {} \;
In the next one, the text to find and replace has special characters (in this case the ‘/’ in the URL).
user@host:~$ find . -type f -exec sed -i 's/http:\/\/www.example.com\/old_directory\//http:\/\/newsubdomain.example.com\/new_directory\//g' {} \;
See the following links to read more about escaping special characters:
- Bash Hackers Wiki - Quotes and escaping
- Unix / Linux Shell Scripting Tutorial - Escape Characters
- Advanced Bash-Scripting Guide
Posted by Karl Herrick on February 8th, 2010 in Wordpress, Linux, Hosting, Bash | No Comments »
Sloppiness at 1and1
So I have been noticing issues with 1and1 again. Yesterday when trying to get into my hosting control panel at admin.and1.com, I received a “HTTP Error 503 Service unavailable” error, and thought to myself… really, on the admin panel… really?
Today while checking out my own site, I noticed that all of the PHP files I tried browsing to returned “500 Internal Server Error” errors.
Now this has gone too far… so I called them up. At first the person I talked to explained that I needed to force PHP5 using a .htaccess file, and proceeded to tell me that they could make the change for me. Calmly, I responded by saying that I did not want a change, and that it had been working fine the way it was for months.
She put me on hold, and while I waited… it started working. She told me that the shared hosting server “had a glitch”.
Afterwards, I ssh’ed into my server. Look what I found:
total XX
-rw-r–r– 1 uXXXXXXXX XXXXXXXX 16 Feb 3 14:06 info.php
I thought, “weird, I didn’t put that there”.
Shame on you 1and1, for not cleaning up after yourself. Well, I guess you get what you pay for.
Posted by Karl Herrick on February 3rd, 2010 in Culture, Linux, Hosting, Bash | No Comments »