Skip to content

Instantly share code, notes, and snippets.

View frankinedinburgh's full-sized avatar

digital-doodle frankinedinburgh

  • Front End Developer
  • Dublin, Ireland
View GitHub Profile
@frankinedinburgh
frankinedinburgh / size.js
Last active July 26, 2018 15:03
get the size of a directory in bytes using node
// EXPORT THE SIZE OF A DIRECTORY USING NODE
const fs = require('fs');
const path = require('path');
const yargs = require('yargs');
const argv = yargs.argv;
const dist = argv.dir;
// du -ach ./dist // unix command
const walkSync = (dir, filelist = []) => {
@frankinedinburgh
frankinedinburgh / screenshot.js
Created July 16, 2018 15:43
take a web screenshot using node puppeteer
const puppeteer = require('puppeteer');
const site = process.argv[2];
async function getPic() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(site, {waitUntil: 'networkidle2'});
@frankinedinburgh
frankinedinburgh / queryStringToJSON.js
Created July 15, 2018 11:10
convert a query string to a JSON object
export const queryStringToJSON = (query) => {
const setValue = (root, path, value) => {
if (path.length > 1){
const dir = path.shift();
if (typeof root[dir] == 'undefined') {
root[dir] = path[0] === '' ? [] : {};
}
arguments.callee(root[dir], path, value);
} else {
if (root instanceof Array) {
@frankinedinburgh
frankinedinburgh / loadScript.js
Created July 15, 2018 11:09
dynamically load a script
const loadScript = (() => {
const _loadedScripts = {};
return (src) => {
if (_loadedScripts[src]) {
return _loadedScripts[src];
}
return ( // eslint-disable-line no-return-assign
_loadedScripts[src] = new Promise(_injectScriptTag)
@frankinedinburgh
frankinedinburgh / hash.js
Created July 15, 2018 11:07
hash a string
export default function hash(str) {
var hash = 0, i, chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
@frankinedinburgh
frankinedinburgh / compatibleBrowser.js
Created July 15, 2018 11:06
detect compatible browser
const minimumChromeCompatableVersion = 53;
export default function detectIncompatibleBrowser() {
/*
-- INCOMPATIBLE browsers --
whatsmybrowser.org/b/PC36ZMV
whatsmybrowser.org/b/UMYYENJ
whatsmybrowser.org/b/QJ96W2C
whatsmybrowser.org/b/9PU8664
whatsmybrowser.org/b/NZ7QMK4
@frankinedinburgh
frankinedinburgh / SassMeister-input.scss
Created August 14, 2015 21:43
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
.border{
$colour: red;
border:{
bottom: 3px solid $colour{
left:{
radius:20px;
@frankinedinburgh
frankinedinburgh / 0_reuse_code.js
Last active August 29, 2015 14:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console