Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Last active February 24, 2018 04:06
Show Gist options
  • Save chathurawidanage/423e0a2f2f5890f2b526db660c4453ae to your computer and use it in GitHub Desktop.
Save chathurawidanage/423e0a2f2f5890f2b526db660c4453ae to your computer and use it in GitHub Desktop.
const { execSync } = require('child_process');
const fs = require("fs");
let read = fs.readFileSync('index.js'); //reading myself
let code = read.toString();
let requireRegex = /=\s*require\s*\(['\"](.+)['\"]\)/g;
let match = requireRegex.exec(code);
while (match != null) {
let lib = match[1];
match = requireRegex.exec(code);
if (lib === 'child_process' || lib === 'fs') {
continue;
}
execSync(`npm install --prefix /tmp --save ${lib}`);
}
let oldRequire = require;
require = function(module) {
return oldRequire(`/tmp/node_modules/${module}`);
}
/* JUST FORGET EVERYTHING AND START YOUR CODE FROM THIS POINT ONWARDS*/
let reverseString = require('reverse-string');
let mathjs = require('mathjs');
exports.handler = (event, context, callback) => {
callback(null, reverseString(' = evitavired')+mathjs.derivative('x^2 + x', 'x'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment