Skip to content

Instantly share code, notes, and snippets.

View robinfehr's full-sized avatar
:octocat:
Focusing

Rob robinfehr

:octocat:
Focusing
View GitHub Profile
class ActionTypes {
static REBALANCE = Symbol("REBALANCE");
static MESSAGE = Symbol("MESSAGE");
static FETCH = Symbol("FETCH");
static {
const enumMap = new Map();
for (const [key, value] of Object.entries(this)) {
enumMap.set(key, value);
}
@robinfehr
robinfehr / startcluster.mongo.py
Created July 28, 2019 19:07
- run: `python startcluster.mongo.py --mongo_path="/usr/local/Cellar/mongodb/4.0.3_1/bin/" --port="27019" --name="exivoreplsetlocal"`
#!/usr/bin/env python
import atexit
import optparse
import os
from select import select
import shutil
from socket import (error,
socket,
AF_INET,
// --------------------------- initial code ----------------------------
// index.js
import { someObject } from './ModuleA';
console.log(someObject.property);
// ModuleA.js
export const someObject = {
property: 100
}
function constructorFn() {
this.x = 100;
}
constructorFn.prototype.nonStaticFn = function() {
return this.x;
}
constructorFn.staticFn = function() {
// this.x; undefined
return 200;
}
// No need to use "let" here since we never reassign the arr
const arr = [];
arr.push({ property: 1 });
// -----------------------------------------------
// If we want to clear the array by reassigning:
//
// because we're reassigning a new arr2 to the variable "arr",
// arr1 isn't assigned anymore and therefore gets flagged
// Of course this is badly written on purpose
// using a constructor fn but it shows that
// .hasOwnProperty is obsolete when using
// e.g. Object.keys()
function modes() {
this.type1 = 1;
this.type2 = 2;
this.type3 = 4;
}
modes.prototype.type4 = 2; // This is our problem.
// Example: Not so concise, not reusable
const component = { signals: [-33, -70, -80] };
function highlightComponent() {
// isHighlighted isn't reusable but also no allocation for an extra function happens (see below)
let isHighligted = false;
for (let signal of component.signals) {
if (signal > -34) {
isHighligted = true;
break;
function _extends(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError(
"Super expression must either be null or a function, not " +
typeof superClass
);
}
// Set both __proto__ and prototype
// ----------------------------------
// The class
class classFn {
constructor(x,y) {
this.x = x;
this.y = y;
}
multiply() {
return this.x * this.y;
}
}
function constructorFn() {
 this.someProperty = "oops!"
}
 
// We've forgotten the "new"
const instance = constructorFn();
instance; //undefined
window.someProperty; // oops!