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 / remote-library.service.ts
Created January 5, 2021 14:45
Remote Library service: Allows including external resources (scripts and CSS) to the DOM. If the library is already loaded just return the Observable.
import { Injectable, Inject } from '@angular/core';
import { ReplaySubject, Observable, forkJoin } from 'rxjs';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class RemoteLibraryService {
// Ref.: https://codeburst.io/lazy-loading-external-javascript-libraries-in-angular-3d86ada54ec7
@jsanta
jsanta / index.js
Created November 25, 2019 16:08
Postgres stream example using Express + Sequelize
// jshint esversion: 6
/**
* El comentario jshint es para indicar al parser de javascript del editor que se utilizarán
* características de ES6 (EcmaScript 6), como funciones de flecha, const, let, y otros.
*/
/**
* Requeridos para poder definir la API
* - express: permite definir los endpoints de la aplicación
* - cors: permite que los endpoints de la API sean accesibles desde servidores externos
@jsanta
jsanta / index.html
Last active February 12, 2025 13:32
PWA index.html file for Android and iOS copy & paste enabled
<!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: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";
});
}
@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 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 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 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 / 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 / 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"
},