Skip to content

Instantly share code, notes, and snippets.

View etdev's full-sized avatar

Eric Turner etdev

View GitHub Profile
@halogenandtoast
halogenandtoast / paste_helper.rb
Created June 8, 2018 13:44
Paste helper for capybara and chromedriver (may work with other drivers)
def paste_in(field_label, with:)
field = find_field(field_label)
selector = "##{field["id"]}"
script = <<-JS
dt = new DataTransfer();
dt.setData("text/plain", '#{with}');
ev = new ClipboardEvent("paste", { clipboardData: dt });
$('#{selector}')[0].dispatchEvent(ev)
JS
page.execute_script(script)
@kachick
kachick / why_i_dont_like_each_with_object.md
Last active March 14, 2021 17:55
Enumerable#each_with_object が嫌いな理由

Enumerable#each_with_object が嫌いだ。

もちろん動作自体は非常に有益だと思っているので、名前が嫌いなんだなーという結論になってしまうんだけど。

名前が長いというのはまぁそうなんだけど、その事自体は大した問題じゃない。
動作と名前が一致しているなら、後から良い短い名前が見つかった時aliasつければ別に困らない。
このメソッドが嫌いなのは、eachから始まっているところだ。
他のeach[_foo]系はブロック付の時にself返すのに、これだけ引数を返す。
これは類推できない、なので嫌だ。 代案の一つとして、こういうのはどうか

@zumbojo
zumbojo / bijective.rb
Created July 9, 2011 22:09
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join