Skip to content

Instantly share code, notes, and snippets.

@nexpr
nexpr / evlogger.js
Created July 10, 2021 12:53
イベントリスナ形式のロガー
export const createLogger = (id, parent) => {
const listeners = parent?.listeners || {}
const logger = {}
const on = (type, fn) => {
if (!listeners[type]) {
listeners[type] = new Set()
}
listeners[type].add(fn)
}
<!doctype html>
<meta charset="utf-8" />
<style>
* {
box-sizing: border-box;
}
body {
height: 100vh;
@nexpr
nexpr / lcsv.js
Created June 26, 2021 08:35
制限付き CSV パーサ / 列情報が必要 / 列数は固定 / 列ごとにクオートの有無と変換する型を指定
const lcsvp = (cols, opt) => {
const cols_def = cols.map((c) => (typeof c === "boolean" ? { quote: c } : c))
const cols_restr = cols_def.map((c) => (c.quote ? `"((?:[^"]|"")*?)"` : "([^,]*?)")).join(opt?.space ? " *, *" : ",")
const row_re = new RegExp(`^${cols_restr}(?:\r?\n|$)`)
const cols_formatter = cols_def.map((x) => (x.type === JSON ? JSON.parse : x.type || String))
const unescape = (str, ci) => (cols_def[ci].quote ? str.replace(/""/g, '"') : str)
return (text) => {
const rows = []
while (text) {
@nexpr
nexpr / get-namespace-items.php
Last active June 8, 2021 08:38
指定の名前空間に定義・宣言されたものの一覧を取得
<?php
function get_namespace_items($namespace, $include_sub_namespaces = false) {
$namespace = trim($namespace, '\\') . '\\';
$classes = get_declared_classes();
$interfaces = get_declared_interfaces();
$traits = get_declared_traits();
$functions = get_defined_functions();
$constants = get_defined_constants();
@nexpr
nexpr / 01.js
Created June 5, 2021 02:59
CustomElement の属性でプロパティを渡す / 属性ではプロパティ名の指定 / getRootNode() で取得できる Node の context オブジェクトから検索
class Base extends HTMLElement {
constructor() {
super()
const root = this.attachShadow({ mode: "open" })
root.context = {}
for (const name of this.bind_properties) {
Object.defineProperty(this, name, {
get() {
const attr = this.getAttribute(name)
@nexpr
nexpr / example.html
Last active June 4, 2021 11:15
leaflet map に多くの位置を表示する を CustomElement 化したもの
<!DOCTYPE html>
<meta charset="UTF-8">
<title>poffice map</title>
<style>
positions-map {
position: fixed;
top: 0;
left: 0;
right: 0;
<!DOCTYPE html>
<meta charset="utf-8" />
<title>enex preview and convert</title>
<style>
* {
box-sizing: border-box;
}
body {
@nexpr
nexpr / prevent-navigation.js
Last active June 2, 2021 15:56
prevent navigation module
const set = new Set()
window.addEventListener("beforeunload", (event) => {
if (set.size) {
event.returnValue = "prevent"
}
})
export const prevent = (key) => {
set.add(key)
@nexpr
nexpr / 3d.html
Created May 30, 2021 04:42
3d example
<!doctype html>
<style>
.cvs {
background: #eee;
width: 500px;
height: 100px;
margin: 30px auto;
display: flex;
perspective: 400px;
@nexpr
nexpr / example.md
Last active May 17, 2021 07:20
縦書き

Example

let text = `
あいう
えお
かきくけこ
`.trim()

console.log(text)