Skip to content

Instantly share code, notes, and snippets.

View daliborgogic's full-sized avatar
:octocat:
In Git we trust!

Dalibor Gogic daliborgogic

:octocat:
In Git we trust!
View GitHub Profile
@daliborgogic
daliborgogic / entry-client.js
Last active July 1, 2019 09:51
Vue.js SPA Google Analytics
// https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
)
@daliborgogic
daliborgogic / App.vue
Last active September 3, 2018 22:39
Notify when caching is complete or new or updated content is available
<script>
mounted () {
window.addEventListener('online', () =>
store.dispatch('snackbar', { id: 0, show: false })
)
window.addEventListener('offline', () =>
store.dispatch('snackbar', { id: 0, show: true })
)
@daliborgogic
daliborgogic / service-worker-dev.js
Created June 22, 2017 16:49
Service worker dev
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// In the production build, this file is replaced with an actual service worker
// file that will precache your site's local assets.
// See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
self.addEventListener('install', () => self.skipWaiting())
self.addEventListener('activate', () => {
self.clients.matchAll({ type: 'window' }).then(windowClients => {
@daliborgogic
daliborgogic / Icons.vue
Last active June 26, 2017 12:35
SVG sprite Vue.js component
<!-- set pug as language, jade is only for gist sintax highlight -->
<template lang="jade">
- var background = 'path(d="M0 0h24v24H0z" fill="none")'
svg(height="0" width="0" style="position:absolute; margin-left: -100%;")
//- If your shape consist of many small chunks, you’ll need to wrap them all with a g tag and add an ID to that group.
g#check-box-outline
#{background}
path(d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z")
g#check-box
#{background}
window.addEventListener('load', () => {
const t = performance.timing
// Log performance details:
for (const key of [
'fetchStart',
'connectStart',
'connectEnd',
'requestStart',
'responseStart',
'responseEnd',
@daliborgogic
daliborgogic / Icon-Settings.vue
Created July 18, 2017 19:47
Using ARIA to enhance SVG accessibility
<template lang="pug">
svg.icon.icon-settings(
fill="#000000"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
role="img"
aria-labelledby="iconSettingsTitle iconSettingsDescription"
)
const CACHE_NAME = '$$$toolbox-cache$$$http://localhost:5000/$$$'
function linkIsAvailableOffline (links) {
links.forEach(link => {
const HREF = link.getAttribute('href')
caches.open(CACHE_NAME).then(cache => {
cache.match(HREF).then(response => {
link.setAttribute('data-offline', response ? true : false)
})
@daliborgogic
daliborgogic / index.js
Created July 24, 2017 16:56
Get, set, delete cookie
const setCookie = (name, value, days = 7, path = '/') => {
const expires = new Date(Date.now() + days * 864e5).toUTCString()
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=${path}`
}
const getCookie = name => {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=')
return parts[0] === name ? decodeURIComponent(parts[1]) : r
}, '')
dlbr@lnx:~/dev/dlbr-pwa$ npm outdated
Package Current Wanted Latest Location
contentful 4.5.0 4.5.2 4.5.0 dlbr-pwa
dlbr@lnx:~/dev/dlbr-pwa$ npx npm-check -u
npx: installed 218 in 5.926s
❤️ Your modules look amazing. Keep up the great work. ❤️
dlbr@lnx:~/dev/dlbr-pwa$ npm update
+ [email protected]
added 120 packages and updated 4 packages in 4.263s
npm i

cat > .env << EOL
CONTENTFUL_SPACE=
CONTENTFUL_DELIVERY_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_ACCESS_TOKEN=
CONTENTFUL_INITIAL_SYNC=true
EOL