Skip to content

Instantly share code, notes, and snippets.

View kenreilly's full-sized avatar
💻
asdf

Ken Reilly kenreilly

💻
asdf
View GitHub Profile
@kenreilly
kenreilly / ws-api.ts
Last active September 15, 2023 20:52
WebSocket API class
import { WebSocketMessage, WebSocketMessageType } from "../../common/ws-message.js"
export class WebSocketAPI {
private static command_table: {[name:string]: Function} = {
'ping': WebSocketAPI.ping,
'echo': WebSocketAPI.echo
}
public static handle(message: WebSocketMessage): Promise<WebSocketMessage> {
@kenreilly
kenreilly / ws-frame.ts
Last active September 15, 2023 20:49
WebSocket frame class
export enum WebSocketOpcode {
CONTINUE = 0x0,
TEXT = 0x1,
BINARY = 0x2,
CLOSE = 0x8
}
export abstract class WebSocketFrame {
@kenreilly
kenreilly / ws-router.ts
Last active September 15, 2023 20:33
WebSocket router class
import * as crypto from 'node:crypto'
import { IncomingMessage } from 'node:http'
import { Duplex } from "node:stream";
import { AppConfig } from '../app-config.js'
import { WebSocketOpcode, WebSocketFrame } from './ws-frame.js';
import { WebSocketMessage } from '../../common/ws-message.js';
import { WebSocketAPI } from './ws-api.js';
export class WebSocketRouter {
@kenreilly
kenreilly / static-app-router.ts
Last active September 15, 2023 20:30
Static app router class
import * as path from 'node:path'
import * as fs from 'node:fs'
import { Dirent } from 'node:fs'
import { IncomingMessage, ServerResponse } from 'node:http'
import { StaticAppFile } from "./static-app-file.js"
import { AppConfig } from '../app-config.js'
export class StaticAppRouter {
private content: { [url: string]: StaticAppFile } = {}
@kenreilly
kenreilly / static-app-file.ts
Last active September 15, 2023 20:30
Static app file class
import * as fs from 'node:fs'
export enum ContentType {
html = 'text/html',
css = 'text/css',
js = 'application/javascript',
ts = 'application/typescript',
map = 'application/octet-stream'
}
@kenreilly
kenreilly / app-server.ts
Last active September 15, 2023 20:14
Application server class
// import * as http from 'node:https'
import * as http from 'node:http'
import { IncomingMessage, ServerResponse } from 'node:http'
import { StaticAppRouter } from './static-app/static-app-router.js'
import { WebSocketRouter } from './websocket/ws-router.js'
import { AppConfig } from './app-config.js'
class AppServer {
private config: AppConfig
@kenreilly
kenreilly / app-config.ts
Last active September 15, 2023 20:13
App configuration class
import * as path from 'node:path'
import * as fs from 'node:fs'
export class AppConfig {
public static readonly ws_rfc_guid: string = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
public readonly server_root: string = process.cwd()
public readonly app_dirs: Array<string> = [
'css/',
@kenreilly
kenreilly / main.ts
Last active January 13, 2022 08:59
TypeScript Infinite Scroll main.ts
class App {
static get random_items(): Array<number> {
return Array.from({length: 10}, () => Math.random() * 10 )
}
static content_el: HTMLElement
static init() {
@kenreilly
kenreilly / style.css
Last active January 13, 2022 08:48
TypeScript Infinite Scroll style.css
:root {
--header-height: 8vh;
--item-height: 15vh;
}
body, html {
height: 100vh;
width: 100vw;
overflow: hidden;
margin: 0;
@kenreilly
kenreilly / index.html
Last active January 13, 2022 08:49
TypeScript Infinite Scroll index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>TypeScript Infinite Scroll</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
</head>