Skip to content

Instantly share code, notes, and snippets.

View lifecycle.test.js
const Cloud = require('../assets/dependencies/cloud');
const ioClient = require('socket.io-client');
const sailsIO = require('../assets/dependencies/sails.io');
const mockSailsSockets = require('./utils/mockSailsSockets');
let sails;
// Before running any tests...
before(function(done) {
View lifecycle.test.js
const Cloud = require('../assets/dependencies/cloud');
const ioClient = require('socket.io-client');
const sailsIO = require('../assets/dependencies/sails.io');
const mockSailsSockets = require('./utils/mockSailsSockets');
let sails;
// Before running any tests...
before(function(done) {
View SocketActivity.js
class SocketActivity {
static get Status() {
return {
CONNECT: 'connect',
DISCONNECT: 'disconnect',
RECONNECT: 'reconnect'
};
View sauils.io.off.bug.js
const SocketsMock = require('./utils/SocketsMock');
const Cloud = require('../assets/dependencies/cloud');
const ioClient = require('socket.io-client');
const sailsIO = require('../assets/dependencies/sails.io');
let sails;
// Before running any tests...
before(function(done) {
View _vscode-how-to-debug-ts.md

JS only

  1. Create folder
  2. Open folder in VSCode
  3. Open any .js file, then hit F5.

TS

  1. Create folder
  2. Open folder in VSCode
  3. npm i typescript --save-dev
  4. Create tsconfig.json
View flatten-array-recursive+iterative.js
function flattenArrayRecursive(arr) {
if (!Array.isArray(arr)) return [arr];
const res = [];
for (const el of arr) {
res.push(...flattenArrayRecursive(el));
}
return res;
}
function flattenArrayIterative(els) {
View es5-class-prototypical-inheritance.js
function Animal(name) {
this.animalName = name;
console.log('Animal constructor');
console.log('An animal named:', name);
}
Animal.prototype.makeNoise = function(noise) {
console.log('Animal makeNoise()');
console.log(noise, 'I can make noise...');
}
View testIfExistsByBinarySearch.js
function testIfExistsByBinarySearch(a, x) {
let il = 0;
let ir = a.length;
while (il < ir) {
const midIndex = Math.floor((ir + il) / 2);
const midValue = a[midIndex];
if (midValue < x) {
// search right half
il = midIndex + 1
} else if (midValue > x) {
View flatten-array-recursive-+-non-recursive.js
function flattenRecur(arr) {
// arr is either array or non-array
if (!Array.isArray(arr)) return arr;
const newArr = [];
for (const el of arr) {
const flattened = flattenRecur(el);
if (Array.isArray(flattened)) newArr.push(...flattened);
else newArr.push(flattened);
View gist:11be7e2c587e7be971f3bf1f5a7a2a87
(function() {
let items = [
{color: 'red', type: 'tv', age: 18},
{color: 'silver', type: 'phone', age: 20}
]
const excludes = [
{k: 'color', v: 'silver'},
{k: 'type', v: 'tv'},
]
You can’t perform that action at this time.