Skip to content

Instantly share code, notes, and snippets.

View santhosh17s's full-sized avatar

Santhosh santhosh17s

  • Altan Calsoft Labs
  • Chennai
View GitHub Profile
@santhosh17s
santhosh17s / promise.js
Last active February 22, 2018 13:45
Sleep in JS using Promises, async, wait
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function sleepWork(){
console.log("I'm going to sleep");
await sleep(100);
console.log("I wake up");
}
sleepWork();
@santhosh17s
santhosh17s / missingNumber.js
Last active February 21, 2018 09:30
Missing Number in Array using JS
var arr = [27,30,23,20,22,25,29,24];
function absent( arr ) {
var mia= [], min= Math.min.apply('',arr), max= Math.max.apply('',arr);
while(min<max){
if(arr.indexOf(++min)== -1) mia.push(min);
}
@santhosh17s
santhosh17s / index.html
Last active February 20, 2018 14:18
Angular 4 - CLI - Build and Deploy URL options
//Angular CLI - Build with base-href and deploy-url options
> ng build --prod --base-href /projectName --deploy-url /publicFolderName
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Single Page Application</title>
@santhosh17s
santhosh17s / string.js
Created February 27, 2018 07:41
String reverse
//STRING REVERSE
var myStringa = "UI FRONTEND";
myStringa.split('').reverse().join(''); //"DNETNORF IU"
@santhosh17s
santhosh17s / sort.js
Created February 27, 2018 09:54
Sort by Two Fields in JS
var obj = [
{ "name":'a', "count1": 1, "count2": 9 },
{ "name":'b', "count1": 10, "count2": 4 },
{ "name":'c', "count1": 21, "count2": 93 },
{ "name":'d', "count1": 10, "count2": 10 },
{ "name":'e', "count1": 10, "count2": 2 },
{ "name":'f', "count1": 5, "count2": 9 },
];
//Simple Class function
function API() {
this.name = 'This is API name';
}
//prototype function for share between the object
API.prototype.getName = function() {
//Take copy of this keyword
var self = this;
@santhosh17s
santhosh17s / throttle-debounce.js
Created April 23, 2018 09:40
Throttling & debounce technique in JS
// Referred in - https://codeburst.io/throttling-and-debouncing-in-javascript-b01cad5c8edf
// Start execute the function until, no more action request. Last requrest get performed.
// Use case - Auto Save, Submit, file send action
const debounce = (func, delay) => {
let inDebounce
return function() {
const context = this
const args = arguments
clearTimeout(inDebounce)
//CSS units - viewport - vh,vw,vmax,vmin
//Refered in - https://alligator.io/css/viewport-units/
body {
margin: 0;
padding: 0;
}
html, body {
overflow-x: hidden;
}
nav {
//---main.js
if (window.Worker) {
//worker(aURL, options)
const worker = new Worker("worker.js");
worker.onmessage = e => {
const msg = e.data;
console.log(`From Worker thread: ${msg}`);
$('document').ready( function(){
//WITHOUT ARROW FUNCTION
$('.my-name').on('click', function() {
var that = this;
setTimeout( function() {
$(that).toggleClass('on');
}, 1000);