Doug


http://www.dougmolineux.com/wp

Check out the new blog!

Advertisements
Posted in Uncategorized | Leave a comment

RSS Feed for Godaddy Users


Another barrier that Godaddy kindly puts up between their users and functionality is that they restrict the use of the PHP function file_get_contents. The only way that I got around this was to use CURL which has been surprisingly left wide open. This quick script curls Yahoo’s Weather API and dumps the response into a variable called $xml:

$url = ‘http://weather.yahooapis.com/forecastrss?w=2504615’;

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_DNS_USE_GLOBAL_CACHE, FALSE);
$buffer = curl_exec($curl_handle);
$error = curl_error($curl_handle);
curl_close($curl_handle);
if (empty($buffer)) {
echo ‘Something went wrong 😦 error: ‘.$error.”;
}

$xml = simplexml_load_string($buffer);

?>

Posted in CURL, PHP, RSS, XML | Tagged , , , , , , | Leave a comment

Moved


We have officially moved to

http://www.dougmolineux.com/wp

Posted in Uncategorized | Leave a comment

CSS3 Border Radius and Rotate


First of all, this website is really useful when deciding how big you want your border radius to be, it also takes into account webkit and Mozilla flavors of browser. Here’s some CSS3 which allows a rounded edge on your divs:

-webkit-border-radius: 99px;
-moz-border-radius: 99px;
border-radius: 99px;

Also, there is also a rotate property introduced in CSS3 which can be really useful. I had a project where I needed a vertical progress bar and couldn’t find anything useful, so I just used this rotation ability and used a normal jQuery horizonal one! Here’s the code, the last line will let it work on the infamous IE6!

-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
transform: rotate(-90deg);
position: absolute;
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

Posted in CSS | Tagged , , , , | Leave a comment

Tar up directory in Linux


To tar a file is basically the same as zipping a file in Windows. This is a Linux/unix command which will tar an entire directory (called cps100) into a tgz file called foo.tgz:

tar cvzf foo.tgz cps100

And to get everything back out of the tarball you use this command:

tar -xvf foo.tgz

Don’t forget about the tab auto-complete! Very useful when traversing bash 🙂

Posted in Linux | Tagged | 1 Comment

Weather RSS Feed For PHP 4


Here is a quick example of how to pull out specific weather information from Yahoo’s Weather API using PHP 4’s xml_parser, it should be pointed out that PHP 5’s Simple XML utilities are much easier to use and to understand, but some of us are stuck on a godaddy server with PHP 4 🙂 and the client is unwilling to upgrade. It should also be mentioned that this array is dependent on the numbered index that the extracted array creates, if the API decides to alter the structure of the array then you’ll need to re-print $vals and find the key you want.

<?php $data = file_get_contents(“http://weather.yahooapis.com/forecastrss?w=2504615&#8221;);
$parser = xml_parser_create(‘UTF-8’);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $vals, $index);
xml_parser_free($parser);

echo $vals[28][“attributes”][“DAY”];
echo ” “.$vals[28][“attributes”][“DATE”];
echo ”

High: “.$vals[28][“attributes”][“HIGH”];
echo ” Low: “.$vals[28][“attributes”][“LOW”].” F”;
echo ”

“.$vals[28][“attributes”][“TEXT”];

?>

Posted in PHP, RSS, XML | Tagged , , , , , | Leave a comment

CodeIgniter’s Ridiculous GET Variable Conumdrum


Sometimes it can be ridiculously hard to grab GET Variables from the URL using CodeIgniter (like this thread emphasizes), so here’s a snippet which manually parses out the URL and grabs all the key value GET variables into an array called splitGet:

$geturl = $_SERVER[‘REQUEST_URI’];
$spliturl = explode(“?”,$geturl);
$getVars = explode(“&”,$spliturl[1]);
foreach($getVars as $key => $value)
{
$splitGet = explode(“=”,$getVars[$key]);
}

Posted in CodeIgniter, PHP | Tagged , , | Leave a comment

Google’s JQuery Include Script


Here is the link to the Google-hosted JQuery JS. Google *hardly* ever goes down. It is very useful to quickly include this in your web files, however it must be pointed out that, you can go to this URL, download the file, upload it to your server and then you don’t have to rely on somebody elses server even if it is Mighty Google. Here it is nevertheless:

http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

Posted in Javascript, JQuery | Tagged , , , , , | Leave a comment

Remove a Single Row from MySQL Table


I was looking for this snippet myself today, and I was surprised I haven’t included it on here! This snippet allows you to Delete one row from a MySQL table, the LIMIT 1 is just to make sure it only deletes one, if your ID’s are auto-incrementing though, there should only be one entry:

$removeRow = “DELETE FROM usertable WHERE id='”.$_GET[“delete”].”‘ LIMIT 1″;
mysql_query($removeRow) or die (mysql_error());

Also, this query is assuming that there’s a GET variable called “delete” in the URL, such as:

http://myserver.net/test.php?delete=5

Where the user deleted will be the user that has an ID of 5.

Posted in PHP & MySQL | Tagged , | Leave a comment

NSLog a UIImageView in XCode for IPhone SDK


Here’s my first IPhone Code Snippet, which I found to be useful. I had a button action which changed the image of a UIImageView but I was having problems. I needed to make sure that the UIImageView was connected properly to myUIImageView that I had created in the Interface Builder. At first, the log was printing:

(null)

So I knew that it was not being set properly. I opened Interface Builder and I realized that it wasn’t connected so I connected it and it worked! Here’s the code which logs the UIImageView object:

myUIImageView.image = [UIImage imageNamed:@”image.jpg”];
NSLog(@”%@”, myUIImageView);

Here are the results from the log when myUIImageView is successfully defined.

<UIImageView: 0x5f1b320; frame = (0 -10; 320 470); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x5f18840>>

Posted in IPhone SDK, Objective-C | Tagged , , , | Leave a comment