Friday, October 10, 2014

Sublime Text: Multiple cursors or Multi-selection

Multiple cursors or Multi-selection in sublime text is easy

  • Press Alt/Command and then click in each region where you require a cursor. 
  • Select a block of lines : Shift + Command + L. 
  • Place the cursor over a particular word, and press Control/Command + D repeatedly to select additional occurrences of that word. 
  • Add an additional cursor at all occurrences of a word : Alt+F3 on Windows or Ctrl+Command+G on Mac.

Tuesday, September 30, 2014

Laravel: Debug by Printing Eloquent Query

Use ->toSql() method like shown below to get the SQL

use Log;

$name = "hawk";

$userResults = DB::table('users')
       ->leftJoin('planets', function($join) {
         $join->on('users.planet_id', '=' , '');
       ->where('users.lname' , 'like', '%'.$name.'%');

//You can print the SQL in your log file
Log::info('My search sql: '.($userResults->toSql()));

// OR you can save into a string variable
$mySQL = $userResults->toSql();

//Then use your get function
$userResults = $userResults->get(array('users.fname', ''));

The above code will print the following into your /storage/logs/laravel.log file

[2014-09-30 17:58:07] production.INFO: My search sql: SELECT * FROM  users LEFT JOIN planets ON (users.planet_id = WHERE users.lname LIKE '%hawk%' 

Thursday, September 11, 2014

Laravel 4: Easy Installation of PHP mcrypt extension for OS X 10.8/10.9

An automated PHP mcrypt extension installer for OS X 10.8/10.9 - Mountain lion and Mavericks.

Download here:

Thursday, September 4, 2014

Laravel, Eloquent: SQL query with left join

If the query needs parentheses/brackets for a where condition like below Normal SQL:

SELECT users.fname, 
FROM  users
LEFT JOIN  planets ON (users.planet_id =
WHERE users.lname LIKE '%hawk%' 


$name = "hawk";

$userResults = DB::table('users')
       ->leftJoin('planets', function($join) {
         $join->on('users.planet_id', '=' , '');
       ->where('users.lname' , 'like', '%'.$name.'%')
       ->get(array('users.fname', ''));

Wednesday, July 2, 2014

Eloquent: SQL Query with where or in brackets

If the query needs parentheses/brackets for a where condition like below Normal SQL:

FROM  users
WHERE planet = 'earth'
AND (fname LIKE '%hawk%' OR lname LIKE '%hawk%')
AND state = 'FL'


$name = "hawk";

$usersResults = DB::table('users')
    ->where('planet', '=', 'earth')
    ->where(function($query) use ($name){
            $query->where('fname' , 'like', '%'.$name.'%');
            $query->orWhere('lname' , 'like', '%'.$name.'%');
     ->where('state', '=', 'FL')

Friday, June 27, 2014

Wordpress: Print-friendly, Print as it looks in browser

If you you want to print a wordpress blog/site as it looks on the browser, then you have to
1. Login to the Wordpress as admin
2. Goto Appearance->Editor in the Left Sidebar menu.
3. On the right side find Header.php file
4. In the file locate the following piece of code

<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen” />

5. Modify to the media=""screen" to media="screen, print"
6. Click Update file at the bottom to save the changes in header.php

<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen, print” />

Wednesday, June 18, 2014

Oracle: Split a String Based on Delimiter

We can split a string based on Delimiter using a combination of  INSTR and SUBSTR functions:

INSTR Returns the position of a String within a String. For more information see Oracle instr function
SUBSTR Returns a substring. For more information see Oracle substring
Syntax of SUBSTR:

Example 1:
select substr('',1,(instr('','.')) - 1)  
 from  dual  


Example 2:
select substr('',1,(instr(','.')) - 1) as First,  
        substr('', (instr('','.')) + 1) as Second  
 from  dual 

First         Second
orange           apple

Tuesday, June 17, 2014

Oracle SQL Developer multiple table view

Oracle SQL Developer, to view multiple tables in different tabs, click on the 'pin' icon.

Monday, June 16, 2014

Eclipse keyboard shortcuts and Sublime Text 3 keybord shortcuts

Switching from Eclipse to Sublime Text 3?,  need some quick shortcuts to

1. Switching/Moving Lines up and down
Eclipse shortcut:  ⌘-UP to move lines up,  ⌘-DOWN to move lines down,
Sublime Text 3: CTRL-⌘-UP to move lines up, CTRL-⌘-DOWN to move lines down.

2. Deleting Entire Line your cursor is on 
Eclipse shortcut:⌘-D
Sublime Text 3: CTRL-SHIFT-K

3. Goto Line in File 
Eclipse shortcut: ⌘-L
Sublime Text 3: ⌘-P, then type a colon followed by the line number (e.g. :12 for line 12). To go to a line in another file, type the file name and then a colon and the line number.