Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@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 / aws-ec2-root-node-port-80.sh
Created December 4, 2019 18:58
Allow non-root node to use ports 80 (HTTP) and 443 (HTTPS) (AWS EC2)
# 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 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
interface Serializer<State, API= any> {
getState() : State;
getAPI() : API;
}
class MyAPI<State> {
state: State;
my() {}
api() {}
methods() {}
// npm install nanoid
import * as generateId from "nanoid/generate";
class MyRoomHandler extends Room {
onInit () {
// this may introduce colliding `roomId`, use at your own risk
this.roomId = generateId("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
}
}
@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>;