1
0

wslでelixir その138

Last updated at Posted at 2024-02-17

概要

wsl(wsl2じゃない)で、elixirやってみた。
Livebookで、じゃんけんをDEPLOYしてみた。

写真

localhost:8080/apps/janken

deploy3.png

セットアップ

Mix.install([
	{:kino, "~> 0.10.0"}
])

サンプルコード

defmodule Janken do
	def hand(c) do
		cond do
		c == 0 ->
			"グー"
		c == 1 ->
			"チョキ"
		c == 2 ->
			"パー"
		:else ->
			"うそ"
		end
	end
	def judge(a, b) do
		cond do
		a == b ->
			"あいこ"
		a == 0 && b == 1 ->
			"あなたの勝ち"
		a == 1 && b == 2 ->
			"あなたの勝ち"
		a == 2 && b == 0 ->
			"あなたの勝ち"
		a == 0 && b == 2 ->
			"あなたの負け"
		a == 1 && b == 0 ->
			"あなたの負け"
		a == 2 && b == 1 ->
			"あなたの負け"
		end
	end
	def pon(a) do
		res = ""
		{a, _} = a
			|> Integer.parse()
		res = res <> hand(a) <> "と"
		b = 0..2 
			|> Enum.random
		res = res <> hand(b) <> "で、"
		res = res <> judge(a, b)
		res
	end
end

frame2 = Kino.Frame.new()

com = Kino.Markdown.new("0-gu 1-choki 2-pa")
Kino.Frame.append(frame2, com)    
inputs2 = [	te: Kino.Input.text("Anata")]
form2 = Kino.Control.form(inputs2, submit: "Send", reset_on_submit: [:te])

Kino.listen(form2, fn %{data: %{te: te}, origin: origin} ->
  res = Janken.pon(te)
	content = Kino.Markdown.new(res)
	Kino.Frame.append(frame2, content)    
end)

デプロイ

左のロケットマークをクリック、configreをクリック。

deploy.png

deploy2.png

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0