Skip to content

Instantly share code, notes, and snippets.

View LionRoar's full-sized avatar
🍎

Ferris Ateniese LionRoar

🍎
View GitHub Profile
@haroldtreen
haroldtreen / promise-test.js
Last active August 25, 2023 13:59
Testing promise rejection with Mocha
const { assert } = require('chai');
function isError(e) {
if (typeof e === 'string') {
return Promise.reject(new Error(e));
}
return Promise.resolve(e);
}
@kbendick
kbendick / mergesort.cpp
Created March 8, 2016 19:44
Implementation of merge sort in c++
// Declare/initialize any useful variables here, including the temporary array
// to merge values into and then copy back into the parameter array.
/*
while the temporary array is not filled
if there are no more values in the left part of a,
move next value from right part of a into next index of the temporary array otherwise, if there are no more values in the right part of a,
move next value from left part of a into next index of the temporary array otherwise (values in each part) compare the first value in each part
move smallest value from a into next index of the temporary array
@dmvaldman
dmvaldman / promisesEM.md
Last active June 1, 2024 00:20
Promises as EventEmitters

Promises as EventEmitters

I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.

I read the spec, some blog posts, and looked through some code. I learned how to

@paulhhowells
paulhhowells / memory leaks .js
Last active May 25, 2022 08:33
avoid memory leaks with closures. google javascript style guide.
// from google javascript style guide:
// One thing to keep in mind, however, is that a closure keeps a pointer to its enclosing scope. As a
// result, attaching a closure to a DOM element can create a circular reference and thus, a memory leak.
// For example, in the following code:
// Leaky example
function foo (element, a, b) {
element.onclick = function() {
// uses a and b
// this func keeps a pointer to foo, its enclosing scope