Skip to content

Instantly share code, notes, and snippets.

@Dobby89
Dobby89 / WithPrivates.js
Created August 16, 2017 16:06
Get and set private property in a javascript class
const PRIVATE_PROPERTY_1 = new Symbol();
class WithPrivates {
get prop1(){
return this[PRIVATE_PROPERTY_1];
}
set prop1(value){
if(typeof value == 'number'){
@Dobby89
Dobby89 / htmlToElement.js
Last active January 16, 2018 08:41
Create a DOM element from a string
/**
* Create a DOM element from a string
*
* @param {String} e.g. `<div><span>Hello World</span></div>`
* @return {Element}
*/
export function htmlToElement(htmlString) {
const wrapper = document.createElement('div');
wrapper.innerHTML = htmlString;
document.body.appendChild(wrapper);
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
indent_style = tab
indent_size = tab
tab_width = 4
end_of_line = lf
charset = utf-8
@Dobby89
Dobby89 / htmlToFragment.js
Created January 4, 2018 13:25
Create a DOM element from a string without having to append to a containing <div>
/**
* Create a DOM element from a string without
* having to append to a containing <div>
*
* @param {String} e.g. `<div><span>Hello World</span></div> Foo bar`
* @return {Element}
*/
export function htmlToFragment(htmlString) {
const fragment = document.createDocumentFragment();
const wrapper = document.createElement('div');
@Dobby89
Dobby89 / gulpfile.js
Created February 20, 2018 08:43
Temp backup of gulpfile changes when making lazyload
/* eslint-disable max-len, no-process-env */
/*
Project setup...
*/
const AO_FEA_GLOBALS_PATH = 'node_modules/ao-globals/'; // Change path to point at root globals
const PROJECT_NAME = 'pc-gaming-cat-pages'; // Change project name to your project name
const PROJECT_SERVER_PATH = '//media.ao.com/uk/qa/pc-gaming-cat-page/'; // Change project server path to your project path
/*
https://ao.com/lg
@Dobby89
Dobby89 / partiallyApply.js
Last active July 5, 2018 12:21
Apply an initial set of params to a method. Similar to bind() but without having to pass `this`
/**
* partiallyApply
*
* Apply an initial set of params to a method.
* Similar to bind() but without having to pass `this`
*
* @param {function} fn
* @param {*} initialArgs
*/
function partiallyApply(fn, ...initialArgs) {
@Dobby89
Dobby89 / node-gyp.md
Created June 13, 2018 07:11
How to install node-gyp on Windows
@Dobby89
Dobby89 / rInterval.js
Last active July 9, 2018 10:42
More accurate/consistent interval using requestAnimationFrame
/**
* A more consistent interval than the native setInterval.
* Should help prevent the time drifting.
*
* @param {function} callback
* @param {integer} delay
*/
const rInterval = function (callback, delay) {
let requestAnimation = window.requestAnimationFrame;
let start = Date.now();
@Dobby89
Dobby89 / cloudSettings
Last active March 19, 2020 08:17
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-03-18T16:06:51.760Z","extensionVersion":"v3.4.3"}