It’s time to relax, my friend!

ript>

Do you often find yourself working with your keyboard and mouse continuously for many hours? There are many things you can do to avoid eye strain and hand/wrist pain.

Besides the possible ergonomic (table/chair/light) rearrangements, one must consider relaxing for a few seconds every now and then, when the workload reaches a high limit.

For this task, there is a very useful utility, called RSIBreak, which monitors the time and speed a user is working with the keyboard and mouse and, when it’s necessary, recommends a short break. Additionally, in case the user didn’t “obey” this advice, it can force her to obey by disabling temporarily the user interface (keyboard/screen)!

Personally, I find it very valuable and, some times, I found myself looking at the small clock icon at the tray with the fear that it will prompt me to relax before I complete whatever I’m writing that moment. [Don’t worry though… for situations like this, the developers included the use of the “Escape” key!]

Think about it…
a short break helps the mind too!


Visit The Light of the LAMP blog for more…

Command-line PHP

Working with the command-line version of PHP can be very enlightening some times. For example, consider the following situations:

  • Instead of having a test page with only phpinfo() in it, just to view PHP’s current settings, you can issue:

    php -i

  • Suppose you want to check your PHP code quickly for any errors. Executing

    php -l filename.php

    can easily reveal any pitfalls.

  • If you want to employ your code in a production environment, your don’t need any textual redundancies, so you can strip all the comments and whitespace by using

    php -w filename.php > ../production_directory/filename.php

  • Finally, suppose you’ve just added/enabled a new module and you want to know if you did everything correctly. Then

    php -m | grep “modulename”

    will answer this question.

For more information, read the manual page of php!

Of course, to be able to do all the above, you have to install the CLI of PHP. For a system that uses the apt-get family of scripts, this is as easy as running:

sudo apt-get install php5-cli

For other systems, I believe that commands like

yum install php5-cli

or

rpm -Uhv php5-cli

will work the same. Check your system’s documentation about the correct command and syntax.

Being able to run PHP scripts from the shell is a very powerful capability, especially if one doesn’t feel comfortable with shell scripts or other interpreted languages, such as PERL or Python.


Visit The Light of the LAMP blog for more…

What’s in the news… about me?

When you have done implementing your web site/application, you should consider monitoring its presence in the search engines. By knowing where your work appears or being proposed/discussed/advertised, you have a clear view of its influence to on-line communities and possible customers or visitors.

This is a very good reason to use the alert facilities developed by the major search engines. In this post I’ll write about the alerts provided by Google and Yahoo!

Yahoo!
First go to Yahoo! Alerts and log in with your account (or create a new if you don’t have one). Select “Most popular alerts” from the right sidebar and press “News”. Then check “Keyword News” (if not already checked) and press “Set Up Alerts”. Write into “Include:” textbox your web site’s name or URL and make sure that “Deliver to: Email” is checked. Then click again “Set Up Alerts” and repeat the procedure if you want more alerts. Finally click on “Done” to confirm and check what you’ve done.

Google
First go to Google Alerts and log in with your account (or create a new if you don’t have one). Insert you web site’s name or URL into “Search terms” textbox, select the appropriate values for the listboxes and click “Create Alert”.

And a useful tip (and a smart move for SEO) for the end of this post.

You can create an alert including your desired keywords (for which you want to rank high in search engines) with the addition of your web site’s name excluded, i.e. preceded by a minus sign like: “-websitename”. With this technique you can monitor for web pages relevant to yours but not mentioning yours!

For example, let’s say your site’s URL includes the word “helkin” [shameless plug to one of my sites about Greek cinema :-)] and you want to rank high with keywords “Greek cinema”. Using the tip above, you should create an alert to monitor for pages using the query: “greek cinema -helkin” (without the double quotes).

The SEO comes when you can add your URL, either as a new catalog entry (if the found page is a catalog) or a blog comment (if it’s a blog), for every new catalog or blog found about Greek cinema! Talking about self-promoting…


Visit The Light of the LAMP blog for more…

HTML validators

Producing valid HTML pages can be a difficult task. But since every web page has to obey some rules (a.k.a. standards), its structure can be validated either by the excellent W3C Markup Validation Service (free online service) or by using some browser extensions.

There is a very helpful extension for Firefox called HTML Validator, which validates each page by using W3C Tidy. A little icon at the lower right corner of Firefox shows the result for each page and it can be in one of three states: Valid, Warning, Error. Double-clicking on the icon reveals the source of the page, highlights any lines/tags with warnings/errors and provides the option to “Clean up the page…”

Another highly recommended extension for Firefox is the Web Developer extension which, among many other things, eases the validation process for HTML pages, CSS (cascading style sheets), links and feeds.


Visit The Light of the LAMP blog for more…

PHP web-based resources

For a PHP programmer, I can recommend two web-based resources, full of useful information.

  • PHP Classes has a vast amount of useful PHP packages in source code with examples.
  • Chris Shiflett is a blogger who writes on advanced topics about PHP programming.

Both sites have RSS feeds and are updated frequently with new stuff.


Visit The Light of the LAMP blog for more…

Environmental issues (part 2)

When working a lot with command line utilities, I usually find myself retyping certain commands. This fact is a good reason for someone to use aliases to save typing time and errors.

At first we have to check our most loved/typed commands. This can be done using:

history | cut -c 8- | sort | uniq -c | sort -nr | head -20

in order to show the 20 most frequently used [1]. Of course, the above commands combination must be an alias too [2].

After analyzing the output, we can decide which commands could be substituted by aliases, insert them in the ~/.alias file and use them after we “source” it [3].

References:
[1] Explanation of the commands used:

  • history: show the last commands entered
  • cut -c 8-: cut the first 7 characters from each line of “history” output (cut off the number)
  • sort: sort the commands alphabetically
  • uniq -c: count same commands in a frequency table
  • sort -nr: sort the frequency table by descending counts
  • head -20: show only the first 20 lines

[2] alias hist_top20=’history | cut -c 8- | sort | uniq -c | sort -nr | head -20′ >> ~/.alias
[3] after editing ~/.alias, `source ~/.alias`


Visit The Light of the LAMP blog for more…

Environmental issues (part 1)

As a developer, I prefer working with command line utilities. That’s why I have devoted my first workspace area to an almost full-screen sized terminal window (I prefer gnome-terminal, although I’m working with KDE and konsole is just as good to work with) comprising of 3 or more tabs.

I want the first tab to always open mutt (the e-mail client that does almost everything), the second one to change to my most recent project’s directory (where I can edit the source files with vim — tabbed, using “vim -p”) and make a backup of the project’s database, the third to check some log-file, and the list goes on.

So, what’s the best way to automate these procedures?

Currently I’m using the output of the “tty” command and a case statement at the end of my ~/.bashrc file (comments included):


# show me from where I logged in
echo Logged in from $(tty)
case "$(tty)" in
"/dev/pts/1")
# run mutt
mutt
;;
"/dev/pts/2")
# first change directory
cd ~/projects/projectName
# then perform a quick database backup
make back
;;
"/dev/pts/3")
# show me web visits, ignoring some of them based on certain criteria
tail -f /var/log/apache2/access.log | egrep -v "localhost|127.0.0|/(Thumb|images|Photo)/|favicon"
;;
esac

With arrangements like the above, one can “feel like home” by just logging in!


Visit The Light of the LAMP blog for more…

bash: quickly rename files

Since one cannot always have the tools she likes, here are some one-liners to rename certain files using only bash.
Rename all ‘jpeg’ files to ‘jpg’:

  • for a in *.jpeg; do mv $a ${a%jpeg}jpg; done

Remove the ‘photo-‘ prefix:

  • for a in photo-*; do mv $a ${a/photo-}; done

Rename ‘dsc’ prefix to ‘photo-‘:

  • for a in dsc*; do mv $a ${a/dsc/photo-}; done

Where can I find these recipes?
man bash 🙂


Visit The Light of the LAMP blog for more…

PHP: function is_me()

A very useful function to determine first if the visitor is the developer or not and then act accordingly.

Code:

/* check if client is me */
function is_me()
{
$ip=$_SERVER["REMOTE_ADDR"];
$br=$_SERVER["HTTP_USER_AGENT"];
if (($ip=="127.0.0.1") and (strstr( $br, "Firefox")))
return true;
return false;
}

Explanation:
If the visitor’s IP is 127.0.0.1 (=localhost) and the browser is “Firefox” then the visitor is me!

Usage example:

if (is_me()) { error_reporting( E_ALL); } else { error_reporting( 0); }

With the above snippet, one developer can check for errors and warnings in a running system without the casual visitor noticing a thing. It is very easy also to view the web-page with another browser to check what the visitor actually sees.


Visit The Light of the LAMP blog for more…