Skip to content

Instantly share code, notes, and snippets.

Andrew Golightly magician11

Block or report user

Report or block magician11

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
magician11 / install-certbot-ubuntu
Last active Jun 5, 2018
How to install certbot on Ubuntu for Nginx
View install-certbot-ubuntu
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
magician11 / nodejs-cron.js
Last active May 1, 2018
How to get a Node.js function to run once on the last day of each month
View nodejs-cron.js
const moment = require('moment');
const someAction = () => console.log('Actioning...');
const wait = ms => new Promise((resolve, reject) => setTimeout(resolve, ms));
const startCron = async () => {
while (true) {
if (
moment().date() ===
magician11 / tweetnacl-test.js
Last active Jan 8, 2020
How to encrypt and decrypt a message with TweetNaCl.js
View tweetnacl-test.js
const tweetnacl = require('tweetnacl'); //
tweetnacl.util = require('tweetnacl-util'); //
// utility function to display the Uint8Array
const asciiArmored = arr => tweetnacl.util.encodeBase64(arr);
// generate the key to encrypt a message
const secretKey = tweetnacl.randomBytes(32);
console.log(`secret key: ${asciiArmored(secretKey)}`);
magician11 / timezones.js
Created Mar 2, 2018
How to use Node.js to display the time now in a different timezone
View timezones.js
const moment = require('moment-timezone'); //
const timestamp = new Date();
.tz('America/Vancouver') // find your zone here
.format('dddd, MMMM Do YYYY, h:mm:ss a (UTC Z)')
magician11 / crontab
Last active Apr 30, 2018
How to automatically restart a Node.js script (with forever) on a server reboot
View crontab
@reboot cd /var/server/script-directory && /root/.nvm/versions/node/v8.11.1/bin/forever start myscript.js
magician11 /
Last active Jan 19, 2018
How to add pre and post hooks for Certbot automatic renewals running Nginx
# renew_before_expiry = 30 days
version = 0.19.0
archive_dir = /etc/letsencrypt/archive/
cert = /etc/letsencrypt/live/
privkey = /etc/letsencrypt/live/
chain = /etc/letsencrypt/live/
fullchain = /etc/letsencrypt/live/
# Options used in the renewal process
magician11 / default
Last active Jan 19, 2018
Reverse proxy with Nginx to Node.js server with HTTP to HTTPS redirect
View default
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$server_name$request_uri;
server {
# SSL configuration
listen 443 ssl http2 default_server;
magician11 /
Last active Mar 1, 2018
Server block example for a WordPress site on Nginx on a DigitalOcean droplet
server {
listen 80;
client_max_body_size 20M;
port_in_redirect off;
access_log /var/log/nginx/;
error_log /var/log/nginx/ error;
root /var/www/goforself;
index index.php;
magician11 / config.js
Last active Dec 2, 2017
How to send an email from Node.js using Gmail
View config.js
module.exports = {
email: {
address: '',
password: 'clever-password'
magician11 / google-oauth.js
Last active Nov 12, 2017
How to get a new Google access token from a refresh token on Node.js
View google-oauth.js
const axios = require('axios');
const querystring = require('querystring');
const keys = require('../config/keys');
const getAccessToken = async refreshToken => {
try {
const accessTokenObj = await
refresh_token: refreshToken,
You can’t perform that action at this time.