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 | |
// Full documentation: | |
// http://php.net/manual/en/function.date.php | |
// Set timezone to avoid PHP warning | |
date_default_timezone_set( 'Europe/London' ); | |
date_default_timezone_set( 'Europe/Madrid' ); | |
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 | |
/** | |
ABUSE CHECK | |
Throttle client requests to avoid DoS attack | |
*/ | |
session_start(); | |
$usage = array(5,5,5,5,10,20,30,40,50,60,120,180,240); // seconds to wait after each request | |
if (isset($_SESSION['use_last'])) { | |
$nextin = $_SESSION['use_last']+$usage[$_SESSION['use_count']]; |
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
The formula for calculating the Top Rated 250 Titles gives a true Bayesian estimate: | |
weighted rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C | |
where: | |
R = average for the movie (mean) = (Rating) | |
v = number of votes for the movie = (votes) | |
m = minimum votes required to be listed in the Top 250 (currently 25000) | |
C = the mean vote across the whole report (currently 7.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
$.ajax({ | |
type: "POST", | |
url: "some.php", | |
data: { name: "John", location: "Boston" } | |
}) | |
.done(function( data ) { | |
data = $.parseJSON(data); | |
console.log(data); | |
}) | |
.fail(function( jqXHR, textStatus ) { |
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
function abbreviate_number($num) { | |
if ($num >= pow(10,3) AND $num < pow(10,4)) { | |
return round($num/1000, 1).'k'; | |
}else if ($num >= pow(10,4) AND $num < pow(10,5)) { | |
return round($num/1000, 1).'k'; | |
}else if ($num >= pow(10,5) AND $num < pow(10,6)) { | |
return round($num/1000, 0).'k'; | |
}else if ($num >= pow(10,6) AND $num < pow(10,7)) { | |
return round($num/1000000, 1).'m'; | |
}else if ($num >= pow(10,7) AND $num < pow(10,8)) { |
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 | |
protected function nice_time($timestamp) { | |
if ( !$timestamp ){ | |
return ''; | |
} | |
// if no timestamp, do it now | |
if ( !is_numeric($timestamp) ){ $timestamp = strtotime( $timestamp ); } | |
// $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); | |
$periods = [$this->_("second"), $this->_("minute"), $this->_("hour"), $this->_("day"), $this->_("week"), $this->_("month"), $this->_("year"), $this->_("decade")]; |
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 | |
// Config | |
define('MYSQL_SERVER', 'localhost'); | |
define('MYSQL_DATABASE', 'database'); | |
define('MYSQL_USER', 'root'); | |
define('MYSQL_PASS', 'pass'); | |
// MySQLi class method |
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 | |
define('DEBUG', in_array($_SERVER['HTTP_HOST'], array('127.0.0.1', 'localhost')) ); | |
if (DEBUG==false) { | |
// PRODUCTION SEVER | |
error_reporting(0); | |
define('APP_URL', 'http://www.example.com/'); | |
define('MYSQL_SERVER', 'localhost'); // |
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 | |
$lang = array( | |
'createaccount' => 'Create Account', | |
'welcome' => 'Welcome %s!', | |
// ... | |
); |
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
/** | |
* This version uses Date to detect cooldown | |
* Much better performance than with Timer | |
*/ | |
var cooldownTime = 2000, // ms | |
nextRun = null; | |
function run() { | |
// Your code here |