Posts

How to config python3.6 interpreter in pycharm in ubuntu os

Image
How to config python3.6 interpreter in pycharm in ubuntu os Install pycharm education is free in ubuntu software store and after installing the pycharm to RUN the python file, we need to config python interpreter by pressing short cut ctrl + Alt  + s in keyword in pycharm will show configuration like screenshot below. pycharm python configuration Type interpreter in search box and select project interpreter  and select show all option in dropdown it will display pop up if you have configured then it will show configuration or it will show empty , if it as configured then select it  if it is not then click the plus + button ,which will give you option to select python version to select interpreter to run your project. select the python version and apply the changes ,then you will be able to run the pythpn file. Please share your comment below and any tips or tricks in python. Thank you

palindrome in python3.6 and php7

I am just practising, some interview question in both python and php to solve palindrome in easy way  to remember in interview.please share your solution or any latest interview question both php and python in comment box. PHP : $s =  'malayalam' ; $y =  '' ; for  ($i = strlen($s) -  1 ; $i >=  0 ; $i--) {     $y .= $s[$i]; } echo $y .  '</br>' ; if  ($s == $y) {     echo  "true" ; }  else  {     echo  "false" ; }

Increase the performance of yii2 project

Image
Increase the performance of yii2 project Recently, I was working on yii2 project with php 7.2 ,we were facing an issue on yii2 schema database ,in which we were using it yii2 as layer and was calling another yii2 API .At long run we were able to find that YII2 as some default rules in schema. Points: 1)  By default we are using active record ORM by YII2, So by default yii2 scans the database schema for every SQL query action. 2)To avoid it we used yii2 schema caching along with that ,we create CRON job to executes code from below link. https://forum.yiiframework.com/t/how-to-clear-schema-cache/35109/6 3) The CRON will refresh the schema of all tables and clear the cache. Please share your comments ,if there any other way to increase the performance of yii2. REFERAL: https://www.yiiframework.com/doc/guide/2.0/en/tutorial-performance-tuning#enable-schema-caching

yii2 arrayhelper::map vs array_map

Recently i was working on YII2 project in which i came across arrayhelper::map() and was thinking alternate in php. so i used array_map() also tested the performance of both in yii2 by start time and end time for both ,surprising was that execution time remain same.please let me know if there is any alternate that will execute faster then arrayhelper::map(). Adding the code in yii2: function find_field($value){ $value['id'] = $value['name']; return $value['id']; } $array = ['1'=>['id'=>1,'name' =>"pramodh",'address' =>'45 vk street','loc'=>'cbe'],'2'=>['id'=>2,'name' =>"pramodh kumar",'address' =>'45343 vk street','loc'=>'pune']]; $a = array_map(array($this,'find_field'),$array); print_r($a); yii2 code: $list = ArrayHelper::map($array,  ' id ' ,  ...

Add and find the rank in array using php

Hi  Recently i went to interview i was asked to add a mark and find the rank of it using php. 1) First i created a function called  rankChecker and passing  two parameter like collection of marks in array and mark that will be added and finding the rank of it. 2) Then i created dumpy variable $s ,$ab as array. 3)After that i added the mark in the array mark list and sorted into descending order and looped in for loop. 4) passing the value of first array into dumpy array $ab as key and passing the $i value  incremented by one as $i starts with zero. 5) And returning the current $ab array and passing $mark as key value in it. function rankChecker($arr,$mark){ $arr[] = $mark; rsort($arr); $ab = array(); //echo count($arr);    for($i=0;$i<count($arr);$i++){          $ab[$arr[$i]] = $i+1;       } return $ab[$mark]; } $arr=[39,37,34,56,67,23,37]; $mark=10; print_r(rankChecker($arr,$ mark));

print triangle of star using php

1) first loop considering $i as row and $j as column ,where total number of row is 4 and column is 7. 2) second is print * as passing the condition as following. CODE: for($i=1;$i<=4;$i++){     for($j=1;$j<=7;$j++){             if($i==1 && $j==4)             {                 echo "*";             } else if(($j==3 || $j==5)&& $i==2 )             {                 echo "*";             }else if(($j==2||$j==6)&&$i==3)             {                 echo "*";             } else if(($j==1||$j==7)&&$i==4){                 echo "*";         ...

find second highest value in array using php

1) First step is to sort the array in desc. 2) create two variable  like $fh as first highest and $sh as second highest. 3) loop the array in foreach ,we will check the if condition to first val is greater then $fh variable ,where first iteration first highest value will be assigned to $fh value. 4) second  else if condition will be same ,but here variable will be $sh and another condition in is check duplicate value of highest in the array. $arr = [55,40,50,76,76,40,30,20,60,89]; rsort($arr); $fh=0; $sh=0; foreach($arr as $val){     if($val > $fh){         $fh = $val;     } elseif(($val>$sh) && ($val != $fh)){         $sh = $val;     }   } echo $sh;

Find pair of n numbers in php

Image
Recently I was working on mobile project in which we were working on service code in php, To find the pair in certain number in list.  Example:  $total = 4; $pair_total = $total * ($total - 1) * 0.5; // 6 So here we are able to find the pair combination using this formula.And pls comment if there any tricks similar to this.

Question: Why should we use class name in another class constructor function in php7?

I was working around oops in php 7 ,in which I pass class name and variable to another class constructor function to access the function of it Like inheritance concept.Let me brief with example Example for passing class name and variable in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constructor   public function __construct(A $a){      $this->a = $a;   }  public function show(){     $user = 'pramodh';     $this->a->execute($user);    } } $b = new B(new A); $b->show(); Out Put : Pramodh Example for passing just variable  in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constru...

Disable back button of any browser in javascript

Hi Friends I was working on web application in which we have to disable browser back button,so search number solution in stackoverflow and found best suitable solution for it.I wanted to share that code ,so that developer can save time on searching. history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); });

skipping sunday in working day in js

Hi friends I like to share some code to validate the date in number of days along with skipping sunday to validate working day in week. <span id="result"></span> var day= 14; document.getElementById('result').innerHTML = addDays(day); function addDays(day){  var day = parseInt(day);     var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];         for(var i=0;i<=day;i++){                var dates = new Date();                 dates.setDate(dates.getDate() + i);              //console.log(weekday[dates.getDay()]);        if(weekday[dates.getDay()]=='Sunday'){              console.log('first if');  ...

optimize gzip and leverage browser cache through .htaccess

Recently i was working on YII2 project i used to several gzip code in yii2 to optimize by validating the site through page speed from google.I was able to come out with solution through youtube and taken the code from comment session and added in my .htaccess file.Let me share the code below <IfModule mod_headers.c> <FilesMatch "\.(js|css|xml|gz)$"> Header append Vary: Accept-Encoding </FilesMatch> </IfModule> # Deflate Compression by FileType <IfModule mod_deflate.c>  AddOutputFilterByType DEFLATE text/plain  AddOutputFilterByType DEFLATE text/html  AddOutputFilterByType DEFLATE text/xml  AddOutputFilterByType DEFLATE text/css  AddOutputFilterByType DEFLATE text/javascript  AddOutputFilterByType DEFLATE application/xml  AddOutputFilterByType DEFLATE application/xhtml+xml  AddOutputFilterByType DEFLATE application/rss+xml  AddOutputFilterByType DEFLATE application/atom_xml  AddOutputFilterByType DEFLATE a...

Holding giant snake by snake expert

Image
Recently in pune tech park ,snake came into the garden they called snake catcher to catch the snake. Please CLICK HERE to view the video

jquery:input field validation allow numeric with and without decimal

The jquery validation to input field to allow only numeric value with or without numeric value on keypress and on blur with regrex to validate it. <span>Float</span> <input type="text" name="numeric" class='allownumericwithdecimal'> <div>Numeric values only allowed  (With Decimal Point) </div>       <br/>   <br/>   <br/>    <span>Int</span> <input type="text" name="numeric" class='allownumericwithoutdecimal'> <div>Numeric values only allowed  (Without Decimal Point) </div> $(".allownumericwithdecimal").on("keypress keyup blur",function (event) {             //this.value = this.value.replace(/[^0-9\.]/g,'');      $(this).val($(this).val().replace(/[^0-9\.]/g,''));             if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event....

Recursive function: multidimensional array looping through 3 x faster

A faster way to replace the strings in multidimensional array is to json_encode() it, do the str_replace() and then json_decode() it, like this:  <?php  function  str_replace_json ( $search ,  $replace ,  $subject ){      return  json_decode ( str_replace ( $search ,  $replace ,   json_encode ( $subject ))); }  ?>  This method is almost 3x faster (in 10000 runs.) than using recursive calling and looping method, and 10x simpler in coding.  Compared to:  <?php  function  str_replace_deep ( $search ,  $replace ,  $subject ) {     if ( is_array ( $subject ))     {         foreach( $subject  as & $oneSubject )              $oneSubject  =  str_replace_deep ( $search ,  $replace ,  $oneSubject );         unset( $oneSubject );         return...

Datatables warning (table id = example) issue (solved)

Image
I have been working on the datatables jquery plugin  and created a dynamic table  with populating json data quit easily.likewise, I also have shared tutorial regarding  datatable jquery : how to create table and display link on hover table row?   but i was facing issue raised during loading the table alert of datatables apeared like I solved the issue according to the column attribute used in the creating column like aoColumns or aoColumnDefs and found solution from link below. http://legacy.datatables.net/usage/columns

Create drupal 7 theme for beginners tutorial

Image
This tutorial is for total beginners,who are looking for basic and theme creating tutorial for drupal 7.  

Drupal 7 notes for beginners

Not sure if this is really a question, but maybe I can give you some useful hints anyway. First, you mentioned that you are familiar with MVC frameworks in the other question. So, here is the first point. Drupal is *not* a MVC framework. It is a CMS (some also use the term CMF for Content Management Framework) and it [roughly follows the PAC design principle.][1] This means that there can be rather big differences for doing X in a MVC framework and doing it in Drupal. Second, Drupal is a *large* and rather complex project. It can do a lot for you out of the box, but to get to do *exactly* what you want, you will have to learn quite a lot. The [documentation][2] is usually very good (not for no reason, there is a dedicated documentation team that is working hard to improve it constantly) but you will have to read more than a single page in most cases to understand a single hook or function. Start with the linked components on the front page. For hooks, they are in general a rather simp...

Happy new year 2@l5

Image
Wish you happy new year, live a healthy and enjoy the life as last day.

Array search in php

Image
 Search string in array functionality. <?php $array_value = array ( array ( 'id' => 2, 'name' => 'Sammy'), array ( 'id' => 3, 'name' => 'ram'), array ( 'id' => 4, 'name' => 'sam'), array ( 'id' => 2, 'name' => 'sammer') ); $index_array = array_keys( array_filter( $array,function ( $x ) { return preg_match('/^D.*$/',$x['name']); } )); var_dump($index_array); ?>