This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp | |
server, but for some reason omit a client connecting to it. I added an | |
example at the bottom. | |
Save the following server in example.js: | |
*/ | |
var net = require('net'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defined first due to TDZ | |
let weighted = (...weightMap) => weightMap | |
.map(({0: value, 1: weight}) => new Array(weight).fill(value)) | |
.reduce((acc, current) => [...acc, ...current]); | |
let random = (array) => array[Math.floor(Math.random() * array.length)]; | |
// You can generate a weighted array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=hello_env.js - making your environment variables rad | |
Documentation=https://example.com | |
After=network.target | |
[Service] | |
Environment=NODE_PORT=3001 | |
Type=simple | |
User=root | |
ExecStart=/usr/bin/node /home/ubuntu/hello_env.js |