Skip to content

Instantly share code, notes, and snippets.

@hizo
hizo / keybase.md
Created September 9, 2019 13:28
Keybase

Keybase proof

I hereby claim:

  • I am hizo on github.
  • I am hizo (https://keybase.io/hizo) on keybase.
  • I have a public key ASBXvqlNLGhuYt-zsfOzcK11OYKqGpDzbWXiVWUhLcJKMgo

To claim this, I am signing this object:

@hizo
hizo / copy-to-clipboard.js
Created December 31, 2018 08:45
Vanilla copy to clipboard
const copy = content => {
const textArea = document.createElement('textarea')
textArea.style.maxHeight = '0px'
textArea.style.height = '0px'
textArea.style.opacity = '0'
textArea.value = content
document.body.appendChild(textArea)
textArea.select()
try {
window.document.execCommand('copy')
@hizo
hizo / pwa.md
Last active July 31, 2018 09:42
PWA

Progressive Web Apps

A PWA lets you install the application from the browser window itself, is available on your phone like a native app, and works offline, just like a native app.

Requirements

Here is a summary of all requirements from google: https://developers.google.com/web/progressive-web-apps/checklist

The minimum are:

@hizo
hizo / data-fetching-hocs.js
Created July 27, 2018 09:05
React data fetching HOCs
// The same api state machine as before
const withApiState = TargetComponent =>
class extends React.Component {
state = {
current: "idle"
};
apiState = {
pending: () => this.setState({ current: "pending" }),
success: () => this.setState({ current: "success" }),
@hizo
hizo / kubernetes.md
Last active March 13, 2019 22:37
Kubernetes useful commands
@hizo
hizo / service-workers.js
Created December 29, 2016 01:12
Service workers easy way
swPrecache.write(path.resolve(__dirname, `../public/service-worker.js`), {
cacheId: `know-it-all`,
filename: `service-worker.js`,
stripPrefix: `public/`,
staticFileGlobs: [
`public/app.*.js`, // don't include the polyfills version
`public/*.{html,ico,json,png}`,
],
dontCacheBustUrlsMatching: [
/\.(js|json)$/, // I'm cache busting js and json files myself
@hizo
hizo / file-hash.js
Created December 29, 2016 01:11
File hash
const fileHash = crypto.createHash('md5').update(fileContents).digest('hex');
@hizo
hizo / script-loading.js
Created December 29, 2016 01:10
Script loading
var scripts = ['app.a700a9a3e91a84de5dc0.js']; // script for all users
var newBrowser = (
'fetch' in window &&
'Promise' in window &&
'assign' in Object &&
'keys' in Object
);
if (!newBrowser) {
@hizo
hizo / font-defaults.css
Created December 29, 2016 01:09
Font defaults
body {
color: #212121;
font-family: "Helvetica Neue", "Calibri Light", Roboto, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
letter-spacing: 0.02em;
}
const windowPopup = (url, width, height) => {
const left = (screen.width / 2) - (width / 2),
top = (screen.height / 2) - (height / 2);
window.open(
url,
"",
"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left
);
}