Skip to content

Instantly share code, notes, and snippets.

@ksk1015
ksk1015 / ItemListInVirtualScroll.tsx
Last active September 8, 2024 17:27
ばかでか配列とかをバーチャルスクロールで表示するコンポーネント
import { useState, useDeferredValue } from 'react'
type Props<T> = {
height: number
items: T[]
maxItemCount?: number
itemHeight: number
bufferCount?: number
renderItem: (item: T, index: number) => JSX.Element
onRender?: (lastIndex: number) => void
@ksk1015
ksk1015 / omikuji-button.js
Created August 30, 2024 13:33
Omikuji Button
customElements.define(
'omikuji-button',
class extends HTMLElement {
#isRunning = false
#text
constructor() {
super()
this.#text = document.createTextNode('-')
const button = document.createElement('button')
@ksk1015
ksk1015 / build.js
Last active September 16, 2024 21:35
esbuildでビルドされたCSSをJSに埋め込む
import esbuild from 'esbuild'
import { fileURLToPath, URL } from 'node:url'
import fs from 'node:fs'
const entryPoint = fileURLToPath(new URL('../src/app.js', import.meta.url))
const outdir = fileURLToPath(new URL('../dist', import.meta.url))
// ビルドされたcssをjsに埋め込む
function injectCssToJs(outputFilename = (jsFilename) => jsFilename) {
return {
@ksk1015
ksk1015 / GoogleMapMarker.vue
Last active February 4, 2023 00:23
Google Map Marker を描画する vueコンポーネントの雑なサンプル
<script lang="ts" setup>
const props = defineProps<{
map: google.maps.Map;
item: Item
selected: boolean
}>();
const emits = defineEmits<{
(e: 'toggleSelect', item: Item): void;
}>();
@ksk1015
ksk1015 / original.svg
Last active November 12, 2022 00:20
shrink Twemoji 🥹 svg (2,953 Byte -> 1,590 Byte)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ksk1015
ksk1015 / ftp-deploy.yaml
Last active October 1, 2020 03:51
Github actions FTP deploy
# FTP-Deploy-Action@3.1.1 だとなぜか
# /usr/bin/git ftp push --force --auto-init --verbose --syncroot=./ --user=*** --passwd=*** --remote-root *** ***
# fatal: Unrecognised option: ***
# 差分のみアップロードするとのことだが、全部アップロードしてた
name: FTP deploy
on:
push:
branches:
function smoothScroll (scroller, endY) {
if (typeof scroller === 'number') {
endY = scroller;
scroller = window;
}
const startY = scroller === window ? scroller.pageYOffset : scroller.scrollTop;
const maxY = (scroller === window) ?
document.documentElement.scrollHeight - document.documentElement.clientHeight :
scroller.scrollHeight - scroller.clientHeight;
endY = Math.min(endY, maxY);
function my_enqueue_inline_style ( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
if ( $src ) {
wp_enqueue_style( $handle, $src, $deps, false, $media );
}
add_filter( 'style_loader_tag', function ( $html, $this_handle, $href, $media ) use ($handle) {
if ($this_handle !== $handle) {
return $html;
}
$css_url = explode('?', $href)[0];
$css_path = str_replace(site_url(), ABSPATH, $css_url);
function my_enqueue_inline_script ($handle, $src = false, $deps = array(), $ver = false, $in_footer = false) {
if ( $src ) {
wp_enqueue_script( $handle, $src, $deps, false, $in_footer );
}
add_filter( 'script_loader_tag', function ( $tag, $this_handle, $src ) use ($handle) {
if ($this_handle !== $handle) {
return $tag;
}
$url = explode('?', $src)[0];
$path = str_replace(site_url(), ABSPATH, $url);
@ksk1015
ksk1015 / add_shortcode_template.php
Created October 23, 2018 10:42
wordpress ショートコードをファイルで管理しやすくするための、ファイルのパスを引数にショートコードを生成する関数
function add_shortcode_template ($name, $template = '') {
if ( !$template ) {
$template = $name;
$name = basename($template, '.php');
}
if ( !preg_match('/\.php$/', $template) ) {
$template .= '.php';
}
$template = get_template_directory() . '/' . $template;
add_shortcode($name, function ($atts, $content = '') use ($template) {