Thursday, December 7, 2017

PHP Call Static Function Method Dynamically Based on __callStatic Method



<?php
abstract class ParentClass {
    public static function __callStatic($method, $args) {
        echo "Method=".$method.",Args=".json_encode($args)."\r\n<BR/>";
    }
}

class ChildClass extends ParentClass {
    public static function x1() {
        $args = func_get_args();
        call_user_func_array(
            array(parent::class, __FUNCTION__), $args
        );
    }
}

ChildClass::x1("x1", 10, 20);
ChildClass::x2("x2", 30, 40);


And output would be like:


Method=x1,Args=["x1",10,20] 
Method=x2,Args=["x2",30,40] 

Sunday, December 3, 2017

GRAILS GROOVY | GString Template Engine | Parse Simple String AS GString Template | String GSP Parser




def gEngine = new groovy.text.GStringTemplateEngine()
def binding = ["a": "a"]
String testVar = gEngine.createTemplate("MY ENGINE STRING AS=\${a}").make(binding).toString()
println(testVar)

Saturday, December 2, 2017

jQuery.noConflict() | Avoiding Conflicts with Other Libraries


(function() {
    function loadJQuery() {
      var startingTime = new Date().getTime();
      var script = document.createElement("SCRIPT");
      script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
      script.type = 'text/javascript';
      script.onload = function() {
        var $j = jQuery.noConflict();
        jQuery = $;
        $(function() {
              var endingTime = new Date().getTime();
              var tookTime = endingTime - startingTime;
              window.alert("jQuery previous version=" + $.fn.jquery + ", version=" + $j.fn.jquery);
          });
      };
      document.getElementsByTagName("head")[0].appendChild(script);    
    }
    loadJQuery();
})();


Check here for JSFiddle

Load jQuery with Javascript and use jQuery | Load jQuery dynamically




(function() {
    function loadJQuery() {
      var startingTime = new Date().getTime();
      var script = document.createElement("SCRIPT");
      script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
      script.type = 'text/javascript';
      script.onload = function() {
        var $ = window.jQuery;
        $(function() {
              var endingTime = new Date().getTime();
              var tookTime = endingTime - startingTime;
              window.alert("jQuery is loaded, after " + tookTime + " milliseconds!, version=" + $.fn.jquery);
          });
      };
      document.getElementsByTagName("head")[0].appendChild(script);    
    }
    if (window.jQuery) {
     alert("JQuery loaded");
    }
    else {
     alert("JQuery not loaded");
      loadJQuery();
    }
})();


Check here for JSFiddle



GIT | View Changed Details For Files By Commits | View List Of Files Changed During Different Commits

This below command will show changes made during last 3 commits for specific file defined
git diff HEAD~3..HEAD -- project/location/file.name
This command will list files changes made during last 3 commits
git diff --name-status HEAD~3..HEAD
This command will list files changes made during last 3 commits with changes
git diff HEAD~3..HEAD
Below command will show history of commits:
git log -3
git log -2
Below command will show difference between two commits:
git diff old_commit new_commit
git diff 5300b....4ea31a 754e8d....c33
git diff --name-status 5300b....4ea31a 754e8d....c33

MySQL Table Create Index Remove Index List Index | Primary Indexing | Unique Indexing | Field Indexing | FullText Indexing




/* Primary INDEXING */
ALTER TABLE `TABLE_NAME` ADD PRIMARY KEY (`ID`);

/* General INDEXING (1 or more field) */
ALTER TABLE `TABLE_NAME` ADD INDEX `INDEX_NAME` (`FIELD_1`, `FIELD_2`);

/* Unique INDEXING (1 or more field) */
ALTER TABLE `TABLE_NAME` ADD UNIQUE `INDEX_NAME` (`FIELD_1`, `FIELD_2`);

/* Fulltext INDEXING (1 or more field) */
ALTER TABLE `TABLE_NAME` ADD FULLTEXT `INDEX_NAME` (`FIELD_1`, `FIELD_2`);

/* Remove INDEXING */
DROP INDEX `INDEX_NAME` ON `TABLE_NAME`;

/* List INDEXING */
SHOW INDEX FROM `TABLE_NAME`;





Friday, December 1, 2017

MYSQL : SQL For Create Table Example




CREATE TABLE `table_name` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `int_field` BIGINT(20) NOT NULL DEFAULT '0',
  `string_field` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
  `long_text_field` LONGTEXT NULL COLLATE 'utf8_unicode_ci',
  `time_stamp_field` TIMESTAMP NULL DEFAULT NULL,
  `date_field` DATE NULL DEFAULT NULL,
  `date_time_field` DATETIME NULL DEFAULT NULL,
  `tinyint_field` TINYINT(1) NOT NULL DEFAULT '0',
  `double_field` DOUBLE(30,10) NULL DEFAULT '0.0000000000',
  `enum_field` ENUM('TRUE','FALSE') NULL DEFAULT 'TRUE' COLLATE 'utf8_unicode_ci',
  `set_field` SET('XA','XB','XC') NULL DEFAULT 'XA,XB' COLLATE 'utf8_unicode_ci',
  `uuid` VARCHAR(70) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uuid` (`uuid`),
  INDEX `int_field_index` (`int_field`),
  INDEX `int_field_index_complex` (`int_field`, `string_field`)
) COLLATE='utf8_general_ci' ENGINE=InnoDB;