Skip to content

Instantly share code, notes, and snippets.

class Array
# 配列の内容が "ズンドコ" か
def zundoko?
self == %w(ズン ズン ズン ズン ドコ)
end
end
ZUN_DOKO = %w(ズン ドコ)
results = []
@mmts1007
mmts1007 / kiyoshi_v3.rb
Created April 9, 2017 06:12
パフォーマンスを考慮してみた。シンボル(ex. :zun, :doko) は常に同じオブジェクトになるため、比較演算のスピードが少し速くなる(はず)
ZUN_DOKO = { zun: 'ズン', doko: 'ドコ' }
results = []
while results != [:zun, :zun, :zun, :zun, :doko]
results << ZUN_DOKO.keys.sample.tap { |key| print ZUN_DOKO[key] }
results.shift if results.length > 5
end
puts 'キ・ヨ・シ!'
ZUN_DOKO = %w(ズン ドコ)
results = []
while results != %w(ズン ズン ズン ズン ドコ)
results << ZUN_DOKO.sample.tap { |z| print z }
results.shift if results.length > 5
end
puts 'キ・ヨ・シ!'
ZUN_DOKO = ['ズン', 'ドコ']
results = []
while true
result = ZUN_DOKO.sample
print result
results << result
results.shift if results.length > 5
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
import static spark.Spark.after;
import static spark.Spark.delete;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.Spark.put;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static spark.Spark.get;
public class HelloSpark {
public static void main(String[] args) {
get("/", (req, res) -> {
return "Hello Spark";
});
}
}
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class HelloStreaming {
public static void main(String... args) {
List<String> numbers = Arrays.asList("4", "5", "1", "2", "3", "4", "5");
// map
numbers.stream().map(num -> Integer.parseInt(num)) // String型をInteger型に変換(マッピング)する
import java.util.ArrayList;
import java.util.List;
public class HelloLambda {
public static void main(String... args) {
List<String> names = new ArrayList<>();
names.add("sample 1");
names.add("sample 2");
names.add("sample 3");