This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addMoneyMiddleware(ctx) { | |
if (!ctx.money) { | |
ctx.money = 1 | |
} else { | |
ctx.money += 1; | |
} | |
} | |
// Lets say a GET /add-money is received |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Koa, { Middleware } from 'koa'; | |
import Router from 'koa-router'; | |
const PORT = 8080; | |
const app = new Koa(); | |
const router = new Router(); | |
// Setup your route based logic | |
const helloWorldController: Middleware = async (ctx) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NPM | |
/node_modules | |
npm-debug.log* | |
yarn-debug.log* | |
yarn-error.log* | |
# misc | |
.DS_Store | |
.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "the-app-name", | |
"version": "1.0.0", | |
"description": "", | |
"main": "src/server.ts", | |
"scripts": { | |
"start": "ts-node src/server.ts" | |
}, | |
"author": "", | |
"license": "ISC", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Hello world'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AtomNode(Node): | |
def __init__(self, name): | |
super(AtomNode, self).__init__() | |
self.name = name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectorNode(Node): | |
def __init__(self, connector_type): | |
super(ConnectorNode, self).__init__(tree) | |
self.type = connector_type | |
self.operands = [] # For example, in A + B, A and B are operands of + | |
self.state = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for rule in npi_rules: | |
atoms = list(re.sub(REGEX_OP, '', rule.npi_left)) | |
atoms += list(re.sub(REGEX_OP, '', rule.npi_right)) | |
self.atoms.update(dict((atom_str, self.create_atom(atom_str)) for atom_str in atoms)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stack = [] | |
for x in npi_rule: | |
if x not in OPERATORS: | |
stack.append(self.atoms[x]) | |
else: | |
pop0 = stack.pop() | |
pop1 = stack.pop() | |
# If one of the popped element is the same connector that we will create (AND, OR, XOR) | |
if isinstance(pop0, ConnectorNode) and pop0.type is LST_OP[x]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self): | |
self.children = [] # In A => B, => is child of B | |
self.visited = False # When recursively parsing the Graph, it avoids infinite loop | |
self.state = False # Saves if the result is True |
NewerOlder