Skip to content

Instantly share code, notes, and snippets.

View kawasima's full-sized avatar

Yoshitaka Kawashima kawasima

View GitHub Profile
@kawasima
kawasima / sevens.ts
Created March 26, 2024 12:56
7並べのモデル Domain Modeling Made Functional風味
import z from "zod";
const Suit = z.enum(["Spade", "Heart", "Diamond", "Club"]);
const Rank = z.enum(["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]);
const Card = z.object({
suit: Suit,
rank: Rank,
});
type Card = z.infer<typeof Card>;
// 手札
import { match } from "ts-pattern";
import z from "zod";
const Station = z.object({
name: z.string()
})
const Time = z.object({
hour: z.number().int().min(0).max(12),
minute: z.number().int().min(0).max(59),
})
@kawasima
kawasima / MethodSecurityMinimal.java
Last active February 1, 2023 13:50
ミニマルなSpring SecurityのMethod Security
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.config.AopConfigUtils;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.authorization.AuthorizationManager;
import org.springframework.security.authorization.method.AuthorizationManagerBeforeMethodInterceptor;
import org.springframework.security.authorization.method.PreAuthorizeAuthorizationManager;
/*
* ------------------------------------------------------------
* "THE YAKINIKUWARE LICENSE" (Revision 42):
* <author> wrote this code. As long as you retain this
* notice, you can do whatever you want with this stuff. If we
* meet someday, and you think this stuff is worth it, you can
* treat me grilled meat in return.
* ------------------------------------------------------------
*/
@kawasima
kawasima / postmortem.md
Created November 14, 2022 04:33
The template of the postmortem

タイトル

(概要)

問題発生期間

(あればタイムラインを書く)

トリガー

import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import java.util.LinkedHashMap;
import java.util.Map;
@kawasima
kawasima / ShiftJISRegexGenerator.java
Created March 16, 2021 08:12
Shift_JISの全角文字のみにマッチする正規表現ジェネレータです。
import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class ShiftJISRegexGenerator {
public static void main(String[] args) {
/**
* ルールの時間範囲を表現するクラスです。
*/
public class RulePeriod {
private LocalTime startTime;
private LocalTime endTime;
public RulePeriod(int startHour, int endHour) {
startTime = LocalTime.of(startHour, 0);
endTime = LocalTime.of(endHour, 0);
@kawasima
kawasima / treeDiff.ts
Created December 16, 2019 09:00
How to get differences between two trees
type TreeNode = {
key: number;
children?: TreeNode[];
}
type Oyako = [ number, number ];
const tree1 : TreeNode = {
key: 1,
children: [
(ns bakusatsu
(:refer-clojure :exclude [+ -])
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as stest]
[clojure.core :as core]))
;; 金額に関する振る舞い(金額同士の加算と減算ができる)
(defprotocol IMoney
(+ [this money])
(- [this money]))