Skip to content

Instantly share code, notes, and snippets.

View jsanta's full-sized avatar

Jose Ignacio Santa Cruz G. jsanta

View GitHub Profile
@jsanta
jsanta / mem-monitor.sh
Created July 13, 2018 19:26
Script to restart PM2 procceses if memory exceeds limit
#!/bin/bash
memtotal=$(free | grep Mem | awk '{ print $2 }')
memuse=$(free | grep Mem | awk '{ print $3 }')
let "memusepercent = $memuse * 100 / $memtotal "
let "memtolerance = $memtotal * 0.9 "
echo "MemTotal: $memtotal (Usage tolerance: $memtolerance )"
echo "MemUsed: $memuse ($memusepercent %)"
if [ $memuse -ge $memtolerance ]; then
echo "Memory use over 90%"
@jsanta
jsanta / some_available_site
Last active October 1, 2018 21:38
some_available_site configuration file for nginx, result of some research and certbot generated configuration
server {
root /opt/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name your_server www.your_server;
location / {
# First attempt to serve request as file, then
@jsanta
jsanta / another_available_site
Last active October 1, 2018 21:38
Sample sites_available configuration for nginx where port 8123 redirects to another server (eg a NodeJS Express app) running on port 3218. This configuration considers WebSocket and CORs support.
server {
listen 8123 default_server;
listen [::]:8123 default_server;
server_name your_server;
add_header Strict-Transport-Security "max-age=31536000";
access_log /var/log/nginx/some_app.access.log;
error_log /var/log/nginx/some_app.error.log;
location / {
@jsanta
jsanta / manifest.json
Created January 1, 2019 18:45
Sample PWA manifest.json file
{
"name": "Ionic",
"short_name": "Ionic",
"start_url": "index.html",
"display": "standalone",
"icons": [{
"src": "assets/imgs/logo-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
@jsanta
jsanta / service-worker.js
Last active January 1, 2019 18:57
Service worker for PWA Sample app. Please note it uses sw-toolbox.
/**
* Check out https://googlechromelabs.github.io/sw-toolbox/ for
* more info on how to use sw-toolbox to custom configure your service worker.
*/
'use strict';
importScripts('./bower_components/sw-toolbox/sw-toolbox.js');
self.toolbox.options.cache = {
@jsanta
jsanta / index.html
Created January 1, 2019 18:53
index.html for including the manifest.json and registering the service worker.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Ionic App</title>
<base href="/" />
<meta
name="viewport"
@jsanta
jsanta / index.html
Created January 1, 2019 19:20
Defer installation script for PWAs (copy & pasted from https://developers.google.com/web/fundamentals/app-install-banners/ )
<script type="text/javascript">
// ...
// Ref. https://developers.google.com/web/fundamentals/app-install-banners/
function addToHomeScreen() {
let a2hsBtn = document.querySelector(".ad2hs-prompt"); // hide our user interface that shows our A2HS button
a2hsBtn.style.display = 'none'; // Show the prompt
deferredPrompt.prompt(); // Wait for the user to respond to the prompt
deferredPrompt.userChoice
@jsanta
jsanta / index.html
Created January 1, 2019 19:28
PWA index.html file with copy & pastable defered installation prompt
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Ionic App</title>
<base href="/" />
<meta
name="viewport"
@jsanta
jsanta / index.html
Created January 1, 2019 20:00
PWA (essentially it applies to most cases) script for iOS and navigation mode detection
<script>
//...
// Detects if device is on iOS
const isIos = () => {
const userAgent = window.navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test( userAgent );
}
// Detects if device is in standalone mode
const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone);
@jsanta
jsanta / index.html
Created January 1, 2019 20:07
iOS and navigation mode detection script
<script>
//...
function showIosInstall() {
let iosPrompt = document.querySelector(".ios-prompt");
iosPrompt.style.display = "block";
iosPrompt.addEventListener("click", () => {
iosPrompt.style.display = "none";
});
}