Skip to content

Instantly share code, notes, and snippets.

View chonthu's full-sized avatar

Nithin Meppurathu chonthu

View GitHub Profile
@chonthu
chonthu / ps1.sh
Created August 22, 2011 18:05
My Favorite PS1
alias bashp='subl ~/.bash_profile'
alias ll='ls -lhaG'
alias refresh='. ~/.bash_profile'
alias zend='sudo /usr/local/zend/bin/zendctl.sh'
alias sites='cd ~/Sites'
alias hubot='cd ~/Sites/hubot;bin/hubot'
alias subl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
alias mongo_start='launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist'
# PS1 prompt color vars
@chonthu
chonthu / backtype.php
Created August 26, 2011 17:50
Backtype
/**
* @name backtype
* @author Nithin Meppurathu
* @author_url http://www.nitmedia.com
* @version 1.1
* @license Do Not distribute under any terms
*
* Backtype library for Codeigniter.
* Class Helps us connect with the backtype api and get back results.
*
@chonthu
chonthu / gist:1312794
Created October 25, 2011 13:55
USE PHPUNIT WITH ZEND CE ON MAC OSX LION
1)In ~/.bash_profile make sure
---------------------------------------
PATH=$PATH:/usr/local/zend/bin:/usr/local/zend/mysql/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zend/lib
2)
sudo ln -s /usr/lib/libltdl.7.dylib /usr/lib/libltdl.3.dylib
3)
sudo pear channel-discover pear.php-tools.net
@chonthu
chonthu / gist:1893463
Created February 23, 2012 16:09
on_duplicate_update 1
$exists = $this->db->select(‘id’)->where(‘id’, $id)->get()->row_array();
if($exists)
{
$this->some_model->add($data);
}
else
{
$this->some_model->update($data);
}
@chonthu
chonthu / gist:1893479
Created February 23, 2012 16:12
on_duplicate_update 2
INSERT INTO
`product`
SET
`id`=?
,`name`=?
,`created_at`=NOW()
ON DUPLICATE KEY UPDATE
,`name`=?
';
$stmt = mysqli_prepare($dbh, $sql);
@chonthu
chonthu / gist:1893482
Created February 23, 2012 16:13
on_duplicate_update 3
require_once(BASEPATH.'database/DB_driver.php');
if ( ! isset($active_record) OR $active_record == TRUE)
{
require_once(BASEPATH.'database/DB_active_rec'.EXT);
// get the CI instance
$CI = & get_instance();
$prefix = $CI->config->item('subclass_prefix');
@chonthu
chonthu / gist:1893486
Created February 23, 2012 16:14
on_duplicate_update 4
<?
class MY_DB_active_record extends CI_DB_active_record
{
function on_duplicate_update($table = '',$fields = NULL,$set = NULL)
{
if ( ! is_null($set))
{
$this->set($set);
}
@chonthu
chonthu / gist:1893489
Created February 23, 2012 16:14
on_duplicate_update 5
<?
class MY_DB_mysqli_driver extends CI_DB_mysqli_driver
{
final public function __construct($params)
{
parent::__construct($params);
}
function _insert_on_duplicate_update($table, $update, $values)
@chonthu
chonthu / gist:1893490
Created February 23, 2012 16:15
on_duplicate_update 6
class MY_Loader extends CI_Loader {
/**
* Database Loader
*
* @access public
* @param string the DB credentials
* @param bool whether to return the DB object
* @param bool whether to enable active record (this allows us to override the config setting)
* @return object
@chonthu
chonthu / gist:1893494
Created February 23, 2012 16:15
on_duplicate_update 7
$update = array_keys($data);
unset($update['created_at']);
$this->db->set($data)->on_duplicate_update('product',$update);