Skip to content

Instantly share code, notes, and snippets.

@morikuni
morikuni / main.go
Created November 12, 2021 08:40
Jasper Alternative
package main
import (
"context"
"fmt"
"github.com/alexeyco/simpletable"
"github.com/google/go-github/v40/github"
"github.com/morikuni/failure"
"golang.org/x/oauth2"
@morikuni
morikuni / test.go
Last active December 11, 2018 06:39
func Field(target interface{}, field string, val interface{}) error {
targetVal := reflect.Indirect(reflect.ValueOf(target)) // セットするstructのreflect.Valueをとる
if targetVal.Kind() != reflect.Struct {
return ErrNotStruct
}
dstVal := targetVal.FieldByName(field) // セットするフィールドのreflect.Valueをとる
if !dstVal.IsValid() {
return ErrNoSuchField
}
srcVal := reflect.ValueOf(val) // セットする値のreflect.Valueをとる
@morikuni
morikuni / proposal.go
Last active December 20, 2018 20:24
Go 2 Error Handling - function and syntactic sugar
// ParseError wraps err with parse error message.
func ParseError(err error) error { return errors.Wrap(err, “parse error“) }
// WithMessagse wraps err with arbitrary message.
func WithMessage(message string) func(err error) error {
return func(err error) error { returns errors.Wrap(err, message) }
}
// Ignore ignores err.
func Ignore(_ error) error { return nil }
@morikuni
morikuni / main.rs
Last active December 21, 2015 14:35
RustでEitherモナド
use self::Either::{Left, Right};
enum Either<E, A> {
Left(E),
Right(A),
}
trait Show {
fn show(self) -> String;
}
@morikuni
morikuni / Functor.scala
Created July 28, 2015 15:19
Haskellみたいに関数を先に受け取るFunctor
import scala.language.higherKinds
trait Functor[F[_]]{
def fmap[A, B](f: A => B)(fa: F[A]): F[B]
}
case class FunctorMap[A, B](val f: A => B){
def apply[F[_]: Functor](fa: F[A]): F[B] = implicitly[Functor[F]].fmap(f)(fa)
}
@morikuni
morikuni / Extract.scala
Last active August 29, 2015 14:24
Scalaのクラスとパッケージを抽出する
import xml._
import java.io.File
object Extract{
def main(args: Array[String]): Unit = {
val scaladoc = new File(args(0))
if(scaladoc.exists){
val html = XML.loadFile(scaladoc)
val builder = Set.newBuilder[String]
@morikuni
morikuni / MonadicAndThen.scala
Last active August 29, 2015 14:23
モナドを返す関数でAndThen
import scala.language.implicitConversions
import scala.language.higherKinds
trait Functor[F[_]]{
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Monad[F[_]] extends Functor[F]{
def unit[A](a: A): F[A]
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
@morikuni
morikuni / Apply.scala
Last active August 29, 2015 14:23
Haskell風のApply
import scala.language.higherKinds
trait Functor[F[_]]{
def fmap[A, B](fa: F[A])(f: A => B): F[B]
}
trait Apply[F[_]] extends Functor[F]{
def apply1[A, B](fa: F[A])(f: A => B): F[B] = fmap(fa)(f)
def apply2[A, B, C](fa: F[A])(f: (A, B) => C): F[B => C] = apply1(fa)(a => (b => f(a, b)))
def apply3[A, B, C, D](fa: F[A])(f: (A, B, C) => D): F[B => C => D] = apply1(fa)(a => b => c => f(a, b, c))
@morikuni
morikuni / paper.tex
Created June 14, 2015 15:38
Texpadで日本語のtex及びbibtexをコンパイルするためのビルドファイル
#!/bin/bash
echo platex "$TEXPAD_ROOTFILE"
platex "$TEXPAD_ROOTFILE"
echo pbibtex "$TEXPAD_ROOTFILE_NO_EXT"
pbibtex "$TEXPAD_ROOTFILE_NO_EXT"
echo platex "$TEXPAD_ROOTFILE"
platex "$TEXPAD_ROOTFILE"
echo platex "$TEXPAD_ROOTFILE"
platex "$TEXPAD_ROOTFILE"