Read this
How to Obtain and Automatically Renew SSL Certs with Let’s Encrypt on Node.js
To avoid havinng to enter a password every time you log in to a server, you can instead use SSL keys.
Enter the following command to start generating a rsa keypair:
1 | ssh-keygen |
When the message ‘Enter file in which to save the key’ appears, just leave the filename blank by pressing Enter.
When the terminal asks you to enter a passphrase, just leave this blank too and press Enter.
Then copy the keypair onto the server with one simple command:
1 | ssh-copy-id userid@hostname |
you can now log in without a password:
1 | ssh userid@hostname |
By default, a touch-enabled device allows a user to pan and zoom a web app. But sometimes this is not something that’s appropriate for an app.
Here’s how to prevent these gestures from messing up your web app:
1 | html, body { |
This will prevent single-finger panning, and two-finger pinch zooming on all elements. This does not, however, disable the double-tap to zoom feature. Disabling double-tap zoom requires a different method.
This zoom effect can be annoying, as clicking a button twice can invoke it.
In order to prevent it, place a listener for dblclick
on the element being clicked:
1 | // gobble up the 'dblclick' event |
Another option to disable double-tap to zoom is with CSS:
1 | /* disable double-tap to zoom */ |
This disables double-tap to zoom, but it enables panning and pinch zoom.
There are many web hosting services that provide ways to monitor your running server and restart it when necessary. But not all of them do, and if you’re stuck like I was on a shared server with no such fancy pants watcher, you may find this simple method using common tools useful.
The watcher script simply runs one time and checks if a server process is running, and if it isn’t, starts it.
In my case, I needed to manually set my $PATH variable, otherwise the cron job wouldn’t be able to run node:
1 | set PATH so cron job can find and execute 'node' |
The next part of the script uses the ps aux
command to see if my server processes are running. If all are running, the script exits early.
In my case, I am looking for two processes: index.js
and encrypt.js
:
1 |
|
This one liner bears some explanation:
1 | (ps aux|grep "index.js"|grep -v "grep"|wc -l) |
It evaluates to 1 if “index.js” is running, 0 if it’s not. (the grep -v "grep"
bit is needed, because the prior grep "index.js"
often shows up as a process in ps aux
).
The remainder of the script simply restarts my server processes:
1 | using pm2, delete then restart my server processes |
Use crontab -e
to add a cron job single line that will run my script every minute, logging stdout
and stderr
:
1 | # |
With just a simple script and one cron job line, I now have a watcher that restarts my web services whenever necessary. Which is pretty important, because the shared server I’m using reboots often, but it doesn’t restart my services.
When building a site or app with Gulp, you often simply need to copy a folder and all of its contents recursively.
Doing it simply is tricky, unless you know this simple incantation:
*
after the folder name (myfolder*
)/**/*
for recursive copymyfolder*/**/*
1 | // recursively copy 'css', 'imgs', and 'fonts' to `dist` directory: |
The results, displayed here using tree command (another nifty tool):
1 | dist |