Install homebrew/services, this will be helpful, you'll see later. :D
$ brew tap homebrew/services
Parts taken from:
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands
Create droplet in DigitalOcean dashboard
(do not add SSH key during setup)
local:
/** | |
* Expose `isUrl`. | |
*/ | |
module.exports = isUrl; | |
/** | |
* RegExps. | |
* A URL must match #1 and then at least one of #2/#3. | |
* Use two levels of REs to avoid REDOS. |
const measurePromise = (p) => new Promise(async (resolve, reject) => { | |
const startHrTime = process.hrtime(); | |
const res = await p; | |
const elapsedHrTime = process.hrtime(startHrTime); | |
const elapsedTimeInMs = Math.round(elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6); | |
console.log('elapsedTime', elapsedTimeInMs / 1000 + 's'); | |
resolve(res); | |
}); | |
module.exports = measurePromise; |
# You should install youtube-dl locally and on the remote server | |
# To use: ./ytdl [video URL] | |
uuid="$(uuidgen).mp4"; | |
ssh USER@IP_ADDRESS " | |
youtube-dl $1 --output $uuid | |
exit; | |
"; |
/*! Planetary.js 1.1.2 | (c) 2013 Michelle Tilley | Released under MIT License */ | |
!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],function(o,i){return n.planetaryjs=t(o,i,n)}):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){if(t.stopped)return!0;t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<i.onDraw.length;n++)i.onDraw[n]()})},l=function(n,t){for(var o=e.length-1;o>=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var i=0,e=function(n){var t=o.onInit[i];t.length?t(function(){i++,n()}):(t(),i++,setTimeout(n,0))},l=function(){i>=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){n.canvas=t,n.context=t.getContext("2d"),n.stop |
/*! Planetary.js 1.1.2 | (c) 2013 Michelle Tilley | Released under MIT License */ | |
!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],function(o,i){return n.planetaryjs=t(o,i,n)}):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){if(t.stopped)return!0;t.context.clearRect(0,0,o.width,o.height);for(var n=0;n<i.onDraw.length;n++)i.onDraw[n]()})},l=function(n,t){for(var o=e.length-1;o>=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o<t.length;o++)t[o](n)},a=function(n,t,o){if(o.onInit.length){var i=0,e=function(n){var t=o.onInit[i];t.length?t(function(){i++,n()}):(t(),i++,setTimeout(n,0))},l=function(){i>=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){n.canvas=t,n.context=t.getContext("2d"),n.stop |
const TelegramBot = require('node-telegram-bot-api'); | |
// replace the value below with the Telegram token you receive from @BotFather | |
const token = YOUR_TOKEN; | |
// read the doc from https://github.com/yagop/node-telegram-bot-api to know how to catch the chatId | |
const chatId = CHAT_ID; | |
const bot = new TelegramBot(token, { polling: false }); | |
const telegrambot = (message, json) => { |
sudo fallocate -l 1G /swapfile | |
sudo chmod 600 /swapfile | |
sudo mkswap /swapfile | |
sudo swapon /swapfile | |
sudo swapon --show | |
sudo cp /etc/fstab /etc/fstab.bak | |
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab | |
sudo sysctl vm.swappiness=10 | |
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf | |
sudo sysctl vm.vfs_cache_pressure=50 |
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5) | |
shuffleArray([1, 2, 3]) //[3, 1, 2] |