Skip to content

Instantly share code, notes, and snippets.

View smagch's full-sized avatar
🗾
Japan

Shimaguchi Tomoya smagch

🗾
Japan
View GitHub Profile
@smagch
smagch / strict.py
Last active November 22, 2022 15:35
python decorator that cast argument type
from typing import Any, Callable, TypeVar, Type, cast, Union, Protocol
from functools import singledispatchmethod
T = TypeVar("T", int, str)
def stricttype(
type_: Type[T],
) -> Callable[[Callable[[Any, Any], None]], Callable[[Any, T], None]]:
def inner(method: Callable[[Any, Any], None]) -> Callable[[Any, T], None]:
@smagch
smagch / dispatch.py
Created July 16, 2022 13:33
Safe way for implementing singledispatch
from functools import singledispatch
from dataclasses import dataclass
from typing import Union, get_args
@dataclass
class Foo:
id: str
name: str
@smagch
smagch / README.md
Last active June 18, 2022 09:34
recursive reducer demo

Recursive reducer demo

The script reducer.ts demonstrates reducer implementation for tree-structured data.

@smagch
smagch / panedemo.html
Created June 17, 2022 05:52
horizontal pane
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,
@smagch
smagch / useTimeout.js
Created July 16, 2020 06:02
useTimeout React hook
const useTimeout = (delay) => {
const [ timeoutFunc, setFunction ] = useState(null);
useEffect(
() => {
if (!timeoutFunc) {
return;
}
let mounted = true;
@smagch
smagch / convert_4k.sh
Created May 12, 2020 13:44
convert multiple movies
#!/usr/bin/env bash
distdir="$(pwd)/dist$RANDOM$RANDOM"
mkdir "$distdir"
for input in "$@"; do
base=$(basename "$input")
output="$distdir/${base,,}"
ffmpeg -i "$input" \
@smagch
smagch / encode_4k.sh
Last active March 20, 2020 17:48
ffmpeg for a6400
# ffmpeg -i input.mp4 -crf 28 -b:a 128k -color_range 1 -color_trc arib-std-b67 -color_primaries bt2020 -colorspace bt2020nc output_28.mp4
# ffmpeg -i output28.mp4 -c copy -map 0 -segment_time 00:01:00 -reset_timestamps 1 -f segment output_%03d.mp4
ffmpeg -i input.mp4 -crf 28 -b:a 128k -color_range 1 -color_trc arib-std-b67 -color_primaries bt2020 -colorspace bt2020nc -segment_time 60 -f segment -reset_timestamps 1 output_%03d.mp4
@smagch
smagch / index.html
Created November 26, 2019 04:14
open/collapse for an element with `height: auto`
<html>
<head>
<style>
.item {
display: block;
overflow: hidden;
}
.head {
height: 30px;
line-height: 30px;
@smagch
smagch / index.html
Created October 16, 2019 15:59
iOS focus test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>iOS focus Test</title>
<style>
.modal {
transition: opacity 0.3s;
@smagch
smagch / hook.js
Last active June 28, 2019 16:32
react hooks: resize check
import { useState, useEffect } from 'react';
import { debounce } from 'lodash';
export const useResizeState = () => {
const [ resizing, setResizing ] = useState(false);
useEffect(() => {
const handleResizeEnd = debounce(() => {
setResizing(false);
}, 300);