Skip to content

Instantly share code, notes, and snippets.

View loopmode's full-sized avatar

Jovica Aleksic loopmode

  • ETECTURE
  • Fulda, Frankfurt
View GitHub Profile
@loopmode
loopmode / Logger.js
Created July 5, 2017 15:53
A console logger with name prefix and persisted enable/disable functionality.
/**
* A console logger with name prefix and persisted enable/disable functionality.
* Disabled by default.
* Enabled/disabled state is persisted in browser storage, e.g. localStorage or sessionStorage, and survives page refresh.
* @example:
* this.logger = new Logger({name: 'Grid'}); this.logger.log('Yay!');
*/
function Logger(options) {
options = options || {};
var name = options.name || 'default';
@loopmode
loopmode / Benchmarks.js
Created July 5, 2017 15:55
A benchmark utility that measures the execution times of functions in an object
/*
Usage:
this.benchmarks = new Benchmarks({
target: this,
functions: ['performLookups', 'createIsotope', 'updateIsotope', 'fitVideos', 'applyRandomSize']
});
*/
/**
* A benchmark utility that measures the execution times of functions in an object, if enabled.
* Disabled by default.
@loopmode
loopmode / commons.definitions.js
Last active August 12, 2017 06:53
desperate-commons-chunks-attempt
const gpCommons = [
{name: 'shared', path: 'src/shared', props: {async: 'common.shared'}},
{name: 'stores', path: 'src/stores', props: {async: 'common.stores'}},
{name: 'mediaplayer', path: 'src/mediaplayer', props: {async: 'common.mediaplayer'}},
{name: 'cms', path: 'src/cms', props: {async: 'common.cms'}},
{name: 'ordering', path: ['src/basket', 'src/footage-request', 'src/footage-orders'], props: {async: 'common.ordering'}},
];
const mpCommons = gpCommons.concat([
{name: 'licensing', path: 'src/clipbin', props: {async: 'common.licensing'}},
]);
import express from 'express';
const Router = express.Router({ mergeParams: true });
Router.post('/login', require('./login'));
Router.post('/create', require('./create'));
Router.post('/delete', require('./delete'));
Router.post('/logout', require('./logout'));
export default Router;
@loopmode
loopmode / react-router-4-setup.md
Created May 16, 2018 09:07
react-router-4-setup.md

Basic react-router 4 setup for login and protected routes.

Assuming there is a UserStore that can perform the actual operations. It also provides a user prop to pages when the user is logged in.

Omitting any insiginificant import statements. This is not copy-pastable code, but still real-world code. (Omitted some project/ui-specific stuff)

index.js

Renders the App, but wrapped in a Router. That way we can use Route and Switch components anywhere in our app tree.

@loopmode
loopmode / react-router-4-setup.md
Last active May 16, 2018 09:16
react-router-4-setup.md

react-router 4 basic setup

Basic react-router 4 setup for login and protected routes. Requires the user to log in in order to see those protected routes.

  • Assuming there is a UserStore that performs actual operations (e.g. ajax calls) and provides a user prop to components when the user is logged in.
  • Omitting any insiginificant import statements. This is not 100% copy-pastable, but still pretty much real-world code

index.js

@loopmode
loopmode / DefaultComponent.js
Last active July 9, 2020 08:34
Safeguarding async chains in React
// we have an async "initialize" method that performs several calls consecutively.
// after each step in the async chain, we might have been unmounted already
// and performing any further calls becomes obsolete
class DefaultComponent extends React.Component {
// ...
componentDidMount() {
this._isMounted = true;
this.initialize();
}
componentWillUnmount() {
@loopmode
loopmode / README.md
Created June 27, 2018 08:51
monkey-patching jscodeshift for decorators support

Execute scripts/patch/patch-jscodeshift.js. It will monkey-patch node_modules/jscodeshift/parser/babel5compat.js by prepending 'decorators-legacy' to the plugins array.

import * as spauth from 'node-sp-auth';
import getBaseUrl from '../utils/getBaseUrl';
export const AuthMethod = {
NONE: 'NONE',
NTLM: 'NTLM',
BASIC: 'BASIC'
};
@loopmode
loopmode / orient-passport-adapter.js
Last active November 8, 2022 08:25
node+express+orientjs+passport+redis
// orientdb/adapter.js
import connect from './connect';
import autobind from 'autobind-decorator';
import applySchema from './applySchema';
import createBaseData from './createBaseData';
const EventEmitter = require('events');