Skip to content

Instantly share code, notes, and snippets.

View kmizu's full-sized avatar

Kota Mizushima kmizu

View GitHub Profile
@kmizu
kmizu / ChatGPT.js
Created March 3, 2023 09:25
Google Apps Script to use ChatGPT API
function doPost(e) {
// slack appsのEvent Subscriptionsのchallenge。同期する時に利用。
var params = JSON.parse(e.postData.getDataAsString());
if('challenge' in params)
{
return ContentService.createTextOutput(params.challenge);
}
// ユーザ名とtextを取得
var userName = params.event.user;
@kmizu
kmizu / A1.txt
Last active May 4, 2023 12:18
「柔らかく言い換える」Chrome拡張を作ってくれるようにGPT-4にお願いしてみた
もちろんです!以下に、Chrome拡張機能を作成するためのコードの例を示します。これは、指定された仕様を満たすシンプルな拡張機能です。
まず、プロジェクトディレクトリに3つのファイルを作成してください。
manifest.json
background.js
content.js
manifest.json:
@kmizu
kmizu / README.md
Last active April 30, 2023 13:13
Blawnの文法について

ソースコード読んだり、実際に処理系を動かしてみたメモを残しておきます。内容は当然ながら無保証です。 基本的に難しいことはやっていないので、ソースを読めばだいたいわかります。

処理系

C++で書かれている。

字句解析(flex) → 構文解析(bison)→ コード生成(LLVM IRを生成)

って感じで特に変なことはしていない。LLVM IR使っているというのが今どきぽいけど。

@kmizu
kmizu / Cont.scala
Created September 25, 2011 14:34
A naive continuation monad implementation in Scala. It is useless. However, it maybe useful to understand continuation monad.
//This implementation is a porting of naive continuation monad in Haskell in "All About Monads" pages.
class Cont[R, +A](val runCont: (A => R) => R) {
def map[B](f: A => B): Cont[R, B] = {
new Cont[R, B](k => runCont(a => Cont.ret[R, B](f(a)).runCont(k)))
}
def flatMap[B](f: A => Cont[R, B]) :Cont[R, B] = {
new Cont[R, B](k => runCont(a => f(a).runCont(k)))
}
}
@kmizu
kmizu / クエリ1.txt
Created December 4, 2022 02:40
ChatGPTに日本語で階乗を計算する疑似コードを無理やり解釈させてみた
以下の日本語をプログラムとして解釈して実行してください。
ほげ数を計算(N)
・もし、N < 2 なら1を返す
・そうでなければ、「N * ほげ数を計算(N - 1)」を返す
ほげ数を計算(10)
@kmizu
kmizu / parsers.nim
Created July 1, 2016 00:51
parser combinator library in Nim
import strutils
import lists
import re
type
Parser[T] = proc(input: string): Maybe[(T, string)]
Maybe*[T] = object
value: T
hasValue: bool
@kmizu
kmizu / DifferentReturnTypes.j
Created April 1, 2022 15:58
戻り値型だけが違うメソッドをJVM上で呼び分ける
.class public DifferentReturnTypes
.super java/lang/Object
;
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
@kmizu
kmizu / From.scala
Last active October 1, 2021 08:44
Delayed list in various programming languages
scala> def from(n: Int): LazyList[Int] = LazyList.cons(n, from(n + 1))
def from(n: Int): LazyList[Int]
scala> from(0).take(10).toList
val res0: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
@kmizu
kmizu / Visitors.scala
Created January 12, 2012 14:22
A Visitor pattern example, which solved "Expression Problem".
trait Visitors {
type V <: Visitor
type E <: Expression
trait Visitor {
def visit(e: Addition): Int
def visit(e: Subtraction): Int
def visit(e: Multiplication): Int
def visit(e: Num): Int
}
@kmizu
kmizu / Calculator1.scala
Last active July 14, 2021 10:19
8÷2(3+1) に対する二通りのパーザ(あるいはインタプリタ)作ってみた
import com.github.kmizu.scomb._
object Calculator1 extends SCombinator[Int] {
def root: Parser[Int] = expression
def expression: Parser[Int] = rule(A)
def A: Parser[Int] = rule(chainl(M) {
$("+").map { op => (lhs: Int, rhs: Int) => lhs + rhs } |
$("-").map { op => (lhs: Int, rhs: Int) => lhs - rhs }