Skip to content

Instantly share code, notes, and snippets.

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

Junichiro Doi jdoiwork

🏠
Working from home
View GitHub Profile
@jdoiwork
jdoiwork / deco_typing.py
Created April 17, 2021 18:50
python decorator typing hint
from typing import Any, Callable, TypeVar, Tuple, cast
F = TypeVar('F', bound=Callable[..., Any])
# A decorator that preserves the signature.
def my_decorator(func: F) -> F:
def wrapper(*args, **kwds):
print("Calling", func)
return func(*args, **kwds)
return cast(F, wrapper)
@jdoiwork
jdoiwork / .gitlab-ci.yml
Last active September 14, 2023 13:30
gitlab ci/cd flake8
default:
image: python:3.9
stages:
- lint
- test
- deploy
# before_script:
# - pip install flake8
@jdoiwork
jdoiwork / deep.plantuml
Created August 2, 2020 18:26
Qiita Autofac用plantuml
@startuml
interface Iすごいサービス {
Execute : () → string
}
class Myとてもすごいサービス {
Execute : () → string
さいこーサービス : Iさいこーサービス
感情サービス : I感情サービス
#nullable enable
using System;
using System.Linq;
using Autofac;
using Autofac.Extras.DynamicProxy;
using Castle.DynamicProxy;
using static System.Console;
@jdoiwork
jdoiwork / MaybeLinq.cs
Last active June 5, 2020 09:55
C# Maybe Monad as Linq
using System;
using System.Collections.Generic;
using System.Linq;
public abstract class Maybe<T> {
public Maybe<TResult> Map<TResult>(Func<T, TResult> selector)
{
return this.Bind(a => new Just<TResult>(selector(a)));
@jdoiwork
jdoiwork / Det.hs
Last active August 28, 2019 17:15
import Data.Array
import System.Random
import Data.Ratio ((%), Ratio)
type MatrixIndex = (Int, Int)
type MatrixElement = Rational
type MatrixValue = Array MatrixIndex MatrixElement
newtype MatrixDimension = MatrixDimension Int deriving (Show)
data Matrix = Matrix
# Eventクラスの作成
# Immutable.jsが必要
class Event
constructor: ->
@funcs = new Immutable.Set()
register: (func) ->
@funcs = @funcs.add(func)
unregister: (func) ->
-- https://en.wikipedia.org/wiki/Levenshtein_distance
type Length = Int
type Distance = Int
levenshteinDistance :: String -> String -> Distance
levenshteinDistance a b = lev a b i j
where i = length a
j = length b
@jdoiwork
jdoiwork / parseISO8601.hs
Last active May 1, 2017 08:23
Haskell parse ISO8601 DateTime
import Data.Time.LocalTime (LocalTime, ZonedTime)
import Data.Time.Clock (UTCTime)
import Data.Time.Format ( parseTimeM
, defaultTimeLocale
, TimeLocale(..)
, ParseTime
)
testTime :: [UTCTime]
testTime = parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%z"
@jdoiwork
jdoiwork / Example-ExceptT.hs
Last active July 23, 2016 19:16
IO (Either e a) を ExceptT を使ってうまいことする
module Main where
import Control.Monad.Except
type IOE a = IO (Either String a)
req1 :: IOE Int
req1 = return . Right $ 1
req2 :: Int -> IOE Int