Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Let's rock on 2021!

Endel Dreyer endel

🚀
Let's rock on 2021!
View GitHub Profile
@endel
endel / dungeon-generator.js
Created Nov 6, 2020
Simple Dungeon Generation Algorithm. Used in https://github.com/endel/mazmorra/
View dungeon-generator.js
// 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 = [];
View lua-ternary-operator.lua
local x = (y > 10) and "condition is true" or "condition is false"
@endel
endel / ecosystem.config.js
Last active Jun 28, 2020
Sample PM2 ecosystem file for deployment
View ecosystem.config.js
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 Mar 28, 2020
Extract parameters of an instance method using TypeScript
View extract-parameters-typeof-typescript.ts
// 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 Dec 18, 2019
Manually generating and using SSL fullchain on Node.js (purchased from ssls.com - Comodo PositiveSSL)
View ssl-fullchain-tutorial.md

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 / aws-ec2-root-node-port-80.sh
Created Dec 4, 2019
Allow non-root node to use ports 80 (HTTP) and 443 (HTTPS) (AWS EC2)
View aws-ec2-root-node-port-80.sh
# Allow non-root node to use ports 80 (HTTP) and 443 (HTTPS)
sudo setcap 'cap_net_bind_service=+ep' $(which node)
@endel
endel / parse-patreon-csv.js
Created Oct 9, 2019
Parse Patreon Members.csv file to output active patron's names (NodeJS)
View parse-patreon-csv.js
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 Aug 7, 2019
Constructor of a type in TypeScript
View constructor-typescript.d.ts
type AConstructorTypeOf<T> = new (...args:any[]) => T;
@endel
endel / strong-signal-usage.ts
Last active Jul 19, 2019
Lightweight Strong Typed Signals in TypeScript
View strong-signal-usage.ts
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) {});
View build.hxml
-main Sandbox.hx
-js Sandbox.js
You can’t perform that action at this time.