Skip to content

Instantly share code, notes, and snippets.

View jinjor's full-sized avatar

Yosuke Torii jinjor

View GitHub Profile
class SelectListElement extends HTMLElement {
constructor() {
super();
this.addEventListener("click", e => {
let target = e.target as Element;
while (target.parentElement !== this) {
target = target.parentElement;
}
if (target instanceof SelectItemElement) {
e.stopPropagation();
class ConfirmButtonGroupElement extends UtilizedElement {
static get observedAttributes() {
return ["disabled"];
}
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.innerHTML = html`
${styles}
type MIDIInputMap = Map<DOMString, MIDIInput>; // maplike
type MIDIOutputMap = Map<DOMString, MIDIOutput>; // maplike
type DOMString = string;
interface MIDIAccess extends EventTarget {
readonly inputs: MIDIInputMap;
readonly outputs: MIDIOutputMap;
onstatechange: (e: MIDIConnectionEvent) => void;
readonly sysexEnabled: boolean;
}
@jinjor
jinjor / domsync.ts
Last active February 6, 2019 02:07
export abstract class DomSync<T, Context extends unknown[]> {
constructor(
private root: Element | Document | ShadowRoot,
private selector?: string
) {}
abstract readonly class: string;
protected identify(obj: T): string | number {
const o = obj as any;
if (o && (typeof o.id === "string" || typeof o.id === "number")) {
return String(o.id).trim();
const BASE_HELTZ = 440;
function generateId() {
return Math.random()
.toString(36)
.substr(2, 9);
}
function noteToHz(note: number) {
return BASE_HELTZ * 2 ** ((note - 69) / 12);
}
const fs = require("fs");
const childProcess = require("child_process");
childProcess.exec("./node_modules/.bin/elm-analyse", (e, out) => {
let file;
let all = {};
for (let line of out.split("\n")) {
if (line.startsWith("-")) {
file = line.slice(2);
continue;
@jinjor
jinjor / 1-problem.ts
Last active January 1, 2019 14:53
Loop Problem
let count = 0;
async function* loop() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 3000));
yield count++;
}
}
(async () => {
for await (const n of loop()) {
console.log(n);
type alias OriginalFoo =
{ barText : Maybe String
, mustNum : Int
}
type alias Foo =
{ barText : String
, mustNum : Int
const fs = require("fs");
const fetch = require("node-fetch");
const readline = require("readline");
run().catch(err => {
console.error(err.message);
process.exit(1);
});
async function run() {

How elm make --optimize works

func-level DCE func-level DCE(kernel) rename record/constructor rename all unwrap constructor minify
default
--optimize
--optimize + uglifyjs