Skip to content

Instantly share code, notes, and snippets.

View tmpaul06's full-sized avatar

Tharun M Paul tmpaul06

View GitHub Profile
mode=javascript/javascript:text/javascript**
speed=1.5**
data=[{"change":{"origin":"+input","duration":5505,"text":["function CounterWidget(parentNode) {}"],"from":{"line":0,"ch":0},"to":{"line":0,"ch":36}},"time":1578914274375},{"change":{"origin":"+input","duration":0,"text":["\n"],"from":{"line":0,"ch":36},"to":{"line":0,"ch":36}},"time":1578914280349},{"change":{"origin":"+input","duration":0,"text":["\n"],"from":{"line":1,"ch":0},"to":{"line":1,"ch":0}},"time":1578914280477},{"change":{"origin":"+input","duration":6886,"text":["\tconst btn = document.createElement('button');\n"],"from":{"line":1,"ch":0},"to":{"line":1,"ch":46}},"time":1578914280899},{"change":{"origin":"+input","duration":0,"text":[" "],"from":{"line":2,"ch":0},"to":{"line":2,"ch":0}},"time":1578914287785},{"change":{"origin":"+input","duration":6870,"text":["const span = document.createElement('span');\n"],"from":{"line":2,"ch":4},"to":{"line":2,"ch":48}},"time":1578914288054},{"change":{"origin":"+input","duration":0,"text":[" "]
mode=javascript/javascript:text/javascript**
speed=1.5**
data=[{"change":{"from":{"line":0,"ch":0,"sticky":null},"text":["const button = document.createElement('button');","","button.innerText = 'Click me';","","const main = document.querySelector('main');","","// Add button to main","main.appendChild(button);"],"removed":[""],"origin":"paste"},"time":1578912183736},{"change":{"from":{"line":7,"ch":25,"sticky":null},"to":{"line":7,"ch":25,"sticky":null},"text":["",""],"removed":[""],"origin":"+input"},"time":1578912185736},{"change":{"from":{"line":8,"ch":0,"sticky":null},"to":{"line":8,"ch":0,"sticky":null},"text":["",""],"removed":[""],"origin":"+input"},"time":1578912192084},{"change":{"from":{"line":9,"ch":0,"sticky":null},"to":{"line":9,"ch":0,"sticky":null},"text":["",""],"removed":[""],"origin":"+input"},"time":1578912192217},{"change":{"origin":"+input","duration":3089,"text":["// Adding counter\n"],"from":{"line":10,"ch":0},"to":{"line":10,"ch":17}},"time":1578912192673},{"change":{"origin":"+input",
@tmpaul06
tmpaul06 / create_button.cpd
Last active January 13, 2020 09:36
Create button codeplaya code
mode=javascript/javascript:text/javascript**
speed=1**
data=[{"change":{"origin":"+input","duration":7964,"text":["const button = document.createElement('button');\n"],"from":{"line":0,"ch":0},"to":{"line":0,"ch":48}},"time":1578906982525},{"change":{"from":{"line":1,"ch":0,"sticky":null},"to":{"line":1,"ch":0,"sticky":null},"text":["",""],"removed":[""],"origin":"+input"},"time":1578906990621},{"change":{"origin":"+input","duration":9203,"text":["button.innerText = 'Click me';\n"],"from":{"line":2,"ch":0},"to":{"line":2,"ch":30}},"time":1578906992447},{"change":{"from":{"line":3,"ch":0,"sticky":null},"to":{"line":3,"ch":0,"sticky":null},"text":["",""],"removed":[""],"origin":"+input"},"time":1578907001967},{"change":{"origin":"+input","duration":7206,"text":["const main = document.querySelector('main');\n"],"from":{"line":4,"ch":0},"to":{"line":4,"ch":44}},"time":1578907003860},{"change":{"from":{"line":5,"ch":0,"sticky":null},"to":{"line":5,"ch":0,"sticky":null},"text":["",""],"removed":[""],"origin":"+inpu
@tmpaul06
tmpaul06 / then.js
Created July 3, 2017 08:10
Promise chain
// domeSomethingAsync is the first promise.
var result = doSomethingAsync()
// It has a `then` method for chaining
.then(...)
// result is a different Promise. It has its own then method
result.then(...) => returns another new Promise
@tmpaul06
tmpaul06 / remote_same.js
Created July 3, 2017 07:53
Remote data call cache
var promise = remoteDataCall();
promise.then(function (result) {});
promise.then(function (result) {});
// Same result as above without executing `remoteDataCall` again.
@tmpaul06
tmpaul06 / remote_promise_again.js
Last active July 3, 2017 07:53
Remote data promise
// The first call returns promise1
remoteDataCall().then(function (result) {});
// Second call returns another promise2 !== promise1
remoteDataCall().then(function (result) {});
@tmpaul06
tmpaul06 / promise_deferred.js
Created July 3, 2017 07:45
Promise deferred
function getSomeJSON(url, callback) {
// AJAX call to get data from server. Accepts callback and calls
// with callback(err, response)
...
}
function fetchJSON(url) {
var deferred = new Deferred();
getSomeJSON(url, function (err, response) {
if (err) return deferred.reject(err);
@tmpaul06
tmpaul06 / promise_constructor.js
Created July 3, 2017 07:33
Promise constructor
function getSomeJSON(url, callback) {
// AJAX call to get data from server. Accepts callback and calls
// with callback(err, response)
...
}
function fetchJSON(url) {
return new Promise(function (resolve, reject) {
getSomeJSON(url, function (err, response) {
if (err) return reject(err);
@tmpaul06
tmpaul06 / mango_promise_main.js
Last active July 6, 2017 07:10
Mango promise
function dadBranch() {
var dadStrategy = askDadForMoney()
.then(buyMangoes, sitAndCry);
return dadStrategy;
}
getMoneyFromAccount()
.then(buyMangoes, dadBranch)
.then(eatMangoes)
@tmpaul06
tmpaul06 / mango_promise_error.js
Last active July 6, 2017 07:11
Promise error handling
getMoneyFromAccount()
// buyMangoes here will throw an Error
.then(buyMangoes, dadBranch)
// Next handler in chain
.then(eatMangoes, handleThief)
The `handleThief` function is called when buyMangoes throws an exception