This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Database | |
| { | |
| protected $adapter; | |
| public function __construct() | |
| { | |
| $this->adapter = new MysqlAdapter; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Automobile | |
| { | |
| private $vehicleMake; | |
| private $vehicleModel; | |
| public function __construct($make, $model) | |
| { | |
| $this->vehicleMake = $make; | |
| $this->vehicleModel = $model; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class UserFactory | |
| { | |
| private function __construct() | |
| { | |
| } | |
| public static function Instance() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function search(string $pattern, string $text): int | |
| { | |
| $patternLength = strlen($pattern); | |
| $textLength = strlen($text); | |
| for ($i=0; $i< $textLength-$patternLength; $i++) { | |
| for ($j=0; $j < $patternLength; $j++) { | |
| if ($pattern[$j] != $text[$i+$j]) { | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var delay = function (elem, callback) { | |
| var timeout = null; | |
| elem.onmouseover = function() { | |
| // Set timeout to be a timer which will invoke callback after 1s | |
| timeout = setTimeout(callback, 1000); | |
| }; | |
| elem.onmouseout = function() { | |
| // Clear any timers set to timeout | |
| clearTimeout(timeout); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // asynchronous request by using timer | |
| // but not working when setInterval with 500, 100 < 1000 | |
| var messages = []; | |
| function getMessages() { | |
| $.ajax({ | |
| url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet' | |
| }) | |
| .done(function(msg){ | |
| if(messages.indexOf(msg) == -1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // take advantages of recursive async | |
| function getMessages(maxMessage) { | |
| var messages = []; | |
| function getNextMessage() { | |
| $.ajax({ | |
| url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet', | |
| method: 'GET', | |
| async: true, | |
| success: function(msg) { | |
| if (messages.length < maxMessage) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // asynchronous request by using timer | |
| // but not working when setInterval with 500, 100 < 1000 | |
| var messages = []; | |
| var timer = setInterval(myTimer, 1000); | |
| function myTimer() { | |
| $.ajax({ | |
| url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet' | |
| }) | |
| .done(function(msg){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Synchronous request to get 3 unique messages from zalora.sg | |
| var messages = []; | |
| while(messages.length < 3) { | |
| $.ajax({ | |
| url: 'https://www.zalora.sg/ajax/catalog/justforyou/?feedName=recentlyviewed&brandName=&size=20&category=&userId=10214339066013667&engine=datajet', | |
| async: false | |
| }) | |
| .done(function(msg){ | |
| if(messages.indexOf(msg) == -1) { | |
| messages.push(msg); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| C++ Program to check for balanced parentheses in an expression using stack. | |
| Given an expression as string comprising of opening and closing characters | |
| of parentheses - (), curly braces - {} and square brackets - [], we need to | |
| check whether symbols are balanced or not. | |
| */ | |
| #include<iostream> | |
| #include<stack> | |
| #include<string> | |
| using namespace std; |