Adventures in Red Hat Enterprise Linux, CentOS, Fedora, OpenBSD and other open source solutions.

Save energy by designing/using black websites

Saving energy is a hot topic. According to it saves energy when pages background color is black, instead of a commonly used white page.

Imagine your website could be government sponsored, if the background would be black...

Blackle claims that Black Google would save 750 Megawatts a year. That sounds dramatic!

Update: partially true

As far as I can measure with my Brennenstuhl PM 230, my monitor uses 42.12 Watts constantly, black or white Google.
On bigger monitors (24", 30" it does seem to make a difference of a few watts.

Check your websites PageRank and Backlink quickly

Check out the Xinu website, which is a collection of webtools and checks gathered at one page. Simple and efficient!

So, check your website/blog with xinu.

Logo creator

Me in IT - hosting web 2.0 logo
Nothing shocking, but this site lets you create a logo in web 2.0 style. Check the Web 2.0 - Logo Creatr website.

Sending mail from command line

There are a few tools available to send mail from the command line to an email-address. Here is "mail" for example:

$ cat file
Hello World
$ cat file | mail -s "Here is my email" [email protected]

Now this is very nice, but it's not possible to set the from (From:) address using mail. To do that you'd need a more sophisticated solution, using Sendmail.

First you will have to modify that file you'd like to send. This file should include the Headers:

$ cat file
From: [email protected]
To: [email protected]
Subject: Here is my email

Hello World

Now you will have to send this file using sendmail. N.B. Another email address is specified here, this is the actual address where your email will be sent to. This means you can forge everything in the Headers. (In the file)

$ /usr/sbin/sendmail [email protected] < file

Well, hope that helps you, it sure helped me when creating reports to send to customers.

Drupal slow, mysql query error

That was a difficult problem; On of my customers website was very slow. I personally created that page, so every piece of code was "known" to me.

My initial thought was that Drupal or some module were slowing down this website. Turns out I made a mistake. I discovered this by reviewing the mysql_slow_query logs. The initial query contained an error:

SELECT files.filepath, node.nid, node.title from files, term_node, term_data,node, node_counter
WHERE files.nid=term_node.nid
AND term_node.tid=term_data.tid
AND node.nid=term_node.nid
AND term_data.tid=65
AND files.filename="thumbnail"

Do you see that the node_counter is opened, but not being used anywhere? After removing the bolded text, everything returned to normal. The query was rewritten to this version:

SELECT files.filepath, node.nid, node.title from files, term_node, term_data,node
WHERE files.nid=term_node.nid
AND term_node.tid=term_data.tid
AND node.nid=term_node.nid
AND term_data.tid=65
AND files.filename="thumbnail"

Cool webcomics

Likely for years around, but new to me it very nice web comic. Check out this image for example!
A webcomic about the 90s.

Importing txt/cvs into Microsoft Visio

When you are in need of a graphical overview of something and you are able to script it, chances are you are able to import this information into Microsoft Visio.

Here is an example case; You would like to see what what objects link to other objects, not in text, but graphically.

Imagine this is the data:

ONE is connected to TWO
TWO is connected to THREE
THREE is connected to ONE

Read more to create this simple graph:
An example image of a graph.

  1. Convert this information into this (Visio compatible) format:
  2. Shape,"ONE","","this shape is called ONE"
    Shape,"TWO","","this shape is called TWO"
    Shape,"THREE","","this shape is called THREE"
  3. Save the file
  4. Open Visio
  5. Click Open
  6. Set Files of type to Text Files and click Open.
  7. Set the Field Separator to a comma(,) and click OK.
  8. Drag things around until you have a clear overview.
  9. That is it, but you might need to know a bit more. Add this line on top of the text file for automatic placement.


    To use a template like Active Directory, use the following syntax. (on top of the text file)

    Template,"Active Directory.vst"

    To indicate an object, like a "site" instead of the default simple box, use the third field in the Shape line:

    Shape,"site3","site","The long version of site3"

    To find out what object names can be used, right-click an object within Visio, and check the properties.

    To add some text on a line, use the fourth field in the Link line:

    Link    ""      ""      "30"    "site2"        "site3"

    (This actually draws a line between site2 and site3, and prints 30 on that line.)

    Good luck making cool layouts!

Cool book: Classic Shell Scripting (O'reilly)

Not trying to be commercial here, but please check out this book about Classic Shell Scripting. It's published by O'reilly, which has produced quite some cool books.

This book focuses on the shell (bash, bourn shell) scripting as you might have guessed, judged by the title. Why this book is better, compare these two pieces of code:


# ugly code example

# Count the number of lines in `w`.
who_raw=`w | wc -l`

# Two lines are used for headers, subtract them.
who=`echo $who_raw-2 | bc`

echo "There are $who users logged in."


# better code example

echo "There are $(($(w | wc -l)-2)) users logged in."

And, trust me, after reading (parts of) this book, the "better code" could be approved on many points.

The result of reading this book is faster, cleaner, more "native" shell scripts.

Replacing things in MySQL

UPDATE The proper trick is described here:

update table set field = replace(field, 'original string','new string');

Here is how to replace some text in mysql, using some shell commands.
I am sure somebody can tell me how this can be done in mysql, not using these shell commands.

This specific query is created for Drupal, but it can be modified for any database model.

mysql -u USER -p DATABASE -B -e "select nid,title from node;" \
| sed 's/\.jpg//;s/\.JPG//'| while read nid title ; do echo "update node \
set title=\"$title\" where nid=$nid;"; done > file.txt

The file.txt will look like this:

update node set title="DSCF0233" where nid=1767;
update node set title="DSCF0236" where nid=1768;
update node set title="DSCF0256" where nid=1769;

To import this back into mysql:

mysql -u USER -p DATABASE &lt; file.txt

Syndicate content