Skip to content

Instantly share code, notes, and snippets.

View makefunstuff's full-sized avatar
😇
Why?

Iurii Plugatariov makefunstuff

😇
Why?
View GitHub Profile
unless Rails.env.production?
bot_files = Dir[Rails.root.join('app', 'messenger_bot', '**', '*.rb')]
bot_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do
bot_files.each{ |file| require_dependency file }
end
ActionDispatch::Callbacks.to_prepare do
bot_reloader.execute_if_updated
end
// tracker middleware
app.use((req, res, next) => {
if (req.metadata.event) {
tracking(req.metadata.event);
next();
}
});
// logger middleware
app.use('/data', (req, res, next) => {
app.get('/data/:entry_id', (req, res, next) => {
next();
});
app.get('/data/:entry_id/filtered', (req, res, next) => {
dataFilterService(req.result)
.then((apiResult) => {
req.metadata = {
info: 'data is filtered',
event: 'api.result.received'
app.param('entry_id', (req, res, next, entry_id) => {
getDataById(entry_id)
.then((data) => {
req.metadata = {
info: 'data is received',
event: 'data.received'
};
req.result = data;
app.get('/data/:entry_id', (req, res, next) => {
const { entry_id } = req.params;
database.getById(id)
.then((data) => {
logger('[INFO] data is received');
tracking('data.received', {id: id});
return res.json(data);
})
.catch(next);
app.get('/data/:entry_id', (req, res, next) => {
const { entry_id } = req.params;
database.getById(id)
.then((data) => {
return res.json(data);
})
.catch((error) => {
logger('[ERROR] ', error.message);
exceptionCatcher(error);
app.get('/data/:id/filtered', (req, res, next) => {
const { id } = req.params;
database.getById(id)
.then((data) => {
logger('[INFO] data is received');
tracking('data.received', {id: id});
return data;
})
.then((data) => dataFilterService({id: data}))
const middleware = require('../middlewares/my-middweware');
const next = sinon.spy();
const req = {};
const res = {};
describe('test my middleware', () => {
it('tests input and output', () => {
middleware(req, res, next);
expect(next).to.have.been.called;
const express = require('express');
const Promise = require('bluebird');
const app = express();
const logger = console.log;
const tracking = console.log;
const exceptionCatcher = console.error;
const getDataById = () => new Promise((resolve, reject) => {
resolve({data: 'I am response'});
@makefunstuff
makefunstuff / index.android.js
Created January 20, 2016 06:18 — forked from axemclion/index.android.js
Cordova Plugins in React native
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
NativeModules,
TouchableHighlight,