Skip to content

Instantly share code, notes, and snippets.

View curegit's full-sized avatar

curegit curegit

View GitHub Profile
@curegit
curegit / Unit.cs
Created October 20, 2021 04:58
C# でのユニット型実装
using System;
using System.Diagnostics.CodeAnalysis;
[Serializable]
public struct Unit : IEquatable<Unit>, IComparable, IComparable<Unit>
{
public override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Unit;
}
@curegit
curegit / Forklift.cgs
Created October 19, 2021 08:57
組合せゲーム Forklift の定義 (CGSuite)
class Forklift extends Game
var boxes;
method Forklift(List boxes)
end
method MakeLeftOptions(Number left, Number left2, List right)
if left == 0 then
return Forklift([left2, right].Flatten);
@curegit
curegit / Subtraction.cgs
Created October 19, 2021 08:48
組合せゲーム Subtraction の定義 (CGSuite)
class Subtraction extends ImpartialGame
var lrset; // The subtraction set
var n; // The heap size
method Subtraction(Set lrset, Number n)
end
override method Options(Player player)
return setof(Subtraction(lrset, n - k) for k in lrset where n - k >= 0);
@curegit
curegit / eratosthenes.py
Last active January 30, 2023 02:32
エラトステネスの篩で素数を無限に列挙する
from itertools import count
def prime():
def sieve(ints):
i = next(ints)
yield i
for n in sieve(k for k in ints if k % i != 0):
yield n
return sieve(count(2))
@curegit
curegit / twtimerename.py
Last active September 25, 2021 09:34
Twitter から保存した画像を時系列順にリネームするスクリプト
import os
import os.path
import sys
import glob
def map(char):
a = ord(char)
if 48 <= a <= 57:
return "~" + char
elif char == "-":
@curegit
curegit / math.html
Last active March 11, 2021 07:06
MathML によるマークアップの例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Repetition-Increasing Sequence</title>
</head>
<body>
<h1>Repetition-Increasing Sequence</h1>
<math style="font-size: xxx-large">
<msub>
@curegit
curegit / image-classification-helper.py
Last active February 25, 2021 03:08
画像ファイルをいるものといらないものに仕分ける Tkinter 製 GUI ツール
#!/usr/bin/env python3
import os
import sys
import glob
import shutil
import tkinter as tk
from tkinter import messagebox
from tkinter import filedialog
from PIL import Image, ImageTk, ImageDraw
@curegit
curegit / self-attention.py
Last active February 9, 2021 05:39
Chainer で二次元マップ Self-Attention 層の実装 (Self-Attention GAN)
from chainer import Parameter, Chain
from chainer.links import Convolution2D
from chainer.functions import einsum, softmax
from chainer.initializers import Zero
def dot(a, b):
return einsum("...ji,...ik->...jk", a, b)
class SelfAttention(Chain):
@curegit
curegit / chainer-lanczos0.5x.py
Last active December 6, 2022 06:09
Chainer で Lanczos 補間による画像二倍縮小層の実装
import numpy as np
from chainer import Link
from chainer.functions import pad, convolution_2d
def lanczos(x, n):
return 0.0 if abs(x) > n else np.sinc(x) * np.sinc(x / n)
class Lanczos2xDownsampler(Link):
def __init__(self, n=3):
@curegit
curegit / chainer-bicubic2x.py
Last active January 13, 2021 02:16
Chainer で Bicubic 補間による画像二倍拡大層の実装
import numpy as np
from chainer import Link
from chainer.functions import pad, convolution_2d, depth2space
def cubic(b, c):
def k(x):
if abs(x) < 1:
return 1 / 6 * ((12 - 9 * b - 6 * c) * abs(x) ** 3 + (-18 + 12 * b + 6 * c) * abs(x) ** 2 + (6 - 2 * b))
elif 1 <= abs(x) < 2:
return 1 / 6 * ((-b - 6 * c) * abs(x) ** 3 + (6 * b + 30 * c) * abs(x) ** 2 + (-12 * b - 48 * c) * abs(x) + (8 * b + 24 * c))