Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Last active March 21, 2022 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ongaeshi/991b7149159746b48be966c5dedf1b15 to your computer and use it in GitHub Desktop.
Save ongaeshi/991b7149159746b48be966c5dedf1b15 to your computer and use it in GitHub Desktop.
DATA = <<EOS
<html>
<head>
<meta charset="utf-8"/>
</head>
<script src="https://cdn.jsdelivr.net/npm/ruby-head-wasm-wasi@0.2.0/dist/browser.umd.js"></script>
<script>
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
const main = async () => {
// Fetch and instntiate WebAssembly binary
const response = await fetch(
"https://cdn.jsdelivr.net/npm/ruby-head-wasm-wasi@0.2.0/dist/ruby.wasm"
);
const buffer = await response.arrayBuffer();
const module = await WebAssembly.compile(buffer);
const { vm } = await DefaultRubyVM(module);
vm.printVersion();
runRubyScriptsInHtml(vm);
};
const runRubyScriptsInHtml = (vm) => {
const input = document.getElementById("input");
const result = vm.eval(input.value);
document.getElementById("output").value = result;
};
main();
</script>
<style>
body {
font-size: 5rem;
text-align: center;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>
<body>
<div>
<textarea id="input" cols="80" rows="10">luckiness = ["Hello", "こんにちは", "😀"].sample</textarea>
<button id="run">Run</button>
</div>
<div>
<textarea id="output" cols="80" rows="10" readonly></textarea>
</div>
</body>
</html>
EOS
lineno = 1
DATA.split("\n").map do |line|
src = "#{lineno}: #{line}".gsub(" ", "\t")
lineno += 1
src
end.join("\n")
def sample
["👩", "🎃", "😀", '🤷‍♀️'].sample
end
100.times.map {|e| sample }.join("-")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment