Jul
12
2014

How to execute jquery change function on page load?

In following code change function will trigger on page load because of change() it at end of function. This change() will make function to trigger on page load.

$("#select_drop_down").change(function(){
   ///// do some code here
}).change();


Jul
12
2014

How to show debug output in browser console in php?

While debugging php code we might need to use print_r() or var_dump() functions with exit or die, as in following code but by following code page will not render completely because exit or die stop remaining code from execution. If we don’t use die or exit then page design will break.

echo '<pre>';
print_r($debug_array);
echo '</pre>';
exit;

But we can also show debug output in browser console and page render completely without any break at same time. To do so following code will help to show output in browser console.

if(is_array($data) || is_object($data))
{
    echo("<script>console.log('".json_encode($data)."');</script>");
} else {
    echo("<script>console.log('".$data."');</script>");
}

Jul
12
2014

How to get controller name and method name in codeigniter?

Following codeigniter code is to get controller name and method name.

$this->router->fetch_class(); // class = controller
$this->router->fetch_method(); //

Jul
12
2014

Vim commands

Vim is a text editor written by Bram Moolenaar. Its based on the vi editor common to Unix-like system.

Following are commands for vi/vim.

Cursor movement

  • h – move left
  • j – move down
  • k – move up
  • l – move right
  • w – jump by start of words (punctuation considered words)
  • W – jump by words (spaces separate words)
  • e – jump to end of words (punctuation considered words)
  • E – jump to end of words (no punctuation)
  • b – jump backward by words (punctuation considered words)
  • B – jump backward by words (no punctuation)
  • 0 – (zero) start of line
  • ^ – first non-blank character of line
  • $ – end of line
  • G – Go To command (prefix with number – 5G goes to line 5)

Jul
12
2014

How to hide notices and warnings in php?

You can add following code on top of your php file. I had warnings and notices on joomla 2.5.11 site, I added following code in index.php file and it works.

ini_set('display_errors','off');

Feb
9
2014

doSelectStmt in symfony 1.2

doSelectStmt in symfony 1.2

        $cd = new Criteria();
        $cd->clearSelectColumns();
        $cd->addSelectColumn('SUM(' . TablePeer::QTY . ') as sumqty');
        $stmt = TablePeer::doSelectStmt($cd);
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        echo $row['sumqty'];

Feb
9
2014

Run custom query in symfony 1.2 with propel

Sometimes we require to execute complex query in symfony 1.2 with propel. For this following code can be used.

$conn = Propel::getConnection();
$query = “Select  * from table”
$statement=$conn->prepare($query);
$statement->execute();
$rowObj = $statement->fetch(PDO::FETCH_OBJ);

$rowObj will have result of your given query. You can check it via var_dump or print_r and show it as you want.


Feb
2
2014

select all checkbox code in jquery

sometimes we have multiple checkbox fields in form and require to select all and deselect all. Following is code to select and deselect.

$("#selectAll").click(function(){
          $(".chkboxes").prop("checked",$("#selectAll").prop("checked"))
       }); 
       $(".chkboxes").click(function(){ 
        if($(".chkboxes").length == $(".chkboxes:checked").length) {
            $("#selectAll").prop("checked", true);
        } else {
            $("#selectAll").removeAttr("checked");
        }
       });

Feb
2
2014

referer redirect method in symfony.

$this->redirect($request->getReferer());

This is very useful method and used to redirect back to sender page.


Dec
8
2013

How to register Ruby environments with pik?

pik add command is used to register your installed ruby environments with pik. For example, I have Ruby 1.9.3, and 2.0.0 installed on my windows, so I used the following in a Command Prompt:

> pik add C:\Ruby193\bin
INFO: Adding:  [ruby-]1.9.3-p392
      Located at:  C:\Ruby193\bin

> pik add C:\Ruby200\bin
INFO: Adding:  [ruby-]2.0.0-p0
      Located at:  C:\Ruby2000\bin

Use the pik list command to list all the ruby interpreters registered with pik:

> pik list
   ruby-1.9.3-p392
   ruby-2.0.0-p0

Make a default Ruby

The pik use command will allow you to switch between your registered ruby interpreters:

> pik use ruby-2.0.0-p0
> ruby -v
ruby 2.0.0p0 (2013-02-024) [i386-mingw32]

Add the –default parameter to set one version as the default:

> pik use ruby-1.9.3-p392 --default

You can use the pik default command to switch to this version:

> pik default
> ruby -v
ruby 1.9.3p392 (2013-02-022) [i386-mingw32]

When you open a command prompt, pik might not automatically loaded, so you will notice that there is no default ruby loaded:

Run the pik default command to load pik or add one particular Ruby interpreter to your user or system PATH environment variable from Control Panel -> System -> Advanced -> Environment Variables

set enviornment variable


Pages:12345678»

Hire Me!

Ads

affiliate_link

Ads


Find Us on Facebok

Subscribe by Email