Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@endel
endel / generateUserAgent.ts
Created September 13, 2018 23:41
Fake User Agent Generator
export function* generateUserAgent() {
let webkitVersion = 10;
let chromeVersion = 1000;
const so = [
'Windows NT 6.1; WOW64',
'Windows NT 6.2; Win64; x64',
"Windows NT 5.1; Win64; x64",,
'Macintosh; Intel Mac OS X 10_12_6',
"X11; Linux x86_64",
///<reference types="mocha" />
import { assert, expect } from "chai";
import { StateContainer, DataChange } from "../src";
function clone (data: any) {
return JSON.parse(JSON.stringify(data));
}
describe("StateContainer", () => {
let container: StateContainer<any>;
@endel
endel / fossil-delta-js-checksum.js
Last active October 26, 2017 13:13
Benchmarking checksum when applying delta using fossil-delta-js: https://github.com/dchest/fossil-delta-js/pull/1
var Benchmark = require('benchmark');
var fs = require('fs');
var path = require('path');
var fossilDelta = require('../fossil-delta.js');
// Silence error logging.
fossilDelta.logError = function() {}
var makeArray = function(buf) {
var a = new Array(buf.length);
@endel
endel / concat-benchmark.ts
Last active October 20, 2017 21:43
Manual concat performs better than `Array.prototype.concat `.
import * as Benchmark from "benchmark";
// Array.prototype.concat()
const concat = function(...args: any[]) {
let arr = [1,2,3]
return arr.concat(args);
};
// "concat" manually, performs better
const manual = (...args: any[]) => {
@endel
endel / new.ts
Created December 11, 2016 21:46
Colyseus.js - patch handling comparison from v0.5.x to v0.6.x (not released yet)
// ...
registerListeners () {
this.room.state.listen("cars/:id", "add", (clientId: string, value: any) => {
this.addCar(clientId, value);
});
this.room.state.listen("cars/:id", "remove", (clientId: string) => {
this.view.removeCar(clientId);
});
@endel
endel / colyseus-patch-handling.md
Created December 9, 2016 15:04
Colyseus.js feature proposal: better patch handling

In the current client version, you currently need to loop through all incoming patch list, and manually check for interesting messages to handle.

Example from tic-tac-toe

room.onPatch.add(function(patches) {
  for (let i=0; i<patches.length; i++) {
    let patch = patches[i]

 if (patch.op === "add" &amp;&amp; patch.path === "/currentTurn") {
@endel
endel / benchmark.js
Created December 3, 2016 22:01
Benchmark between "fast-json-patch" and "deep-diff" modules.
const deep = require('deep-diff');
const jsonpatch = require('fast-json-patch');
const Benchmark = require('benchmark');
var obj1 = {
name: "Hello",
number: 10,
deep: [1,2,3,4],
deepObj: {
arr: [1,2,3],
@endel
endel / InteractionManagerMixin.js
Created August 17, 2016 15:22
PIXI v4: minimal event bubbling working
import PIXI = require("pixi.js");
/**
* @mixin
*/
export let InteractionManagerMixin = {
processInteractive: function (point, displayObject, func, hitTest, interactive) {
let eventTargets: PIXI.DisplayObject[] = [];
@endel
endel / chat_room.js
Last active March 1, 2021 13:55
Colyseus: using the same room handler for multiple rooms.
var Room = require('colyseus').Room
class ChatRoom extends Room {
constructor (options) {
super( options )
this.name = options.name;
this.setState({ messages: [] })
@endel
endel / conver.pe
Last active August 16, 2024 21:03
FontForge script to convert .ttf file to its webfont variations (.otf, .svg, .woff, .woff2)
#!/usr/local/bin/fontforge
Open($1)
Generate($1:r + ".otf")
Generate($1:r + ".svg")
Generate($1:r + ".woff")
Generate($1:r + ".woff2")