Skip to content

Instantly share code, notes, and snippets.

View ducksoupdev's full-sized avatar

Matt Levy ducksoupdev

View GitHub Profile
@ducksoupdev
ducksoupdev / service-worker.js
Created February 19, 2021 09:53 — forked from revsmoke/service-worker.js
An example of a service worker for serving network first, cache second
// the cache version gets updated every time there is a new deployment
const CACHE_VERSION = 10;
const CURRENT_CACHE = `main-${CACHE_VERSION}`;
// these are the routes we are going to cache for offline support
const cacheFiles = ['/', '/about-me/', '/projects/', '/offline/'];
// on activation we clean up the previously registered service workers
self.addEventListener('activate', evt =>
evt.waitUntil(
@ducksoupdev
ducksoupdev / dom-tree-depth-level.js
Created December 18, 2019 06:20 — forked from JasonRammoray/dom-tree-depth-level.js
Get depth of a DOM tree with a list of nodes included into longest path
function getDomDepthLevel(root = document.documentElement) {
let pathInfo = {
route: [],
level: 0
};
for (let i = 0, j = root.children.length; i < j; i++) {
const curNodePathInfo = getDomDepthLevel(root.children[i]);
if (curNodePathInfo.level > pathInfo.level) {
pathInfo = curNodePathInfo;
}
@ducksoupdev
ducksoupdev / service-worker-ghost-cms.js
Created July 25, 2019 09:04 — forked from mordka/service-worker-ghost-cms.js
Service Worker for Ghost CMS - ignore Ghost admin
const cacheName = 'blogCache';
const offlineUrl = '/offline/';
const adminPageSlug = '/ghost';
/**
* The event listener for the service worker installation
*/
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName)
@ducksoupdev
ducksoupdev / HTMLElementPlus.js
Created November 1, 2018 16:24 — forked from AdaRoseCannon/HTMLElementPlus.js
HTML Element Plus for Web Components
'use strict';
class HTMLElementPlus extends HTMLElement {
static defaultAttributeValue() {
/* the name of the attribute is parsed in as a parameter */
return;
}
static parseAttributeValue(name, value) {
@ducksoupdev
ducksoupdev / index.html
Created October 30, 2018 21:15 — forked from malbernaz/index.html
JSX Web components
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>webcomponents test</title>
<style>
body {
margin: 0;
@ducksoupdev
ducksoupdev / Article.md
Created September 27, 2018 04:49 — forked from Warry/Article.md
How to make faster scroll effects?

How to make faster scroll effects?

  • Avoid too many reflows (the browser to recalculate everything)
  • Use advanced CSS3 for graphic card rendering
  • Precalculate sizes and positions

Beware of reflows

The reflow appens as many times as there are frames per seconds. It recalculate all positions that change in order to diplay them. Basically, when you scroll you execute a function where you move things between two reflows. But there are functions that triggers reflows such as jQuery offset, scroll... So there are two things to take care about when you dynamically change objects in javascript to avoid too many reflows:

@ducksoupdev
ducksoupdev / scroll-listener.js
Created September 27, 2018 04:49
60FPS onscroll event listener
(function() {
var lastScrollY = 0;
var ticking = false;
var update = function() {
// do your stuff
ticking = false;
};
var requestTick = function() {
@ducksoupdev
ducksoupdev / inject_css_js.js
Created July 31, 2018 12:54 — forked from calderonsteven/inject_css_js.js
inject css and js via javascript
function includeCSSfile(href) {
var head_node = document.getElementsByTagName('head')[0];
var link_tag = document.createElement('link');
link_tag.setAttribute('rel', 'stylesheet');
link_tag.setAttribute('type', 'text/css');
link_tag.setAttribute('href', href);
head_node.appendChild(link_tag);
}
function includeJavascript(src) {
@ducksoupdev
ducksoupdev / public_enc_example.sh
Created July 24, 2018 09:06 — forked from thinkerbot/public_enc_example.sh
Public-key encryption example using OpenSSL
#!/bin/bash
#
# Public-Key Encryption and Decryption
# * http://www.openssl.org/
# * http://barelyenough.org/blog/2008/04/fun-with-public-keys/
#
# Mac OS X 10.6.4
# OpenSSL 0.9.8l 5 Nov 2009
# Generate keys
@ducksoupdev
ducksoupdev / RSACryptoService.cs
Created July 24, 2018 08:59 — forked from beginor/RSACryptoService.cs
C# RSACryptoService with openssl rsa key
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace CMCloud.SaaS
{