A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Category Archives: Uncategorized

Linode!

Migrated everything to Linode now.

Posted in Uncategorized | Leave a comment

Getting the Bayesian Average for rankings (PHP / MySQL)

When you need to correctly display the leader-board based on ratings, you can’t just display the average rating for each entry. ———————————— Restaurant A | 1 Vote(s) | Rating 10 ———————————— Restaurant B | 3 Vote(s) | Rating 6 | … Continue reading

Posted in Uncategorized | Leave a comment

CakePHP Facebook Component

A simple CakePHP component that uses the Facebook PHP SDK (https://github.com/facebook/facebook-php-sdk). Setup the component like this: public $components = array( ‘Facebook’ => array( ‘appId’ => ‘xxx’, ‘secret’ => ‘xxx’, ‘cookie’ => true, ‘fileUpload’ => 1, ‘canvas’ => 1, ‘fbconnect’ => … Continue reading

Posted in Uncategorized | Leave a comment

Facebook Page Tab: Remove scrollbars and auto-resize height

I have come across many ones, but this one always worked for me without problems. CSS html, body { overflow: hidden; } Put this just after the tag: <div id="fb-root"></div> Put this after you have jQuery and other libraries loaded. … Continue reading

Posted in Uncategorized | Tagged | Leave a comment

Twitter: Get tweets from User Timeline with API 1.1 (PHP)

This code is from http://stackoverflow.com/q/12916539/66767 combined with http://stackoverflow.com/a/15387732/66767 to auto-link URLs and hashtags. Quick and dirty… copy and paste below! <?php function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach($params as $key=>$value){ $r[] = "$key=" . rawurlencode($value); } return … Continue reading

Posted in Uncategorized | Leave a comment

Setting up File Uploader / FineUploader Basic with CakePHP

The configuration: <?php // app/Config/core.php Configure::write("App.SITE_URL", ‘http://www.mysite.com’); Configure::write("App.UPLOAD_PATH", ‘/usr/local/www/vhosts/mysite.com/httpdocs/app/webroot/uploads’); //no trailing slash Configure::write("App.UPLOAD_PATH_URL", ‘http://mysite/uploads’); //no trailing slash The setting up the .json and .txt extensions in the routes file. I need the txt. This is because Internet Explorer does not … Continue reading

Posted in Uncategorized | Leave a comment

CakePHP: Disabling the Security Component for Specific Actions in a Controller

Sometimes, I need to disable the Security component for certain actions in the controller. For example, if I need to handle FineUpload. If I do not disable the Security component, I get a “request has been blackholed” error. <?php class … Continue reading

Posted in Uncategorized | 1 Comment

CakePHP: Select Box / Drop-down List linked from related Model

For example, an Article has an Author. In the database, the Article table would have an author_id field. Assuming that we are following the CakePHP Model and Database Conventions (http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html#model-and-database-conventions), the models would look something like these: <?php ## /Model/Article.php … Continue reading

Posted in Uncategorized | Leave a comment

CakePHP: Displaying images that are outside the public accessible directory (webroot) using Media Views

Let’s say that Configure::read(‘App.uploads_temp’) is somewhere outside the public accessible directory: /var/www/yourapp/private //This goes into the controller /** * @param $filename A filename without the path. EG: default-guy.jpg */ public function downloadimage($filename) { $file_parts = pathinfo($filename); $this->viewClass = ‘Media’; $params … Continue reading

Posted in Uncategorized | Leave a comment

Some useful Knockout.JS examples from my JSFiddle

I am learning Knockout.js Accessing an observable array outside the foreach loop from the HTML http://jsfiddle.net/wenbert/MEKLN/ Setting a default / selected option in a Select box http://jsfiddle.net/wenbert/ZpGeS/ Working with child models http://jsfiddle.net/wenbert/Ev8H6/ Thanks to the guys at Stackoverflow and #javascript … Continue reading

Posted in Uncategorized | Leave a comment