Skip to content

Instantly share code, notes, and snippets.

View kmizu's full-sized avatar

Kota Mizushima kmizu

View GitHub Profile
@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 / 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 / クエリ1.txt
Created December 4, 2022 02:40
ChatGPTに日本語で階乗を計算する疑似コードを無理やり解釈させてみた
以下の日本語をプログラムとして解釈して実行してください。
ほげ数を計算(N)
・もし、N < 2 なら1を返す
・そうでなければ、「N * ほげ数を計算(N - 1)」を返す
ほげ数を計算(10)
@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 / 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 }
@kmizu
kmizu / NQueen.java
Created December 9, 2020 08:03
NQueen Problem Solver in Java
import java.util.*;
import java.awt.Point;
public class NQueen {
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_WHITE = "\u001B[37m";
private final int N;
private final Set<Point> queens;
public NQueen(int N) {
this.N = N;
@kmizu
kmizu / ExampleSpec.scala
Created June 24, 2020 06:30
NoSuchMethodError occurs in (Scala 2.12.x or 2.13.x) and ScalaTest 3.1.x with scalikejdbc
import org.scalatest.BeforeAndAfterAll
import org.scalatest.fixture.FunSpec
import scalikejdbc.{DB, _}
import scalikejdbc.config.DBs
import scalikejdbc.scalatest.AutoRollback
class ReservationRepositorySpec extends FunSpec with AutoRollback with BeforeAndAfterAll {
//テスト実行前にダミーデータを追加
override def beforeAll(): Unit = {
@kmizu
kmizu / description.md
Last active May 27, 2020 06:16
FizzBuzz class problem in Scala

整数mから整数n(n >= 1、m >= 1)までのFizzBuzzを計算せよ。ただし、FizzBuzzのクラス定義は次のようになっていなければいけないものとする。

なお、剰余は x % y、 数値の文字列化は num.toString で可能である。

case class FizzBuzz(val m: Int, val n: Int) {
  def call(): Unit = {
    ???
  }
}
@kmizu
kmizu / For.ij
Created April 19, 2020 10:29
Indent-based Java (Thought Experiment)
package for
public class For:
public static void main(String[] args):
for(int i = 0; i < 10; i++):
System.out.println(i)