Monthly Archives: February 2017

Example of Associative Array in Javascript

Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence “The quick brown fox jumps over the lazy dog” repeatedly, because it is a pangram. (Pangrams are sentences constructed by using … Continue reading

Posted in Javascript | Leave a comment

PHP Reading from command line

$handle = fopen (“php://stdin”,”r”); // if single input (having no spaces) fscanf($handle,”%d”,$n); // if trying to read 2 values separated by a space fscanf($handle,”%d %s”,$d,$s); // if trying to read a string having spaces $inp = trim(fgets($handle));

Posted in PHP | Leave a comment

Advanced Features of PHP

1) Late Static Binding: “Late binding” comes from the fact that static:: will not be resolved using the class where the method is defined but it will rather be computed using runtime information. class A { public static function who() … Continue reading

Posted in PHP | Leave a comment

New Features in PHP 7

https://blog.feryn.eu/php-7-is-now-available-new-features-improvements/ 1) Speed 2) Type Declarations: Since PHP 5, you can use type hinting to specify the expected data type of an argument in a function declaration, but only in the declaration. When you call the function, PHP will check … Continue reading

Posted in PHP | Leave a comment

Given a sequence of words, print all anagrams together

$sortFunc = function($val) { $strArr = str_split($val); sort($strArr); return implode(“”, $strArr); }; $arr = array(“cat”, “dog”, “tac”, “god”, “act”); $words = array(); $index = array(); // form a new array with each string sorted within itself $words = array_map($sortFunc, $arr); … Continue reading

Posted in Algorithms | Leave a comment

Interesting Algorithm Interview Questions

1) Sorting a list of words such anagrams are grouped together. (Soundhound.com) Input: [‘abc’,’test’,’vac’, ‘bac’, ‘london’, ‘cba’, ‘cav’, ‘lon’, ‘pst’] Output: [‘abc’, ‘bac’, ‘cba’, ‘vac’, ‘cav’, ‘london’, ‘test’, ‘lon’, ‘pst’] 2. Design Twitter algorithm to retrieve top 10 new feeds … Continue reading

Posted in Algorithms | Leave a comment

Stored Procedure vs Function in MySQL

* Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes whenever it is called. But Function is compiled and executed every time when it is called. Stored * Procedures are … Continue reading

Posted in Database | Leave a comment

Questions on MYSQL Queries

1) How to display nth highest record in a table for example? How to display 4th highest (salary) record from customer table? SELECT DISTINCT(`salary`) FROM `customer` ORDER BY `salary` DESC LIMIT 3,1;

Posted in Database | Leave a comment

Find a substring within a string and return the index where it was found

$bigString = “I am a really big realtor in the bay area”; $pattern = “realtor”; $i = 0; $j = 0; $bigStringLen = strlen($bigString); $patternLen = strlen($pattern); $found = false; while ($i = $patternLen) { $found = true; break; } … Continue reading

Posted in Algorithms | Leave a comment

Module Pattern in Javascript

http://stackoverflow.com/questions/17776940/javascript-module-pattern-with-example http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html https://toddmotto.com/mastering-the-module-pattern/

Posted in Javascript | Leave a comment