Skip to content

Instantly share code, notes, and snippets.

View thinker3197's full-sized avatar
:shipit:
making dope tech

Ashish thinker3197

:shipit:
making dope tech
View GitHub Profile
function multiply(a, b) {
return a*b;
}
function square(a) {
const sq = multiply(a, a);
console.log(sq);
}

Understanding the JavaScript event loop

If you are someone who has heard about the terms event loop, callback queue, concurrency model and call stack but doesn't really understand what they actually mean, this post is for you. Being said that, if you're an experienced developer this post might help you to understand the internal working of the language and enable you to write more performant user interfaces.

JavaScript as a language has grown exponentially over the past decade and has expanded its reach on various levels of developer stack i.e. frontend, backend, hybrid apps etc. Gone are those days when we used to talk about JavaScript in the context of browsers only. Despite its popularity and growing demand, very few developers actually understand how the language works internally. This post is an attempt to clarify and highlight how JavaScript works and what makes it weird when compared to languages that you might have previously used.

Overview

Unlike languages like C++ or Ruby, JavaScript is a

@thinker3197
thinker3197 / DESCRIPTION.md
Last active December 27, 2017 17:42
Avensis 2017 - Website

Avensis 2017

Website contents -
  • About AVENSIS
  • Messages of director Sir nd convenor
  • Pics of CA nd CO
  • About events (with rules nd everything) - around 20 events hai
  • Last yr sponsors (logos)
  • Contact Us (isme links hongay FB, Insta nd any other platform)
@thinker3197
thinker3197 / promise.js
Last active January 31, 2017 16:50
A basic implementation of promises in javascript, covers Promise/A+ specification
function Promise(callback) {
let state = 'pending';
let value;
let deferred = null;
const resolve = function(newValue) {
if(newValue && typeof newValue.then === 'function') {
newValue.then(resolve, reject);
return;
}
@thinker3197
thinker3197 / getElementsByAttributes.js
Last active December 16, 2022 09:14
Implementation of getElementsByAttributes API for HTML DOM
document.getElementsByAttribute =
Element.prototype.getElementsByAttribute = (attr, value) => {
const nodeList = document.getElementsByTagName('*'),
matchedNodes = []
for(let node of nodeList) {
if(node.hasAttribute(attr)) {
if(value === '*')
matchedNodes.push(node)
else

Overlay Dev Env.

(The following instructions are for bash)

  1. Check if ruby exists : cd ../../System/Library/Frameworks/Ruby.Framework (This folder should exist & it indicates ruby env is installed.)
  2. Install brew : 2.1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 2.2 run brew doctor, to check brew'w installation. 2.2 In case of any error, DONT REFER STACKOVERFLOW! Ask me, else you'll fuck your dev enviornment.
const drag = (() => {
return {
move: function(elem, xpos, ypos) {
elem.style.left = xpos + 'px';
elem.style.top = ypos + 'px';
},
start: function(elem, container, event) {
let posX = event.clientX,
posY = event.clientY,
elemTop = (elem.style.top).replace('px', ''),
@thinker3197
thinker3197 / download.js
Last active December 27, 2017 06:47
Download files using NodeJs
const fs = require('fs'),
http = require('http'), // Use https module if content is served over https connection
const url = 'http://urlToYourFile.com/bla/file.mp4',
name = 'filename',
extension = 'mp4'; // or mp3, txt, jpeg etc
const file = fs.createWriteStream(name+'.'+extension);
let request = http.get(url, function(response){
@thinker3197
thinker3197 / queue.js
Last active September 9, 2016 15:05
Implementation of queue using two stacks in O(m) time for m operations
// Create Stack
function Stack() {
var array = [];
this.push = function() {
array.push.apply(array, arguments);
return arguments;
};
this.pop = function() {