Skip to content

Instantly share code, notes, and snippets.

View hserang's full-sized avatar

Haroun Serang hserang

View GitHub Profile
//setup
var someError = "oops";
//before
if (someError === "oops") {
//do something
} else if (someError === "ohgodwhy") {
//do something else
} else if (someError === "stopthemadness") {
//and more
@hserang
hserang / example_factory
Last active March 6, 2018 01:32
Example fixture factory using rosie and chance.js
'use strict';
var _ = require('lodash');
var Chance = require('chance');
var Factory = require('rosie').Factory;
function getExternalTransaction(chance) {
function getAmount() {
return chance.floating({
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@hserang
hserang / errors.js
Last active August 29, 2015 14:20 — forked from gr0uch/errors.js
// TypedError class which other typed errors subclass from.
class TypedError extends Error {
constructor (message) {
super();
if (Error.hasOwnProperty('captureStackTrace'))
Error.captureStackTrace(this, this.constructor);
else
Object.defineProperty(this, 'stack', {
@hserang
hserang / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

If you've reached this page, it's probably because your "parent-based and owner-based contexts differ".

As we've been iterating on React's "context" feature, we've discovered that the parent-based relationship is more useful than the owner-based relationship, so we're migrating to use a parent-based hierarchy.

In short, the owner of a component is whomever creates the component, while the parent of a component is whomever would be the containing ancestor in the DOM hierarchy. To learn more about the owner relationship, see the docs here: http://facebook.github.io/react/docs/multiple-components.html

In many cases, the owner and the parent are the same node, in which case, no further action is necessary. However, if your owner and your parent differ, you should ensure that the context variables you're using aren't going to break when we switch from owner-based contexts to parent-based contexts. If you're seeing the warning, your component may not be ready for the switch.

NOTE: semantically-equal context var

// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@hserang
hserang / console.log.js
Created June 10, 2015 18:04
Quick and Dirty console.log formatting
function cl(message='log', data='') {
console.log('\n--------------');
if (typeof data === 'object') {
console.log(`${message}`, JSON.stringify(data, null, 2));
} else {
console.log(`${message}`, data);
}
console.log('--------------\n');
};
@hserang
hserang / simple-co.js
Created February 3, 2016 17:34 — forked from clark800/simple-co.js
simplified co
'use strict';
function isGenerator(obj) {
return typeof obj.next === 'function' && typeof obj.throw === 'function';
}
// co returns a promise that resolves to the return value of the generator arg
function co(generator) {
return new Promise(resolve => {
function next(result) {
@hserang
hserang / cloudSettings
Last active March 27, 2020 22:55
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-03-27T22:55:44.719Z","extensionVersion":"v3.4.3"}