// Create Stack | |
function Stack() { | |
var array = []; | |
this.push = function() { | |
array.push.apply(array, arguments); | |
return arguments; | |
}; | |
this.pop = function() { |
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){ |
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', ''), |
(The following instructions are for bash)
- Check if ruby exists :
cd ../../System/Library/Frameworks/Ruby.Framework
(This folder should exist & it indicates ruby env is installed.) - Install brew :
2.1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.2 runbrew 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.
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 |
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; | |
} |
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.
Unlike languages like C++ or Ruby, JavaScript is a
function multiply(a, b) { | |
return a*b; | |
} | |
function square(a) { | |
const sq = multiply(a, a); | |
console.log(sq); | |
} |