Skip to content

Instantly share code, notes, and snippets.

@jmblog
jmblog / rehype-remove-style-attrs.ts
Last active October 5, 2021 06:05
rehype plugin to remove all style attributes
import { Transformer } from 'unified';
import { Element } from 'hast';
import { visit } from 'unist-util-visit';
export default function rehypeRemoveStyleAttrs(): Transformer {
return (tree) => {
visit(tree, 'element', (node: Element) => {
if (node.properties?.style) {
node.properties.style = undefined;
}
// https://letsbuildui.dev/articles/building-a-dropdown-menu-component-with-react-hooks
import { useState, useEffect, RefObject } from 'react';
export const useDetectOutsideClick = (ref: RefObject<HTMLElement>, initialState: boolean) => {
const [isActive, setIsActive] = useState(initialState);
useEffect(() => {
const pageClickEvent = (event: MouseEvent) => {
// If the active element exists and is clicked outside of
if (ref.current !== null && !ref.current.contains(event.target as Node)) {
// https://www.netlify.com/blog/2017/07/18/http/2-server-push-on-netlify/
const debug = require('debug')('nuxt:netlify-http2-server-push');
const path = require('path');
const glob = require('glob');
const fs = require('fs');
module.exports = function module(moduleOptions) {
// This module is only enabled on production builds
if (this.options.dev) {
@jmblog
jmblog / file0.txt
Last active December 5, 2017 05:33
Vanilla JS や TypeScript で Custom Elements を書く際の注意点 ref: https://qiita.com/jimbo/items/d17a121f815236c2f55b
Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
@jmblog
jmblog / karabiner.json
Last active November 12, 2017 00:47
かなキーで「英数/かな」のトグル切り替え(Karabiner-Elements 11.1.8以上が必要)
{
"profiles": [
{
"complex_modifications": {
"rules": [
{
"description": "Toggle input source (English or Japanese) by kana key (available since Karabiner-Elements 11.1.8)",
"manipulators": [
{
"conditions": [
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"strictNullChecks": true,
"removeComments": true,
"module": "commonjs",
"target": "es5",
"jsx": "react"
@jmblog
jmblog / .editorconfig
Created December 28, 2016 01:16
My .editorconfig
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
@jmblog
jmblog / file0.txt
Last active November 7, 2016 00:46
CI のビルド時に patch を適用する際の注意点 ref: http://qiita.com/jimbo/items/1643523195b03f53e860
# 1回目
$ patch --batch -p0 -i xxx.patch
patching file node_modules/foo/bar/xxx
# 2回目
$ patch --batch -p0 -i xxx.patch
patching file node_modules/foo/bar/xxx
Reversed (or previously applied) patch detected! Assuming -R. # 元に戻ってしまう
@jmblog
jmblog / bash_prompt
Created May 23, 2014 11:30
Bash prompt customization
#!/usr/bin/env bash
# Check that terminfo exists before changing TERM var to xterm-256color
# Prevents prompt flashing in Mac OS X 10.6 Terminal.app
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
export TERM='xterm-256color'
fi
# Turn off standout; turn off underline
tput sgr 0 0