Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / array_filter_closure.php
Created December 27, 2010 17:37
Basic example for create_function()
<?php
$array = array(1,2,3,4,5);
$v= 4;
$result = array_filter($array,function($n) use(&$v){return $v === $n;});
print_r($reslt);
?>
@shameerc
shameerc / mysql_prepared_functions.php
Created January 1, 2011 05:41
This is a part of mysqli class for prepared statements
<?php
/**
* @param mixed $query Query to be prepared for executing
* multiple times
* Usage "SELECT * FROM table_name WHERE column = ? "
* "INSERT INTO table_name(field1,field2) VALUES(?,?) ";
* returns true if the query is a valid mysql statement else throws an
* exception
*
*/
@shameerc
shameerc / qr_code.html
Created January 14, 2011 09:03
jQuery code to generate qr code for links
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.qr = function(){
var url = $(this).attr('href');
var size= 4;
return 'http://qrcode.kaywa.com/img.php?s='+size+'&d='+url;
};
@shameerc
shameerc / tiny_mce.js
Created January 19, 2011 12:08
tinyeditor getcontent of active editor
tinyMCE.activeEditor.getContent()
<?php
class Controller_Foo extends
{
public function action_foo()
{
$ext_response = Request::factory('http://site.com/foo/bar/bas')
->execute()
->response;
}
@shameerc
shameerc / sample.php
Created January 22, 2011 08:21
Example of a kohana configuration file
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Sample extends Controller
{
public function action_index()
{
$testConfig = Kohana::config('test');
}
}