Skip to content

Instantly share code, notes, and snippets.

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

Magnus 'Bagzy' Thor MagnusThor

🏠
Working from home
  • Freelancer & member of coloquium
  • Sweden
View GitHub Profile
@MagnusThor
MagnusThor / DOMUtils.ts
Created February 26, 2025 17:54
Utils functions that i used regularly, i not that keen to use massive framework for tiny web app, less is more!
export class DOMUtils {
static value<T>(selector: string, value?: any) {
const element = DOMUtils.get<HTMLInputElement>(selector);
if (value && element) element!.value = value;
return element ? element.value as T : null;
}
static get<T extends HTMLElement>(selector: string, parent?: Element | DocumentFragment | null): T | null { // Allow null
if (!parent) {
@MagnusThor
MagnusThor / greenscreenmshitfix.ts
Last active May 26, 2021 19:09
Snapshot , dump of virtual-bg example broski dosiki, kushki khleb
import { GreenScreenStream, GreenScreenMethod } from "../../src/GreenScreenStream";
document.addEventListener("DOMContentLoaded", () => {
const bgfile = location.hash.length > 0 ? location.hash.replace("#", "") : "beach.jpg"
navigator.getUserMedia({ video: { width: 640, height: 360 }, audio: false }, (ms: MediaStream) => {
let instance = GreenScreenStream.getInstance(true, `../assets/${bgfile}`, undefined, 640, 360);
instance.onReady = () => {
const fps = 60;
instance.initialize().then(result => {
instance.start(GreenScreenMethod.VirtualBackground);
@MagnusThor
MagnusThor / p.json
Created August 12, 2020 21:11
Points 5x5 ( 25 joints )
let pp =
[[0,4],[0,3],[0,2],[0,1],[0,0],[1,0],[2,0],[3,0],[4,0],[4,1],[4,2],[4,3],[4,4],[3,4],[3,3],[3,2],[3,1],[2,1],[1,1],[1,2],[1,3],[1,4],[2,4],[2,3],[2,2]]
@MagnusThor
MagnusThor / client.ts
Created July 30, 2020 12:53
thor.io.client-vnext tiuny example
import { ClientFactory, WebRTCFactory, BinaryMessage, TextMessage, Controller } from 'thor-io.client-vnext'
export class TestClient{
factory: ClientFactory;
controller: Controller;
constructor(){
this.factory = new ClientFactory("ws://localhost:1337",["example"],{});
this.factory.onOpen = (controller: Controller) => {
this.controller = controller;
@MagnusThor
MagnusThor / Server.ts
Created July 30, 2020 12:52
Set up a ThorIO Server on Express
import path from "path";
import fs from "fs";
import http from "http";
import https from "https";
import express from "express";
import webSocket from "ws";
import { ExampleController } from "./controllers/ExampleController";
import { BrokerController } from "../src/Controllers/BrokerController/Broker";
import { ThorIO } from "..";
@MagnusThor
MagnusThor / ExampleController.ts
Created July 30, 2020 12:50
thor-io.vnext ExampleController
import { CanSet } from '../../src/Decorators/CanSet';
import { CanInvoke } from '../../src/Decorators/CanInvoke';
import { ControllerProperties } from '../../src/Decorators/ControllerProperties';
import { ControllerBase } from "../../src/Controller/ControllerBase";
import { BinaryMessage } from 'thor-io.client-vnext';
import { Connection } from '../../src/Connection/Connection';
interface IMyModel{
age:number;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
uniform sampler2D iChannel0;
vec3 mcol=vec3(0.);
float randSeed;
void randomize(vec2 c){randSeed=fract(sin(dot(c,vec2(113.421,17.329)))*3134.1234);}
float rand(){return fract(sin(randSeed++)*3143.45345);}
precision highp float;
uniform sampler2D S;
uniform sampler2D R;
uniform vec2 X;
// Combines 2 buffers, blurred in directions [0,1] and [sin(120°), cos(120°)] to create hexagon
// bokeh pattern. Technique I got from DICE that they used in Frostbyte engine.
void main() {
gl_FragColor = vec4(0);
for (int i = 0; i < 10; i++) {
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;