Skip to content

Instantly share code, notes, and snippets.

@shameerc
shameerc / date_formater.php
Created May 21, 2011 11:02
This can be used in formating date if the given format is smarty specific
<?php
public function formatDate($date, $dateFormat='', $timeFormat='')
{
$_dateMap = array ( '%B %e, %Y'=> 'F d, Y',
'%A, %B %e, %Y' => 'l F d, Y',
'%m/%d/%Y' =>'m/d/Y',
'%d/%m/%Y' => 'd/m/Y'
);
@shameerc
shameerc / Model_User.php
Created May 20, 2011 18:19
Files used in ajax validation
<?php
class Model_User extends Model {
/**
*
* Define the array of rules to be validated against
* the signup information
* @return array rules
*/
public function rules() {
@shameerc
shameerc / js_regex_price.js
Created March 21, 2011 05:49
To replace number in a string with another number
function numberReplace(s,d) {
return s.replace (/\.?\d[\d.,]*/, d);
}
alert(numberReplace('25 $',12));
@shameerc
shameerc / parsJSON.js
Created March 12, 2011 02:10
Prse json and dynamic property names
var obj = $.parseJSON(msg);
for(var key in obj){
alert(obj[key]);
}
@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');
}
}
<?php
class Controller_Foo extends
{
public function action_foo()
{
$ext_response = Request::factory('http://site.com/foo/bar/bas')
->execute()
->response;
}
@shameerc
shameerc / tiny_mce.js
Created January 19, 2011 12:08
tinyeditor getcontent of active editor
tinyMCE.activeEditor.getContent()
@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 / 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 / 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);
?>