Skip to content

Instantly share code, notes, and snippets.

@shameerc
shameerc / array_filter.php
Created December 26, 2010 08:03
Array filter function using lambda function
<?php
$time = array('morning', 'noon');
array_filter($time, function($a){
if($a=='noon')
echo 'Its lunch time';
else
echo "Its time for breakfast";
}
);
?>
@shameerc
shameerc / stream_post.php
Created December 21, 2010 10:36
Post using streams
<?php
$data = array ('name' => 'hello', 'email' => 'hello@hello.com');
$data = http_build_query($data);
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
@shameerc
shameerc / debug_backtrace.php
Created December 14, 2010 09:06
Simple usage of debug_trace() function
<?php
echo "<pre>";
print_r(array_reverse(debug_backtrace(true)));
echo "</pre>";
?>
@shameerc
shameerc / Application.php
Created December 11, 2010 08:54
Simple plugin system using Reflection api
<?php
/**
* Application class
*
* @author Shameer
*/
class Application {
private $plugins = array();
public function __construct() {
// Constructor
@shameerc
shameerc / validate_email.php
Created December 10, 2010 05:47
Simple email valiation
<?php
// This function uses simple filter_var function
// instead of regular expression to validate email
// @param string email Email address to be validated
function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
?>
@shameerc
shameerc / ie_hack.css
Created December 7, 2010 10:42
Css hacks for IE
div.example {
width: 300px; /* applied in all browsers */
*width: 350px; /* applied to IE6 and IE7 only */
_width: 360px; /* applied to IE6 only */
}
@shameerc
shameerc / simple_labda.php
Created December 2, 2010 04:04
basic example for lambda function
<?php
$sum = function($a,$b){
return $a+$b;
};
echo $sum(2,5);
?>
@shameerc
shameerc / pdo_conn_select.php
Created November 10, 2010 07:24
PHP Pdo class
<?
$dsn = 'mysql:dbname=test;host=hostname';
$user = 'username';
$password = 'Password';
try {
$dbh = new PDO($dsn, $user, $password);
echo "Connected";
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
@shameerc
shameerc / gist:662115
Created November 4, 2010 04:02
Avoid double encoding special characters
//Use the fourth argument as false
echo htmlentities($foo, ENT_COMPAT, 'UTF-8',false);
if(navigator.appName=="Microsoft Internet Explorer" ) {
return false;
}
else {
return this.init(canvasId,displayRadius,skinId,showSecondHand,gmtOffset);
}