Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@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")
@endel
endel / dev_server.php
Last active March 5, 2016 15:29
Simple development server for running PHP projects without having to configure a web application server (nginx, apache, etc)
<?php
//
// Development server.
//
// Requires PHP 5.4+, with built-in web-server feature:
// http://php.net/manual/en/features.commandline.webserver.php
//
// Run it through console via:
// $ php -S localhost:8000 ./dev_server.php
//
@endel
endel / authors.yaml
Last active February 17, 2016 20:31
hook: Example configuration using `belongs_to` / `has_many` relationships and eager-loading. http://github.com/doubleleft/hook
# hook-ext/seeds/authors.yaml
# Generated through command `hook generate:seed authors`
#
# Seed for authors
#
truncate: true
data:
- _id: 1
name: Author one
@endel
endel / psd_export_layers_power_of_two.rb
Created December 22, 2015 14:05
Export Photoshop Layers into power-of-two sized images.
require 'json'
require 'psd'
def is_power_of_two(x)
n = x.to_i
while (((x % 2) == 0) && x > 1)
x = x/2
end
x == 1 && n != 1
end
@endel
endel / array-shufle.js
Created December 12, 2015 22:27
JavaScript one-liner Array shuffle
Array.prototype.shuffle = function() {
for(var j, x, i = this.length; i; j = Math.floor(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
return this;
}
@endel
endel / sample-large.json
Last active November 20, 2015 19:37
JSON samples used for benchmarking msgpack encoder/decoder.
[
{
"_id":"56490c18d9275a0003000000",
"author":null,
"created_at":"2015-11-15T22:50:00.170Z",
"description":"A weekly discussion by Ruby developers about programming, life, and careers.",
"image":"https://s3.amazonaws.com/devchat.tv/ruby-rogues-thumb.jpg",
"keywords":[
"Business",
"Careers",