This is a Clog, or Code Log
I'll stick random explanations, code snippets etc. here.
| Displaying the temperature in your BASH prompt 05-08-2007 |
Problem:
You need to know the temperature outside before you open the front door.
Now, you could do this in one step, by putting the command to grab the temperature straight into your bash profile, but there can be delays caused by waiting for the web-page to load. So what I do is to have the script below running in a cron-job, writing the temperature to a file in my home directory, then when I go into the console, all the hard-work's done and it just has to concentrate on displaying the value.
First Part:
Script to screen-scrape temperature...
#!/bin/bash
#single-liner to grab a web-page and scrape the temperature into a file in ~/
wget -q -O - http://weather.noaa.gov/weather/current/EGKB.html | grep ' C)' | head -n 1\
| sed 's/.*(\([[:digit:]]*\).*)$/\1/' > ~/temperature.txt
The website I get the temperature from is http://weather.noaa.gov. Browse through to find the direct link to your nearest airport/airfield wherever you are in the world and use it instead of EGKB.html (Biggin Hill). The script should continue to work, no matter where you are in the world.Copy the above script into /usr/local/bin, make it executable and then append the following lines to your crontab:
# Run temperature.sh every 5 minutes.
*/5 * * * * /usr/local/bin/temperature.sh prompt >/dev/null
Second Part:
Meat and potatoes to show the colour-coded temperature in your prompt...
(My bash prompt also displays the current time, the current working directory and the logged-in user name.) If you want to parse out those bits, consult a tutorial and decipher the PS1 environment variable. The temperature is on the first line of the PS1.
TEMPERATURE=`less ~/temperature.txt`
TEMPTHRESHOLD=20
COLOUR_LOW='1;34'
# light blue
COLOUR_HIGH='1;31'
# light red
if [ $TEMPERATURE -gt $TEMPTHRESHOLD ]
then
TEMPCOLOUR=$COLOUR_HIGH
else
TEMPCOLOUR=$COLOUR_LOW
fi
export PS1="\[\033[\$(echo -n \$TEMPCOLOUR)m\][Temperature \$TEMPERATURE C]\[\033[0m\]\
\[\033[1;32m\][\$(date +%T) $(date +%d-%B-%y)]\
\[\033[1;31m\][\$(pwd)]\[\033[0m\]\n\
\[\033[1;34m\][\u@\h]\\$ \[\033[0m\]"
And the final result:

|
| Redirecting based on referrer URL using PHP 15-06-2007 |
Problem: Google searches for something unsavory point to your website and you want to redirect those visitors somewhere else.
E.g.:http://www.google.com/search?q=keyword
Solution:Redirect any request with the keyword in the referer URL to another site.
<?php (...)
$referTo = array("http://www.google.com/search?safe=off&q=inslovency",
"http://www.google.com/search?safe=off&q=%22duplicituos%22");
if(isset($_SERVER['HTTP_REFERER'])){
if (eregi('keyword', $_SERVER['HTTP_REFERER'])
|| eregi('keyword2', $_SERVER['HTTP_REFERER']) ){
header("Location: ".$referTo[array_rand($referTo)]);
exit;
}
}
?>
The above example uses an array and randomises the URL it redirects to. Code is free to use under the GPL v2 or later.
|
| Adobe Flashplayer 9 for Linux crashes Firefox 03-06-2007 |
I recently repaired my dead PC after *several* RMAs of my motherboard to Asrock. I browsed to Youtube and was told that I was missing the latest Flashplayer plugin. After installing the plugin manually in Firefox 1.5.*, navigating to any site that used flash caused Firefox to summarily exit with a Fatal exception.
I then upgraded Firefox to 2.0.0.4, just in case that was at fault, I deleted and re-installed the Flashplayer 9 plugin both manually and using the "Install plugin now" button, and still it crashes.
The only way to get round this that I've found is to revert to version 8 of Flash player. Adobe, very unhelpfully only distributes old versions of Flashplayer for Windows and Mac and not Linux. So make sure you back up your version 8 libflashplayer.so and flashplayer.xpt from your plugins directory!
|
| Adam's Tab Renamer 21-08-2006 |
The first two releases of Adam's Tab Renamer (or ART) are here. Both allow you to rename a tab to any arbitrary string you care to. I haven't thoroughly tested for bugs, but neither have I found any obvious showstoppers. All code is released under the GNU GPL v2.
I wrote it because I use MS Sharepoint at work which doesn't use (or isn't set up to use) sensible titles for a lot of pages and I wanted to be able to see at a glance what was what. The extension is still in it's earliest stages and unless you go through the steps below, when the tab is reloaded, the name you gave it will be lost.
To make the changes to a tab name permanent:
./ Follow the instructions here to run Firefox from it's constituent files instead of the .jar files.
./ Next, go to /.../chrome/content/global/bindings, where /.../ is the path to your firefox installation (on my machine it's /usr/lib/firefox-1.5.0.1/).
./ In this file, search for instances of "aTab.label=" and replace whatever's after the equals sign with "aTab.label". Or comment them out. Whatever.
On GNU/Linux, you should be able to use this patch to effect these changes. The patch is called "crippletabbrowser.patch" for a reason, if you navigate somewhere else in a tab, the name will stay on what you previously set. You may not want this...
|
| Remove Hotmail's "Remember Me" Radio button 20-01-2006 |
Are you fed up of people logging into hotmail on your machine and leaving the "remember me" radio button selected? Want to stop this?
Get the chromEdit extension for Firefox. Restart firefox, goto Tools > Edit User Files and then select userContent.css.
Add this line to the bottom:
.css0146{
display:none !important;
}
"css0146" is the class name of the table cell where the options are. It tells the browser not to display anything in it, and the "!important" bit makes sure the user css file takes preference. Beware, if you visit another site that uses "css00146" as a class name, it will destroy that too!
Restart Firefox, and browse to hotmail.com and the options disappear! Perhaps this is obvious, but you need to sign in with "Never remember me" toggled before you do this, otherwise you'll have no way to change it :o)
|
|
|