A Pen by Hoang Minh Tuan on CodePen.
A Pen by Hoang Minh Tuan on CodePen.
This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains 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; |
This file contains 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 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 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 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 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 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; |
OlderNewer