Skip to content

Instantly share code, notes, and snippets.

Federico Zivolo FezVrasta

View GitHub Profile
@FezVrasta
FezVrasta / import.sh
Last active Jun 30, 2020 — forked from whistler/import.sh
Copy files to another repository while saving git history
View import.sh
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git clone <git repository A url> # clone source repository
cd <git repository A directory>
git remote rm origin # to make sure it doesn't affect the original repository
git filter-repo --path <directory 1> # remove all files other than the ones needed
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed)
mv * <directory 1>
git add .
git commit -m "moved to <directory 1>"
View gist:3a59b77636b97379c28497d5ee85af96
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
}
.push {
width: 2000px;
View bug.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
}
.push {
width: 2000px;
View apocalypseHandler.js
window.addEventListener('error', async err => {
// Since we are handling the error here, we must make
// sure we log it into the console nonetheless, otherwise
// it will be very difficult to understand why your app
// is crashing.
console.error(err);
// If no service worker is available, our work ends here
// because we don't need to unregister the service worker
// to make sure the user is able to get a newer version of
View useServiceWorker.js
serviceWorker.register({
onUpdate: registration => {
setWaitingServiceWorker(registration.waiting);
setUpdateAvailable(true);
},
onWaiting: waiting => {
setWaitingServiceWorker(waiting);
setUpdateAvailable(true);
}
});
View serviceWorker.js
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
// WE ADD THE CODE BELOW
if (registration.waiting) {
if (config && config.onWaiting) {
config.onWaiting(registration.waiting);
}
}
View serviceWorker.js
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
// WE ADD THE CODE BELOW
if (registration.waiting) {
if (config && config.onWaiting) {
config.onWaiting(registration.waiting);
}
}
View index.js
import { ServiceWorkerProvider, useServiceWorker } from './useServiceWorker';
const App = () => {
const { isUpdateAvailable, updateAssets } = useServiceWorker();
return (
<div>
Hello, World!
{isUpdateAvailable && (
View serviceWorker.js
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
View useServiceWorker.js
const ServiceWorkerContext = React.createContext();
export const ServiceWorkerProvider = ({ children }) => {
const [waitingServiceWorker, setWaitingServiceWorker] = useState(null);
const [isUpdateAvailable, setUpdateAvailable] = useState(false);
React.useEffect(() => {
serviceWorker.register({
onUpdate: registration => {
setWaitingServiceWorker(registration.waiting);
You can’t perform that action at this time.