Skip to content

Instantly share code, notes, and snippets.

View koresar's full-sized avatar

Vasyl Boroviak koresar

View GitHub Profile
function getUniqueKeys() {
var keys = [];
_.forEach(behaviors, function (behavior) {
keys.push(Object.keys(behavior.parametersTemplate));
}.bind(this));
return _.uniq(_.flatten(keys));
}
// OR
@koresar
koresar / gist:aca0ca81edc34f58462c
Last active June 5, 2016 00:03
Pick the prettiest logo for Stampit
@koresar
koresar / index.js
Created December 27, 2016 01:08
Fun with Stamps. Episode 11. Interfering composition
const _ = require('lodash');
const stampit = require('stampit');
const isStamp = require('stampit/isStamp');
const Tracked = stampit()
.composers(({composables, stamp}) => { // declaring a composer
console.log(`Composed a stamp "${stamp}" from the following:
"${composables.join()}"`);
});
@koresar
koresar / collision.js
Last active January 26, 2017 01:51
Collision allowance and protection
const stampit = require('stampit');
const ProtectMethodCollisions = stampit({
statics: {
protectMethodCollisions(name) {
if (this.compose.methods && this.compose.methods[name]) {
const method = this.compose.methods[name];
function collisionProtectedMethodWrapper() {
return method.apply(this, arguments);
}
@koresar
koresar / privatize_plus_collision.js
Created February 9, 2017 02:43
Fun with stamps. Episode 12
import compose from '@stamp/compose';
import Privatize from '@stamp/privatize';
import Collision from '@stamp/collision';
const Password = compose({
properties: {
password: '12345qwert'
},
methods: {
getPassword() {
@koresar
koresar / app.js
Last active July 23, 2017 03:53
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app.js
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const http = require('http');
const debug = require('debug')('my-app-name:server');
// Application
const app = express();
@koresar
koresar / app2-test2.js
Last active July 23, 2017 07:26
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2-test2.js
describe('routing', () => {
const App = require('../app2');
const {handleNotFound, handleGenericError} = App.compose.methods;
it('should set status code to 404 when no route found', (done) => {
handleNotFound({}, {}, (error) => {
if (!error || error.status !== 404) {
throw new Error('Error status should be 404');
}
done();
@koresar
koresar / app2-test3.js
Last active July 23, 2017 07:26
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2-test3.js
describe('server', () => {
const App = require('../app2');
it('should call exit process after setImmediate()', (done) => {
let errorCallback = null;
let setImmediateCalled = false;
const MockedApp = App.props({
http: {
createServer() {
return {
@koresar
koresar / app2-test1.js
Last active July 23, 2017 10:39
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2-test1.js
describe('express app setup', () => {
const http = {
createServer() {
return {on() {}, listen() {}};
}
};
const App = require('../app2').props({http});
it('should share ./public', (done) => {
const express = () => ({set() {}, use() {}});
@koresar
koresar / app2.js
Last active September 4, 2017 05:44
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2.js
module.exports = require('@stamp/it')({
props: {
express: require('express'),
path: require('path'),
logger: require('morgan'),
cookieParser: require('cookie-parser'),
bodyParser: require('body-parser'),
http: require('http'),
debug: require('debug')('my-app-name:server'),
process,