- 並行と並列
- 並行すると嬉しいとき
- 並列すると嬉しいとき
- 並列処理
- Kernel#fork API
- 課題:結果の同期
- ノンプリエンプティブな並行処理
- 継続
- Fiber
- 課題:制御の切り替え
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: new IntervalNotation('[−3,1]').test(1) => true | |
// What's interval notation? see: https://www.varsitytutors.com/hotmath/hotmath_help/topics/interval-notation | |
class IntervalNotation { | |
constructor(str) { | |
const [left, right] = str.split(',') | |
if (!right) { | |
if (left.startsWith('[') || left.startsWith('(')) { | |
// Upper limit is omitted | |
this._lowwerCond = getLowwerCond(left) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Thread.new { | |
p 'hi thread' | |
sleep 3 | |
p 'bye thread' | |
} | |
fork do | |
p 'hi process' | |
t.join | |
p 'bye process' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'drb' | |
uri = 'druby://localhost:54000' | |
kvs = Hash.new | |
fork do | |
sleep 0.1 | |
kvs = DRbObject.new_with_uri uri | |
kvs['greeting'] = 'hello, world' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'drb' | |
uri = 'druby://localhost:54000' | |
kvs = Hash.new | |
DRb.start_service uri, kvs | |
fork do | |
DRb.start_service # この行をコメントアウトすると出力が"hello, world"からnilになる | |
kvs = DRbObject.new_with_uri uri | |
kvs['greeting'] = 'hello, world' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse line | |
line.split(' ').last.split('#') | |
end | |
lines = readlines | |
controllers = lines.reject do |line| | |
line.include? 'Controller#Action' | |
end.reduce({}) do |hash, line| | |
name, method = parse line | |
hash[name] ||= {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
require "base64" | |
API = 'https://api.github.com' | |
uri = URI API | |
def request_with_token url | |
req = Net::HTTP::Get.new URI url | |
req['Authorization'] = "token #{ENV['token']}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
uri = URI 'http://13.231.133.131/ea67874a-4718-4190-945d-6cd76e4efeae' | |
http = Net::HTTP.new uri.hostname, uri.port | |
http.start | |
req = Net::HTTP::Get.new uri.path | |
responses = [] | |
thread_A = Thread.start { responses << http.request(req) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared_development: | |
<<: *default | |
database: second_db_development | |
username: postgres | |
password: password | |
host: db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ node --experimental-worker require-libxmljs-twice.js | |
events.js:167 | |
throw er; // Unhandled 'error' event | |
^ | |
Error: Module did not self-register. | |
at Object.Module._extensions..node (internal/modules/cjs/loader.js:731:18) | |
at Module.load (internal/modules/cjs/loader.js:612:32) | |
at tryModuleLoad (internal/modules/cjs/loader.js:551:12) | |
at Function.Module._load (internal/modules/cjs/loader.js:543:3) |