Monday, 19 December 2016

PHP Array to stdClass Array – stdClass Object

<?php
$_TestAry = $this->_TestModel->getTestData();
if( isset($_TestAry) && !empty($_TestAry) && count($_TestAry) > 0){

 $_TestAry[count(_TestAry)+1]   = new StdClass; 
        // avoid warning creating default object from empty value

 $_TestAry[count(_TestAry)+1]->id   = 11;

 $_TestAry[count(_TestAry)+1]->name   = 'Jayakumar';

}
?>

Wednesday, 30 November 2016

Moto E first generation wifi, bluetooth, sound and calls not working

Flash stock rom via fastboot: Ensure your phone's battery is atleast 50% charged. Just charge your phone for 45 mins,ead if yor phones seems dead. You DONT need to unlock bootloader for flashing official firmwares
  1. Download and install Motorola device manager
  2. Download and extract adb_fastboot.zip to any folder on your pc
  3. Download Stock 5.1 rom file for your device model [thanks to lost101] and extract its contents to the same folder where you have adb_fastboot files
  4. Reboot your phone to 'bootloader mode'. To do this turn of your phone completely. Hold volume down button and then press and hold power button. Release power button after 4-6 seconds and then release volume down button. Your phone is now in bootloader mode.
  5. Connect your phone to pc via a reliable usb cable. Look at your phone screen. It should say 'USB connected'.
  6. Now go to the folder where you have extracted all the files. Holding down shift key, Right click on any point on white screen. Then click on 'open command window here' from the menu that appears. Command Prompt will open now
  7. On command prompt type Code: fastboot devices and check if it is detecting your device.
  8. Now run the following commands in the given sequence
Code:
mfastboot flash partition gpt.bin
mfastboot flash motoboot motoboot.img
mfastboot flash logo logo.bin
mfastboot flash boot boot.img
mfastboot flash recovery recovery.img
mfastboot.exe flash system system.img_sparsechunk.0
mfastboot.exe flash system system.img_sparsechunk.1
mfastboot.exe flash system system.img_sparsechunk.2
mfastboot.exe flash system system.img_sparsechunk.3
mfastboot flash modem NON-HLOS.bin
mfastboot erase modemst1 
mfastboot erase modemst2 
mfastboot flash fsg fsg.mbn
mfastboot erase cache
mfastboot erase userdata
fastboot reboot
Proceed to each command after you get success message on command. If file name of system.img_sparsechunk is different then change the command accordingly. Just ensure to flash all system.img_sparsechunk files. Your phone may take 10-20 mins to turn on the first time. Dont panic this is normal. If it takes more time then power it off by holding power button till it turns off. Power it on after it cools down.

How to detect Safari, Chrome, IE, Firefox and Opera browser?

// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// At least Safari 3+: "[object HTMLElementConstructor]"
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;



Wednesday, 24 August 2016

Codeigniter group by multiple columns

$this->db->group_by()

Permits you to write the GROUP BY portion of your query:

$this->db->group_by("title"); // Produces: GROUP BY title 
 
You can also pass an array of multiple values as well:

$this->db->group_by(array("title", "date"));  // Produces: GROUP BY title, date

Get last executed query in MySQL with PHP/CodeIgniter

$this->db->last_query();
Returns the last query that was run (the query string, not the result).
  
Example:
         $str = $this->db->last_query();

Wednesday, 17 August 2016

jQuery validation plugin multiple email addresses

<form id="form" method="post">
Het e-mailadres van je vriend(in):<input type="text" name="emails" id="emails" class="emails"><br />
<input type="submit" value="Verstuur">
</form>
jQuery.validator.addMethod(
    "multiemails",
     function(value, element) {
         if (this.optional(element)) // return true on optional element
             return true;
         var emails = value.split(/[;,]+/); // split element by , and ;
         valid = true;
         for (var i in emails) {
             value = emails[i];
             valid = valid &&
                     jQuery.validator.methods.email.call(this, $.trim(value), element);
         }
         return valid;
     },

   jQuery.validator.messages.multiemails
);

$("#form").validate({
     rules: {
                emails: { required: true, multiemails: true }
            },
     messages: {
                    emails: {
                                required: "enter the email",
                                multiemails: "Not Valid email"
                            }
               }

});

Disable automatic sorting on the first column when using jQuery DataTables

Set the aaSorting option to an empty array. It will disable initial sorting, whilst still allowing manual sorting when you click on a column.

"aaSorting": []

You just need to add the following parameter to the DataTables options:

 "order": []

Set up your DataTable as follows in order to override the default setting:
 
$('#example').dataTable( { "order": [], // Your other options here... } );

Friday, 12 August 2016

Converting string to Date and DateTime

Use strtotime() on your first date then date('Y-m-d') to convert it back:
$time = strtotime('10/15/2003');

$newformat = date('Y-m-d',$time);

echo $newformat;
// 2003-10-15

Wednesday, 10 August 2016

check / uncheck checkbox using jquery

Check/uncheck a checkbox, use the attribute checked 
$('#myCheckbox').attr('checked', true); // Checks it
$('#myCheckbox').attr('checked', false); // Unchecks it

Thursday, 21 July 2016

Validate username as alphanumeric with underscores using PHP

Regular Expression is /^[A-Za-z0-9_]+$/
This allows just alphanumeric characters and the underscore.

Eg:
      if( preg_match('/^[A-Za-z0-9_]+$/', 'hello123_') )
             echo "Success";
      else
             echo "Fail";

Monday, 4 July 2016

show modal using jquery without button click

Bootstrap has a few functions that can be called manually on modals:

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');

You can see more here: Bootstrap modal component
Specifically the methods section.

So you would need to change:
 
$('#my-modal').modal({
    show: 'false'
}); 

to:
 
$('#myModal').modal('show'); 

Wednesday, 15 June 2016

CodeIgniter URLs

  • Human friendly
  • Search-engine
  • Standard “query string” approach
  • Dynamic systems
  • Segment-based approach
jayakumar.xyz/codeigniter/docs/urls

URI Segments

It is following MVC Approach
jayakumar.xyz/class/function/ID
  1. The first segment represents the controller class 
  2. The second segment represents the function (method) class
  3. The third segment represents the ids, variable or passing any variables class 
The URI Library and the URL Helper contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the URI Routing feature for more flexibility


Removing the index.php file

By default, the index.php file will be included in your URLs:
jayakumar.xyz/index.php/codeigniter/docs/urls
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.

Example: .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

After using .htaccess file default url changed
jayakumar.xyz/codeigniter/docs/urls

Enabling Query Strings

In some cases you might prefer to use query strings URLs:
jayakumar.xyz/index.php?c=products&m=view&id=345
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file.

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm'; 
jayakumar.xyz/index.php?c=controller&m=method 

CodeIgniter General Topics

  • CodeIgniter URLs
  • Controllers
  • Reserved Names
  • Views
  • Models
  • Helpers
  • Using CodeIgniter Libraries
  • Creating Libraries
  • Using CodeIgniter Drivers
  • Creating Drivers
  • Creating Core System Classes
  • Creating Ancillary Classes
  • Hooks - Extending the Framework Core
  • Auto-loading Resources
  • Common Functions
  • Compatibility Functions
  • URI Routing
  • Error Handling
  • Caching
  • Profiling Your Application
  • Running via the CLI
  • Managing your Applications
  • Handling Multiple Environments
  • Alternate PHP Syntax for View Files
  • Security
  • PHP Style Guide

Who want Codeigniter?

  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
  • You want a framework that requires nearly zero configuration.
  • You want a framework that does not require you to use the command line.
  • You want a framework that does not require you to adhere to restrictive coding rules.
  • You are not interested in large-scale monolithic libraries like PEAR.
  • You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
  • You eschew complexity, favoring simple solutions.
  • You need clear, thorough documentation.

What is Codeigniter?

CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Monday, 18 April 2016

Change folder permissions and ownership Ubuntu

Use chown to change ownership and chmod to change rights.

sudo chown -R username:group directory

Monday, 4 April 2016

Tuesday, 2 February 2016

Windows Kill Process By Port Number

For windows

netstat -a -o -n                     list of process ids and port numbers

taskkill /F /PID 28344         Kill process (28344 is PID )

For ubuntu

ps -ef                 list of process ids and port numbers

kill -9 28344      Kill process (28344 is PID) 

Git merge branch to another branch

$ git checkout develop $ git pull $ git checkout test-branch $ git merge develop $ git push