Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
ongaeshi / console.txt
Last active October 4, 2023 17:39
「ruby について本を書こうと思う」という質問をGPTに投げた結果
PS C:\Users\ongaeshi\Code\runa_app\ruby_openai> runa run .\question.rb
---
Title: Mastering Ruby: Unlocking the Power of a Dynamic Programming Language
Table of Contents:
1. Introduction to Ruby
- Overview of Ruby's history and philosophy
- Setting up a Ruby development environment
- Basic syntax and data types in Ruby
scala> def largerThan(n: Int)(i: Int): Boolean = i > n
def largerThan(n: Int)(i: Int): Boolean
scala> largerThan(4)
val res1: Int => Boolean = Lambda$6155/0x000001919e039400@372eb77
scala> largerThan(4)(5)
val res2: Boolean = true
scala> List(5,1,2,4,0).filter(largerThan(4))
# 一度 uninstall してから install するとうまくいった。
C:/Ruby32-x64/lib/ruby/3.2.0/rubygems.rb:263:in `find_spec_for_exe': can't find gem runa (>= 0.a) with executable runa (Gem::GemNotFoundException)
from C:/Ruby32-x64/lib/ruby/3.2.0/rubygems.rb:282:in `activate_bin_path'
from C:/Ruby32-x64/bin/runa:32:in `<main>'
PS C:\Users\ongaeshi\Code\tmp\ruby2d_test> gem uninstall runa
Successfully uninstalled runa-0.1.0
PS C:\Users\ongaeshi\Code\tmp\ruby2d_test> gem install runa
Fetching runa-0.1.0.gem
Successfully installed runa-0.1.0
```
irb(main):002:0> $LOAD_PATH
=>
["C:/Users/ongaeshi/Code/rurema/vendor/bundle/ruby/3.2.0/gems/thor-1.2.2/lib",
"C:/Users/ongaeshi/Code/rurema/vendor/bundle/ruby/3.2.0/bundler/gems/ruremai-a7c249c92623/lib",
"C:/Users/ongaeshi/Code/rurema/vendor/bundle/ruby/3.2.0/gems/launchy-2.5.2/lib",
"C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/lib",
"C:/Users/ongaeshi/Code/rurema/vendor/bundle/ruby/3.2.0/gems/addressable-2.8.4/lib",
"C:/Users/ongaeshi/Code/rurema/vendor/bundle/ruby/3.2.0/gems/public_suffix-5.0.1/lib",
"C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0",
@ongaeshi
ongaeshi / errorlog.txt
Last active March 21, 2023 15:39
ruby.wasm build Error log: rake build:head-wasm32-unknown-wasi-full-js
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-pc-linux-gnu
checking host system type... wasm32-unknown-wasi
checking target system type... wasm32-unknown-wasi
checking for wasm32-wasi-wasm-opt... /home/ongaeshi/WslCode/ruby.wasm/build/toolchain/binaryen/bin/wasm-opt
checking wheather $WASI_SDK_PATH is set... no
configure: error: WASI_SDK_PATH environment variable is required
make: *** No rule to make target 'rbconfig.rb'. Stop.
creating Makefile
@ongaeshi
ongaeshi / errorlog.txt
Created March 1, 2023 17:45
ruby.wasm error "Uncaught RuntimeError: unreachable executed"
Uncaught RuntimeError: unreachable executed
rbFuncallvProtect https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:3540
callRbMethod https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:4378
wrapRbOperation https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:4356
callRbMethod https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:4377
call https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:4234
procToJsFunction https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@next/dist/browser.script.iife.js:4008
redraw https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js:68314
_draw https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js:60836
_draw https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js:60854
# https://twitter.com/lisasekaida/status/1629291753261117441
$s=600
def setup
createCanvas($s,$s,WEBGL)
noStroke
end
$a=0
graph

1 --> 2 --> 3 --> 4

1(1. u32のソート)
2(2. ジェネリクス対応)
3(3. クロージャによるソート順のカスタマイズ)
4(4. 並列ソートの実現)
# https://ongaeshi.github.io/rubyonbrowser/ でPC実行すると1ループ約1秒位だった
(1..10).map do
(1..10000000).each {}
Time.now
end.join("\n")
DATA = <<EOS
<html>
<head>
<meta charset="utf-8"/>
</head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/browser.umd.js"></script>
<script>
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
const main = async () => {
// Fetch and instntiate WebAssembly binary