All Blogs | Help
Archives
September 2010 (1)
March 2010 (1)
January 2010 (1)
November 2009 (1)
July 2009 (1)
January 2009 (3)
December 2008 (1)
Sections
Code Tutorial (4)
Misc (2)
QRCode Button (1)
Server Admin (2)
Os
Debian (1)
Code Tags
PHP (3)
Mysql (1)
Bash (1)
Tools
Show/Hide Keys
9th September 2010 @ 22:33
Code Tags: PHP
So I may be a bit late to the party, but I have now created by first GitHub project. For my project I decided to actually finish my MQTT class.

I have posted it at http://github.com/bluerhinos/phpMQTT

At the moment the publishing part works a treat, but there currently a problem with the subscribe part (hangs after about 3 hours) I am trying to trace the fault. Also at the moment it will only support quality of service (qos) of 0.

Example Publishing:
php code:
require("../phpMQTT.php");
$mqtt = new phpMQTT();
/* broker(broker address, broker port, client id); */
$mqtt->broker("example.com", 1883, "PHP MQTT Client");
$mqtt->connect();
/* publish( topic, message, qos); */
$mqtt->publish("bluerhinos/phpMQTT/examples/publishtest","Hello World!",0);
$mqtt->close();
26th March 2010 @ 21:47
Code Tags: bash
I needed to keep my GeoIP db up to date for my stats package so I decided to write a cron script that would do it for me.

bash code:
#!/bin/bash
 
#############################################################
# ./geoipupdate = Auto updates the free GeoIP databases
# (c) andrew[at]bluerhinos.co.uk 2010 : Creative Commons
#############################################################
 
#list of urls
URLS=" http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"
URLS="$URLS http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"
 
#target directory
TARGETDIR="/var/lib/GeoIP"
 
for URL in $URLS
do
wget -q -N -P "$TARGETDIR" "$URL"
BASENAME=`basename "$URL"`
gunzip -f "$TARGETDIR/$BASENAME";
done
 


Place the above code (or download here http://blogs.bluerhinos.co.uk/data/files/9/geoipupdate ) into /etc/cron.monthly/geoipupdate

Note: they update their db on the 1st or 2nd so I changed my /etc/crontab so that the monthly scrips run on the 3rd
25th January 2010 @ 23:06
If you are like me, you dislike the .php extension for web pages that display content, eg /contactus.php . To me this is a web page that is displaying HTML, so lets give it an .html suffix. but the easist way to implements templates is to use html.

To achieve this easily just create a .htaccess file to redirect .html's to .php.
.htaccess code:
 
RewriteEngine On
RewriteRule (.*).html $1.php [QSA]
 
(The QSA just forwards all variables to the .php script)
Requirements: are apache and mod_rewrite
More Info: http://www.kuro5hin.org/story/2003/7/31/2335/08552
28th November 2009 @ 23:23
Code Tags: PHP
I was working on a project that needed to list the Beaufort wind force. The first attempt was to do a lookup based function using the data here: http://en.wikipedia.org/wiki/Beaufort_scale

Attempt 1
php code:
function beaufort_scale($speed, $unit="m/s"){
 
$units['m/s'] = 1;
$units['kph'] = 1/3.6;
$units['mph'] = 0.44704;
$units['kts'] = 0.514444444;
 
if(!in_array($unit,array_keys($units))){
return "Error: couldn't recognise unit";
}
 
$speed *= $units[$unit];
 
$scale = array(0.3,1.5,3.4,5.4,7.9,10.7,13.8,17.1,20.7,24.4,28.4,32.6,1000);
 
foreach($scale as $key=>$val){
if($speed <= $val) return $key;
}
return 'Error';
}

I then noticed on the wikipedia page the scale's empirical formula
so i thought i could improve the function ;)
v = 0.866 * B3/2 (units m/s)



Attempt 2
php code:
function beaufort_scale($speed, $unit="m/s", $rnd=0){
 
$units['m/s'] = 1;
$units['kph'] = 1/3.6;
$units['mph'] = 0.44704;
$units['kts'] = 0.514444444;
 
if(!in_array($unit,array_keys($units))){
return "Error: couldn't recognise unit";
}
 
$speed *= $units[$unit];
 
$scale = pow(($speed/0.836),(2/3));
 
return round($scale,$rnd);
}
This one has the added ability of returning a decimal answer
29th July 2009 @ 08:44
Os: Debian
Oh and it has to be stable ish.

Yesterday I had to try and get php-ffmpeg and x264 enabled ffmpeg to sit side by side each other on a Debian Lenny install. The problem is that debian's ffmpeg that ships in the lenny package tree is not 264 enabled. But when you use the ffmpeg from debian-multimedia it breaks the installed php-ffmpeg.

So I suggest you do this:

Start With vanilla debian install

Install your php, apache, php-ffmpeg etc

Then add your debian-multimedia.org as a apt source.

Then follow these instructions
http://tovid.wikia.com/wiki/Installing_svn_ffmpeg_on_a_Debian_based_distro
(I have attahed a pdf of the page incase its not there when you read this, Data: Instruction for compiling ffmpeg

Happy Hunting