Skip to content

Instantly share code, notes, and snippets.

View jterrazz's full-sized avatar
👀
Hi

Jean-Baptiste Terrazzoni jterrazz

👀
Hi
View GitHub Profile
function addMoneyMiddleware(ctx) {
if (!ctx.money) {
ctx.money = 1
} else {
ctx.money += 1;
}
}
// Lets say a GET /add-money is received
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) => {
# NPM
/node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# misc
.DS_Store
.env*
{
"name": "the-app-name",
"version": "1.0.0",
"description": "",
"main": "src/server.ts",
"scripts": {
"start": "ts-node src/server.ts"
},
"author": "",
"license": "ISC",
console.log('Hello world');
class AtomNode(Node):
def __init__(self, name):
super(AtomNode, self).__init__()
self.name = name
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
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))
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]:
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