Skip to content

Instantly share code, notes, and snippets.

View jneums's full-sized avatar
🏠
Working from home

Jesse jneums

🏠
Working from home
View GitHub Profile
@jneums
jneums / webWorker.js
Created July 27, 2021 22:40 — forked from vitkon/webWorker.js
Long polling with web workers
function workerFunction() {
this.addEventListener('message', (e) => {
console.log('log2: ', e);
fetchUrl(e.data);
})
const fetchUrl = (url) => {
fetch(url)
.then((response) => {
console.log(response);
@jneums
jneums / numpy.ipynb
Last active August 11, 2020 18:37
numpy.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jneums
jneums / ormconfig.json
Created July 30, 2020 21:23
Quick config for setting up TypeORM
{
"type": "sqlite",
"username": "test",
"password": "test",
"database": "./data/games.db",
"synchronize": true,
"logging": true,
"entities": [
"src/entity/**/*.ts"
],
@jneums
jneums / CRUDCommandFactory.ts
Last active August 3, 2020 02:19
Factory pattern for creating commands relevant to the domain level
import { CreateGame } from './'
import ICommandConfig from '../../../common/ICommandConfig'
export class CRUDCommandFactory implements ICommandFactory {
makeCommand = (config:ICommandConfig) => {
if (config.commandName == CreateGame.name) {
return new CreateGame(config.args)
} else {
@jneums
jneums / GameCommandFactory.ts
Last active August 3, 2020 02:19
Factory for creating game commands with access to the application layer
import { POSTCommand } from './POSTGameCommand'
import ICommandConfig from '../../../common/ICommandConfig'
export class GameCommandFactory implements ICommandFactory {
makeCommand = (config:ICommandConfig) => {
if (config.commandName == POSTCommand.name) {
return new POSTCommand(config.args)
} else {
throw new Error('Command not found!')
}
@jneums
jneums / server.ts
Created July 30, 2020 20:29
Updated server using TypeORM
import * as express from "express";
import gamesRouter from './routes/games'
const morgan = require('morgan')
import {createConnection} from "typeorm";
const app = express();
app.use(morgan('tiny'))
@jneums
jneums / Games.ts
Created July 30, 2020 20:25
TypeORM games entity
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
@Entity()
export class Games {
@PrimaryGeneratedColumn()
id: number;
@Column({ nullable: true })
Name: string;
@jneums
jneums / CreateGameCommand.ts
Last active August 3, 2020 02:19
Command in the domain level for creating game
import { Games } from "../../../entity/Games";
import { getManager } from "typeorm";
export class CreateGame implements ICommand {
private game:Games;
constructor(game:Games) {
this.game = game
}
@jneums
jneums / POSTGameCommand.ts
Last active August 3, 2020 02:20
Command for calling into the domain
import { Games } from "../../../entity/Games";
import * as DomainGameCommands from '../../domain/games';
export class POSTCommand implements ICommand {
private game:Games;
constructor(game:Games) {
this.game = game
}
@jneums
jneums / games.ts
Last active July 30, 2020 20:44
Games route with POST
var express = require('express')
var gamesRouter = express.Router()
import * as AppGameCommands from '../commands/application/games'
import { Games } from "../entity/Games";
const gameCommandFactory = new AppGameCommands.GameCommandFactory()
gamesRouter.post('/create', (req, res, next) => {