This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Small, free, weather web-service using Yahoo APIs that don't require an API key. | |
*/ | |
// Fetch zip code | |
$location = isset($_GET['location']) ? $_GET['location'] : 'Tempe,AZ'; | |
// Use YQL to get the WOEID by the location | |
$query = 'select * from geo.places where text="'.$location.'"'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Thanks for the help Zeelot | |
// Admin Route | |
Route::set('admin', 'admin(/<controller>(/<action>(/<id>)))') | |
->defaults(array( | |
'directory' => 'admin', | |
'controller' => 'account', | |
'action' => 'login', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Uses Kohana 3 Framework | |
function time_ago($timestamp) | |
{ | |
$time_ago = Date::span($timestamp); | |
foreach ($time_ago as $unit => $value) | |
{ | |
if ($value > 0) | |
{ | |
return 'about '.$value.' '.Inflector::singular($unit, $value).' ago'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds a hasEvent() function for jQuery objects. | |
// Example: var hasClickEvent = $('a.add').hasEvent('click'); | |
(function($){ | |
$.fn.hasEvent = function(eventType){ | |
var events = this.data("events"); | |
return (events && events[eventType]); | |
}; | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Demonstrating how the presence of __isset() method affects accessing object members | |
class Person implements ArrayAccess { | |
protected $_data = array(); | |
public function __construct($first_name, $last_name) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
// Extending Auth to support user impersonation functions | |
class Auth extends Kohana_Auth { | |
public function impersonate(ORM $user) | |
{ | |
if ( ! $user->loaded()) | |
throw new Exception; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Code Golf: Return a number with its ordinal suffix (eg. 31 -> 31st) | |
error_reporting(E_ALL ^ E_NOTICE); | |
function ordinal($n) | |
{ | |
return($n%=100)>10&&$n<14?th:date(S,mktime(0,0,0,0,$n%10,0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // This script is an example of how you can find the last item in a non-branching inheritance hierarchy | |
// Declaring classes | |
class food {} | |
class cheese extends food {} | |
class cheddar extends cheese {} | |
class white_cheddar extends cheddar {} | |
// Finds the last child in a non-branching inheritance hierarchy | |
function get_last_child($parent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Singleton | |
{ | |
public static function instance() | |
{ | |
static $instance; | |
$class = get_called_class(); | |
return $instance ?: ($instance = new $class); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // PHP has a ArrayAccess interface, why not an ObjectAccess interface? | |
interface ObjectAccess | |
{ | |
public function __isset($key); | |
public function __get($key); | |
public function __set($key, $value); | |
public function __unset($key); | |
} |
OlderNewer