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 / t.go
Last active August 21, 2023 06:11
Golang: time without date
package main
import (
"time"
"log"
"errors"
"encoding/json"
)
var timeLayout = "15:04"
@smagch
smagch / index.html
Created August 28, 2018 05:16
horizontal scroll testing: Intersection Observer API
<!DOCTYPE html>
<html>
<head>
<style>
.h-container {
position: absolute;
left: 0;
right: 0;
top: 100px;
height: 300px;
@smagch
smagch / index.html
Last active December 7, 2022 07:40
HTML Canvas text highlighter
<!DOCTYPE html>
<html>
<head>
<title>Strepsirrhini</title>
<meta name="viewport" content="user-scalable=no" />
<style>
body {
margin: 0;
font-size: 1em;
@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 / .dockerignore
Last active November 19, 2022 16:53
AWS: CloudFormation with Elastic Beanstalk, Docker Go web app.
.git
@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;
package main
import (
"crypto/rand"
"log"
"math/big"
)
func sixDigits() int64 {
max := big.NewInt(999999)