Skip to content

Instantly share code, notes, and snippets.

View inline-es-modules.js
const files = {
"m1.js": `import {func} from './m2.js'; console.log(func());`,
"m2.js": `export function func() { return 'abc'; }`
}
const urls = new Map
function getURL(filename) {
let url = urls.get(filename)
if (!url) {
@javan
javan / optimized-screenshots.md
Created Jul 8, 2019
macOS: Optimized Screenshots
View optimized-screenshots.md
😱 Before: ~/Desktop/Screen Shot….png 4.1 MB
🏆 After: ~/Screenshots/Screen Shot….png 937 KB

 

  1. Install https://pngquant.org/
    $ brew install pngquant
@javan
javan / add-sf-mono-to-firefox.md
Created Jun 11, 2019
Add SF Mono to Firefox (macOS only)
View add-sf-mono-to-firefox.md

GitHub uses the following CSS font stack to display code:

font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace;

Chrome will use SFMono-Regular when that font is installed locally, but Firefox will not. Workaround: Add the following CSS to your Firefox profile's userContent.css file:

@font-face {
@javan
javan / test.html
Last active Jun 24, 2018 — forked from triskweline/test.html
Custom Elements v0 vs. DOMParser
View test.html
<!doctype html>
<html>
<head>
<title>Custom elements test</title>
</head>
<body>
<h3>Custom elements from HTML</h3>
<ol class="from-html" start="0">
@javan
javan / webpack-fixme.md
Created May 30, 2018
Ideas for improving webpack.config.js
View webpack-fixme.md

This is the example webpack.config.js on https://webpack.js.org/:

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  }
}
View trix_color_attributes.coffee
getHexColor = (color) ->
return "" unless color
return color if /^#/.test(color)
rgbValues = getRGBValues(color)
hexValues = rgbValues.map(numberToHex)
"#" + hexValues.join("")
numberToHex = (number) ->
"0#{number.toString(16)}".slice(-2).toUpperCase()
View buggy_mutation_observer_workaround.ts
(async () => {
if (await mutionObserverIsBuggy()) {
patchInnerHTML()
}
})()
function mutionObserverIsBuggy(): Promise<boolean> {
return new Promise(resolve => {
const element = document.createElement("div")
element.innerHTML = "<a><em></em></a>"
@javan
javan / direct-uploads.md
Last active Mar 19, 2019
Active Storage direct uploads
View direct-uploads.md
@javan
javan / index.html
Created Jun 9, 2017
Electron <webview> document.visibiltyState
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div style="margin: 20px;">
<p>
&lt;webview&gt; visibilityState: <strong id="visibility-state"></strong>
<button id="update-visibility-state">Update</button>
@javan
javan / bc_require_element.coffee
Created Nov 28, 2016
<bc-require>: Basecamp 3's lazy JavaScript loader
View bc_require_element.coffee
BC.registerElement "bc-require",
createdCallback: ->
@setAttribute("pending", "")
attachedCallback: ->
BC.ready =>
if Loader.find(@script)?.loaded
@activate()
else
@deactivate()