^ ^

13 09 2010

Happy Programmer’s Day! 🙂





Get Twitter Status with JSON

13 08 2010

$url = 'http://twitter.com/statuses/user_timeline/phoenixblue.json?count=10';
$url_content= file_get_contents($url,0,NULL,NULL);
$statuses = json_decode($url_content);
//var_dump($statuses);
echo $statuses[0]->text;





Delete all Orders

2 08 2010

Magento version 1.4.1.1
In Database,

SET FOREIGN_KEY_CHECKS = 1;
DELETE FROM sales_flat_order;
DELETE FROM sales_flat_quote;
DELETE FROM eav_entity_store;





Reset Auto-Increment

2 08 2010

Mighty useful for deleting test data!

ALTER TABLE table_name AUTO_INCREMENT = 1;





CSS Rotation

1 08 2010

Safari/Chrome
-webkit-transform: rotate(90deg);

Firefox
-moz-transform: rotate(90deg);

IE
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);





Truncate Whole Words

1 08 2010

function trunc($phrase, $max_words)
{
$phrase_array = explode(' ',$phrase);
if(count($phrase_array) > $max_words && $max_words > 0) {
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...' ;
}
return $phrase;
}





Get Twitter Statuses With curl()

1 08 2010

function get_twitter_status() {
  $status_list = array();
  $c = curl_init();
  curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/phoenixblue.xml?count=10");
  // count = number of statuses to grab
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($c, CURLOPT_CONNECTTIMEOUT, 20);
  curl_setopt($c, CURLOPT_TIMEOUT,5);
  $src = curl_exec($c);
  $xmlList = new SimpleXMLElement($src);
  foreach($xmlList->status as $xml) {
    $text = (string)$xml->text;
    $status_list[] = $text;
  }
  if(count($status_list) $status_list[] = $xmlList->error;
  return $status_list;
}





Problems With Magento Installation

1 08 2010

Problem 1. Installing MCrypt on Mac
Mac OS X comes with pre-installed PHP which needs to be switched on and most likely updated to the latest version of PHP which is simple enough however installing MCrypt is a major pain. After spending 2 hours on this, I think the best thing to do is to use MAMP instead. Comes with Apache, PHP and MySQL.. SWEET!!!

Problem 2. Can’t log into admin
So Magento is installed on the localhost and now I can’t log into admin..

There are lots of workaround like changing the Varien.php file if you google this however they didn’t work for me so..

Please uninstall and make sure you reinstall Magento on http://127.0.0.1 instead of http://localhost/





Escape special characters in SQL statement

1 08 2010

mysql_real_escape_string(string,connection)

$user = mysql_real_escape_string($user);
$pwd = mysql_real_escape_string($pwd);
$sql = "SELECT * FROM users WHERE user='" . $user . "' AND password='" . $pwd . "'"





Change Last Modified Header

1 08 2010

At the top of the file in php tags:

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");