Skip to content

Instantly share code, notes, and snippets.

View gautamk's full-sized avatar

Gautam gautamk

  • Block | Meta | Appdynamics | Cisco | Amazon | University of Washington
  • PST
View GitHub Profile
@gautamk
gautamk / action_specific_css_js_cake.php
Created February 29, 2012 14:25
Auto include Action Specific Css and Javascript CakePHP
<?php
// Add this to any `view` recommended is View/Layouts/default.ctp
/*
WWW_ROOT generally refers to your webroot directory
DS is usually '/'
$this->params['controller'] returns controller name in lowercase
$this->params['action'] returns action name in lowercase
Refer
* http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html
@gautamk
gautamk / bgchanger.js
Created February 18, 2012 16:17
Tumblr bgchanger
//(function(){
//Refer http://code.google.com/apis/picasaweb/docs/2.0/reference.html
// Album url can be obtained by getting the rss feed of a Public or Limited album
var album_url = "https://picasaweb.google.com/data/feed/base/user/104873802064687726116/albumid/5710488196657525265?"+ // The base url
//Query Parameters
"alt=json"+ // Options are json and rss ,
"&kind=photo"+
"&authkey=Gv1sRgCIC0zJCjrbqplwE"+//Necessary only because the album's visibility is Limited , link only
@gautamk
gautamk / jqslide.html
Created February 18, 2012 15:51
A Simple jqeury based slideshow
<html>
<head>
<title>jQSlide</title>
</head>
<body>
<img src="" id="slide_show_pic" alt="">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
@gautamk
gautamk / single_line_php.sh
Created February 8, 2012 02:07
Testing single line php code
# What if you wanted to test a single line of code in php ?
# Simple
echo "<?php phpinfo();" | /path/to/php
# Since I am using XAMPP
# The following works
echo "<?php phpinfo();" | /opt/lampp/bin/php
@gautamk
gautamk / auth.php
Created February 4, 2012 15:10
CodeIgniter Authentication Library , application/libraries/auth.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth {
/**
* @author K.Gautam
* @version 0.1
* @todo ability to add configuration.
*/
protected $CI=NULL;
<?php
require_once 'Zend.php';
require_once 'Zend/Uri/Exception.php';
require_once 'Zend/Uri/Http.php';
require_once 'Zend/Uri/Mailto.php';
abstract class Zend_Uri
{
/**
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends Controller {
function Test() {
parent::Controller()
$this->load->library('Acl');
define('ROLE', '1');
define('RESOURCE', '1');
}
function index() {
if (!$this->acl->can_read(ROLE, RESOURCE)) {
INSERT INTO `user_resources` (`id`, `name`, `description`, `parentId`) VALUES
(1, 'test', 'Acl Test Controller', NULLL)
INSERT INTO `user_roles` (`id`, `name`, `description`, `parentId`) VALUES
(1, 'test', 'Acl Test Role', NULLL)
INSERT INTO `user_permissions` (`id` ,`role` ,`resource` ,`read` ,`write` ,`modify` ,`delete` ,`publish`)
VALUES (NULL , '1', '1', '1', '1', '0', '0', '0');
CREATE TABLE `user_resources` (
`id` INT NOT NULL AUTO_INCREMENT
, `name` VARCHAR(255)
, `description` VARCHAR(255)
, `parentId` INT DEFAULT NULL
, PRIMARY KEY (`id`)
);
CREATE TABLE `user_roles` (
`id` INT NOT NULL AUTO_INCREMENT
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once BASEPATH .'libraries/Zend/Acl.php';
class Acl extends Zend_Acl {
function __construct() {
$CI = &get_instance();
$this->acl = new Zend_Acl();
$CI->db->order_by('ParentId', 'ASC'); //Get the roles
$query = $CI->db->get('user_roles');