This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasLocalStorage = typeof window !== 'undefined' && !!window.localStorage; | |
export const set = (key: string, data: any) => { | |
if (!hasLocalStorage) return undefined; | |
try { | |
const string = typeof data === 'string' ? data : JSON.stringify(data); | |
return localStorage.setItem(key, string); | |
} catch (err) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear(); | |
(async () => { | |
const list = ['one', 'two', 'three']; | |
const doSlowly = msg => new Promise(resolve => { | |
setTimeout(() => { | |
resolve(`Processed ${msg}`); | |
}, 100); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const zlib = require('zlib'); | |
const PORT = 3001; | |
const STATIC_DIRECTORY = path.resolve(__dirname, '../build/'); | |
const cache = {}; | |
const getStaticFile = fileName => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adapted from https://github.com/sindresorhus/github-markdown-css | |
The MIT License (MIT) | |
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http2 = require('http2'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const zlib = require('zlib'); | |
const brotli = require('brotli'); // npm package | |
const PORT = 3032; | |
const BROTLI_QUALITY = 11; // slow, but we're caching so who cares | |
const STATIC_DIRECTORY = path.resolve(__dirname, '../dist/'); | |
const cache = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## AWS | |
# from http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-categories | |
http://169.254.169.254/latest/user-data | |
http://169.254.169.254/latest/user-data/iam/security-credentials/[ROLE NAME] | |
http://169.254.169.254/latest/meta-data/iam/security-credentials/[ROLE NAME] | |
http://169.254.169.254/latest/meta-data/ami-id | |
http://169.254.169.254/latest/meta-data/reservation-id | |
http://169.254.169.254/latest/meta-data/hostname | |
http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logColor(color, args) { | |
console.log(`%c ${args.join(' ')}`, `color: ${color}`); | |
} | |
const log = { | |
aliceblue: (...args) => { logColor('aliceblue', args)}, | |
antiquewhite: (...args) => { logColor('antiquewhite', args)}, | |
aqua: (...args) => { logColor('aqua', args)}, | |
aquamarine: (...args) => { logColor('aquamarine', args)}, | |
azure: (...args) => { logColor('azure', args)}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const zlib = require('zlib'); | |
const file = fs.readFileSync('./some_file.js'); | |
const rawSize = file.length; | |
const gzippedSize = zlib.gzipSync(file).length; | |
console.log('Raw size: ', (rawSize / 1000), 'KB'); | |
console.log('Gzipped size: ', (gzippedSize / 1000), 'KB'); | |
console.log('Compression: ', `${100 - Math.round(gzippedSize / rawSize * 1000) / 10}%`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list lines of code by file type: | |
`npx sloc --format cli-table src/` | |
# print out update/version info about your project's packages | |
`npx npm-check` | |
# display a breakdown of package contents by size (for a CRA page) | |
`npx source-map-explorer build/static/js/main.*` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy/paste this into your Dev Tools console while on https://medium.com/me/stats | |
// You can save it as a snippet in Chrome if you like: https://developers.google.com/web/tools/chrome-devtools/snippets | |
console.clear(); | |
(() => { | |
console.info('Remember to scroll down first to load all your articles'); | |
const formatPercent = rawValue => `${(rawValue * 100).toFixed(1)}%`; | |
const tableHeaderCell = document.querySelector('.sortableTableHeaders tr').insertCell(); | |
tableHeaderCell.textContent = 'Fans/views'; |
NewerOlder