Skip to content

Instantly share code, notes, and snippets.

View tacigar's full-sized avatar
🏠
Working from home

tacigar tacigar

🏠
Working from home
View GitHub Profile
@tacigar
tacigar / ChatGPTButton.tsx
Created March 19, 2023 16:10
ChatGPTとの問答の末にできたボタンコンポーネント
import React from 'react';
type ButtonAnchorProps = {
href: string;
} & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>;
type ButtonButtonProps = {
href?: never;
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
import { useCallback, useState, useEffect } from "react";
const X = () => {
const [count, setCount] = useState(0);
const handleClick = useCallback(() => {
setCount((prev) => prev + 1);
}, []);
return <button onClick={handleClick}>Button1 ({count})</button>;
};
@tacigar
tacigar / viewBox.html
Created August 8, 2021 00:17
viewBox
<!DOCTYPE html>
<html>
<body>
<svg preserveAspectRatio="xMinYMin meet" viewBox="0 0 80 80" width="40" height="120">
<circle cx="40" cy="40" r="40" />
</svg>
<svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 80 80" width="40" height="120">
<circle cx="40" cy="40" r="40" />
</svg>
<svg preserveAspectRatio="xMaxYMax meet" viewBox="0 0 80 80" width="40" height="120">
@tacigar
tacigar / bubblesort.go2
Created July 25, 2021 04:58
Go Generic Bubble Sort
package sort
type Ordered interface {
type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64, string
}
func BubbleSort[T Ordered](slice []T) {
for i := 0; i < len(slice)-1; i++ {
done := true
for j := 1; j < len(slice)-i; j++ {
@tacigar
tacigar / useUploadImage.tsx
Created July 11, 2021 14:04
画像をアップロードするHook
import React, { useCallback, useState } from 'react';
const useUploadImage = (url: string, file: File) => {
const [state, setState] = useState<{
uploadPercent: number;
downloadPercent: number;
state:
| 'none'
| 'uploading'
| 'downloading'
@tacigar
tacigar / ImageUploader.tsx
Last active July 10, 2021 08:53
Very simple image uploader
import React, { useCallback } from 'react';
import { useState } from 'react';
interface ImageUploaderProps {}
const ImageUploader: React.FC<ImageUploaderProps> = () => {
const [imageUrl, setImageUrl] = useState('');
const handleDrop = useCallback((event: React.DragEvent<HTMLDivElement>) => {
event.preventDefault();
local field = {}
for i = 1, 9 do
local buf = io.read()
field[i] = {}
for j = 1, 9 do
field[i][j] = tonumber(buf:sub(j, j))
end
end
@tacigar
tacigar / example.dat
Created February 19, 2018 23:59
駅データ.jp から駅の緯度経度情報を取得し KML を出力する Lua スクリプト
# JR山手線
- 西日暮里
- 田端
- 駒込
- 巣鴨
- 大塚
- 池袋
- 目白
- 高田馬場
- 新大久保
wget https://www.lua.org/ftp/lua-1.1.tar.gz
mkdir lua-1.1
tar zxvf lua-1.1.tar.gz -C lua-1.1 --strip-components 1
cd lua-1.1
sed -i -e "21 s/\$/ -lc/" src/Makefile
sed -i -e "14 s/^/\/\//" clients/lib/iolib.c
sed -i -e "21 s/stdin/NULL/" clients/lib/iolib.c
sed -i -e "21 s/stdout/NULL/" clients/lib/iolib.c
sed -i -e "472i in=stdin; out=stdout;" clients/lib/iolib.c
sed -i -e "20 s/\$/ -lm -lc -L\$(LIB) -llua/" clients/lib/Makefile
@tacigar
tacigar / yacc-grammar-extractor.cpp
Last active February 14, 2018 17:00
y.output から文法情報のみを抽出
#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
#include <unordered_map>
auto main() -> int
{
while (true) {