Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@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 / dungeon-generator.js
Created November 6, 2020 18:45
Simple Dungeon Generation Algorithm. Used in https://github.com/endel/mazmorra/
// Based on: http://breinygames.blogspot.com/2011/07/random-map-generation.html
// Needs improvment:
// - It is possible with small rooms for it to not be closed (i.e. a wall tile missing)
// - Walls often double up (more room spacing?)
var RoomMaze = srm = {
generate: function(gridSize, minRoomSize, maxRoomSize, maxRooms) {
// 1) Create the grid
var grid = [];
@endel
endel / lua-ternary-operator.lua
Created September 24, 2020 21:16
LUA Ternary Operator
local x = (y > 10) and "condition is true" or "condition is false"
@endel
endel / ecosystem.config.js
Last active June 28, 2020 00:30
Sample PM2 ecosystem file for deployment
module.exports = {
apps : [{
name : 'my-app',
script : 'lib/index.js',
watch : false,
instances : 1,
exec_mode : 'fork',
env: {
NODE_ENV: 'development'
}
@endel
endel / extract-parameters-typeof-typescript.ts
Created March 28, 2020 15:21
Extract parameters of an instance method using TypeScript
// Playground link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=19&pc=49#code/C4TwDgpgBAKuEB4YD4oF4oDsIHcoAoA6YgQwCcBzAZwC4oTMQBtAXQEp1UYBuAKF4DGAGxJUqUAEoB7KQFsk6eo1QBvXlChVgJYBAD8dHuqhTMAYTIQdEfFLDAAlqdpKQHNRoC+vb4JFioAFkQaTkoCAAPXUwAE3FQ+RUYhwAzFIhLTGAAcQhsMgcBOi0CzApPVWNTCytdW3snTBcVLBJZCGLgUooAGighCAA3CCE6TABXWQAjDKhPd29fFPHMAUdTKBiIFIdsBUjouNh4BATkZHxjMhlZOEhDHqqG5zoABXI2iF0yKgQASSa2lWEDuiBQTAA5NVLNYISxkEwAAwsXjuHz8LY7bD4YIJPotTCfOgAIj+wCgOCkZAA1lQAITEvoDYajKAARjmbG4QA
type Type<T> = new (...args: any[]) => T;
class Room<T = any> {
state?: T;
onCreate(options: any) {
}
}
@endel
endel / ssl-fullchain-tutorial.md
Created December 18, 2019 02:56
Manually generating and using SSL fullchain on Node.js (purchased from ssls.com - Comodo PositiveSSL)

Before purchasing the SSL certificate, you'll generate a CSR and PEM files:

  • STAR_domainname_com.csr
  • STAR_domainname_com.pem

When purchasing a SSL from ssls.com, they give you these files:

  • STAR_domainname_com.ca-bundle
  • STAR_domainname_com.crt

To generate the fullchain.pem

@endel
endel / parse-patreon-csv.js
Created October 9, 2019 20:55
Parse Patreon Members.csv file to output active patron's names (NodeJS)
const csv = require('csv-parser')
const fs = require('fs')
const patrons = [];
const GENEROUS_PLEDGE = 30;
const GENEROUS_LIFETIME = 200;
fs.createReadStream(process.argv[2])
.pipe(csv())
.on('data', (data) => patrons.push(data))
@endel
endel / constructor-typescript.d.ts
Created August 7, 2019 19:55
Constructor of a type in TypeScript
type AConstructorTypeOf<T> = new (...args:any[]) => T;
@endel
endel / strong-signal-usage.ts
Last active July 19, 2019 20:16
Lightweight Strong Typed Signals in TypeScript
import { createSignal } from "./strong-signal"
// declare the signal
const onNumber = createSignal<(num: number) => void>();
// ok
onNumber(function(num) {});
// compilation error! second argument not allowed
onNumber(function(num, secondArg) {});
-main Sandbox.hx
-js Sandbox.js