Skip to content

Instantly share code, notes, and snippets.

@joakin
joakin / index.html
Last active November 14, 2017 11:30
Standalone React CDN HTML file
<!doctype html>
<html>
<head>
<title>React from CDN Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
@joakin
joakin / webpack-broken-commons.md
Last active November 2, 2017 11:04
Broken webpack commons chunk stuff

master

dist/public/index.e2772e0a6203bb4e7d8c.js              19K
dist/public/pages/about.6cf1f3ef68a498cda3ef.js        2.0K
dist/public/pages/home.027c5030538475eb1253.js         1.9K
dist/public/pages/not-found.2c096c3f04c871042160.js    448B
dist/public/pages/style-guide.d86c4d68eb850d6c36e4.js  2.0K
dist/public/pages/summary.45286bca48ea38c1929b.js      8.1K
dist/public/pages/wiki.670fa01a683d03f3c5df.js         10K
@joakin
joakin / notepad-bookmarklet
Created October 17, 2017 16:32
Notepad bookmarklet
data:text/html, <body style='padding:0;margin:0;overflow:hidden;width:100%;height:100%;' contenteditable><textarea style="width:100%;position:absolute;top:0;left:0;right:0;bottom:0;padding:1em 10%;box-sizing:border-box;font-size:24px;font-family:monospace"></textarea><script>document.querySelector('textarea').focus()</script>
@joakin
joakin / dynamic-header.tsx
Last active October 6, 2017 16:31
Dynamic component type with JSX
export default function HeaderLevel({
level,
children,
...props
}: { level: number } & ChildrenProps & ClassProps): JSX.Element {
const classes = classOf("HeaderLevel", props.class);
const Header = level > 0 && level <= 6 ? `h${level}` : 'div'
return <Header class={classes}>{children}</Header>;
}
@joakin
joakin / get-percentage-stats.js
Last active October 4, 2017 16:54
Get percentage stats of number of projects from phlogiston table
// Run it on http://phlogiston-dev.wmflabs.org/red_status_report.html
// Open devtools, paste all contents
var tbody = document.querySelector("table.bord tbody.list");
var trs = Array.from(tbody.childNodes);
var trsCount = trs.reduce((a, tr) => {
var cell = tr.querySelector("td").textContent;
a[cell] = (a[cell] || 0) + 1;
@joakin
joakin / fonts.css
Created October 2, 2017 12:09
Default sans font using system fonts (wordpress font stack)
body{
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
@joakin
joakin / runtime.js
Created October 2, 2017 10:08
Compiled runtime and vendor
!(function(e) {
function n(r) {
if (t[r]) return t[r].exports;
var o = (t[r] = { i: r, l: !1, exports: {} });
return e[r].call(o.exports, o, o.exports, n), (o.l = !0), o.exports;
}
var r = window.webpackJsonp;
window.webpackJsonp = function(t, a, c) {
for (var u, i, f, s = 0, d = []; s < t.length; s++)
(i = t[s]), o[i] && d.push(o[i][0]), (o[i] = 0);
@joakin
joakin / fonts.css
Last active September 27, 2017 14:37
Font size scale with CSS vars and calc
:root {
--font-size-factor: 1.125;
--font-size-base: 1em;
--font-size-caption: calc(var(--font-size-note) / var(--font-size-factor));
--font-size-note: calc(var(--font-size-base) / var(--font-size-factor));
--font-size-h5: calc(var(--font-size-base) * var(--font-size-factor));
--font-size-h4: calc(var(--font-size-h5) * var(--font-size-factor));
--font-size-h3: calc(var(--font-size-h4) * var(--font-size-factor));
--font-size-h2: calc(var(--font-size-h3) * var(--font-size-factor));
@joakin
joakin / example.tsx
Created August 22, 2017 15:17
What to type
// --- 1
const app: FunctionalComponent<any> = (_props: any):JSX.Element =>
<div class="App">Hello world</div>;
export default app
// --- 2
const app: FunctionalComponent<any> = () =>
@joakin
joakin / async.diff
Created August 9, 2017 09:00
Sync w/ promises to async function
/*
* Get disambiguation links for a given page
* @param {!Request} req
* @return {!BBPromise}
*/
- function getDisambiguationLinks(req) {
+ async function getDisambiguationLinks(req) {
const p = req.params;
const query = {
action: 'query',