Skip to content

Instantly share code, notes, and snippets.

View lastday154's full-sized avatar

Steve Hoang lastday154

  • NIT Warangal, India
View GitHub Profile
@lastday154
lastday154 / 0_reuse_code.js
Created March 27, 2017 07:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@lastday154
lastday154 / BalancedParentheses.cpp
Created April 1, 2017 04:14 — forked from mycodeschool/BalancedParentheses.cpp
C++ Program to check for balanced parentheses in an expression using stack.
/*
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;
@lastday154
lastday154 / sync.js
Last active June 22, 2017 02:25
Synchronous request
// 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);
@lastday154
lastday154 / async_timer.js
Last active June 22, 2017 02:31
Asynchronous request
// 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){
@lastday154
lastday154 / async_recursive.js
Created June 22, 2017 02:30
take advantages of recursive async
// 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) {
// 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) {
@lastday154
lastday154 / hover_delay.js
Created July 26, 2017 04:07
How to have a mouseover event fire only if the mouse is hovered over an element for at least 1 second?
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);
@lastday154
lastday154 / strstr.php
Created November 21, 2017 01:36
Strstr PHP implementation
<?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;