Skip to content

Instantly share code, notes, and snippets.

View freedive-cebu30's full-sized avatar

Joji freedive-cebu30

View GitHub Profile
@freedive-cebu30
freedive-cebu30 / swap.sh
Created April 16, 2019 10:22
Linux_swap
grep VmSwap /proc/*/status | sort -n -k 2 -r | head
ps axfu | grep 対象プロセス
cat /proc/meminfo | grep Mem
# 配列の宣言
arr_1 = [1, 2, 3, 4, 5]
# 繰り返しの処理
arr_1.each do |arr|
puts 'hi'
puts arr
end
# 実行結果
# hi
# 1
# 空のhashを定義
h1 = Hash.new
h2 = {}
# keyとvalueをセットして定義
# シンボルでも文字列でも定義できる
h3 = {a: 1, b: 2, c: 3}
h4 = {"a" => 1, "b" => 2, "c" => 3}
h1[:a] = 1
h1[:b] = 2
h1[:c] = 3
puts h1[:b]
# 実行結果
# 2
h2["a"] = 4
h2["b"] = 5
h = {a: 1, b: 2, c: 3}
puts h.length
# 実行結果
# 3
puts h.size
# 実行結果
# 3
puts h.count
h = {a: 1, b: 2, c: 3, d: "taro", e: "jiro"}
h.delete(:a)
puts h
# 実行結果
# {:b=>2, :c=>3, :d=>"taro", :e=>"jiro"}
h = {a: 1, b: 2, c: 3, d: "taro", e: "jiro"}
# valueが数字の値だけを削除します。
h.delete_if{|key, value| value.kind_of?(Integer)}
puts h
h1 = { a: 1, b: 2, c: 3 }
h2 = { d: "taro", e: "jiro" }
h3 = h1.merge(h2)
puts h3
# 実行結果
# {:a=>1, :b=>2, :c=>3, :d=>"taro", :e=>"jiro"}
h = {:a => 1, :b => 2, :c => 3, :d => "taro", :e = >"jiro"}
puts h.empty?
# 実行結果
# false
# hashを初期化
h.clear
puts h
# 実行結果
# {}
h = {:a => 1, :b => 2, :c => 3, :d => "taro", :e => "jiro"}
# keyの一覧を取得
puts h.keys
# 実行結果
# [:a, :b, :c, :d, :e]
# keyがあるかの確認
puts h.key?(:a)
# 実行結果
# true