Skip to content

Instantly share code, notes, and snippets.

View ducksoupdev's full-sized avatar

Matt Levy ducksoupdev

View GitHub Profile
@ducksoupdev
ducksoupdev / js_array_dedupe.js
Created March 16, 2019 18:22
Dedupe objects from Array
const books = [
{ name: "x", author: "y" },
{ name: "a", author: "b" },
{ name: "x", author: "y" }
]
const filteredBooks = [...new Set(books.map(b => JSON.stringify(b)))].map(b => JSON.parse(b))
console.log(filteredBooks)
@ducksoupdev
ducksoupdev / html2emmet.js
Last active January 14, 2019 17:25
HTML to Emmet
const jsdom = require('jsdom')
const { JSDOM } = jsdom
function allDescendants (html, node) {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i]
let s = '+('
if (i === 0) {
s = '>'
}
@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() {
['/css/font-awesome.css', '/css/font-populaire.css'].forEach(function (f) {
var gf = document.createElement('link')
gf.rel = 'stylesheet'
gf.href = f
gf.type = 'text/css'
var gd = document.getElementsByTagName('link')[0]
gd.parentNode.insertBefore(gf, gd)
})
(function (window, document) {
// do stuff
})(window, document)
@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