Skip to content

Instantly share code, notes, and snippets.

View thash's full-sized avatar
🌵
⭐️ ⭐️ ⭐️ ⭐️ ⭐️

Takuya Hashimoto thash

🌵
⭐️ ⭐️ ⭐️ ⭐️ ⭐️
View GitHub Profile
@thash
thash / Gemfile
Last active August 29, 2015 14:11
source 'https://rubygems.org'
gem 'capybara-webkit'
(function ($hx_exports) { "use strict";
var console = (1,eval)('this').console || {log:function(){}};
var Hoge = $hx_exports.Hoge = function() { };
Hoge.main = function() {
};
Hoge.init = function() {
new js.JQuery("button.toggle").click(function() {
new js.JQuery("button.toggle").toggle();
});
};
(function ($hx_exports) { "use strict";
var console = (1,eval)('this').console || {log:function(){}};
var Hoge = $hx_exports.Hoge = function() { };
Hoge.main = function() {
};
Hoge.init = function() {
new js.JQuery("button.toggle").click(function() {
new js.JQuery("button.toggle").toggle();
});
};
@thash
thash / venn.md
Last active August 29, 2015 14:10

Rubyで適当な値のデータを作り, RのVennDiagramライブラリで描画

ame = (Date.today.beginning_of_year..Date.today.end_of_year).to_a.sample(100).map(&:to_s)
jiko = (ame.sample(20) + (Date.today.beginning_of_year..Date.today.end_of_year).to_a.sample(50)).uniq.map(&:to_s)
uni = (Date.today.beginning_of_year..Date.today.end_of_year).to_a.map(&:to_s)

なんとなく雨の日が事故率高いように狙って作成してる. それぞれprintしてRコンソールにコピペ(原始的)

@thash
thash / at.rb
Last active August 29, 2015 14:10
AllAbout 024 HTML(1)
# Nokogiri::XML::Node#at メソッドは検索結果の最初のヒットを返す
doc.at('title')
# => #(Element:0x3feb0890f99c { name = "title", children = [ #(Text "All About(オールアバウト)")] })
doc.at('title').class # => Nokogiri::XML::Element
@thash
thash / bool.rb
Last active August 29, 2015 14:09
AllAbout 023 Conditions
def judge(cond)
if cond
puts 'TRUE!!'
else
puts 'FALSE!!'
end
end
judge(0) #=> TRUE!!
judge(999) #=> TRUE!!
@thash
thash / Gemfile
Last active August 29, 2015 14:08
AllAbout 022 EventMachine
source 'https://rubygems.org'
gem 'eventmachine'
@thash
thash / ampersand.rb
Last active August 29, 2015 14:07
AllAbout 021 Block
def iter(&b)
p b # => #<Proc:0x007fb92a934c30@ampersand.rb:6>
p b.class # => Proc
p b.class.ancestors # => [Proc, Object, Kernel, BasicObject]
# yieldの代わりにProc#callを使う
b.call # => hey
end
iter do
@thash
thash / fib.rb
Last active August 29, 2015 14:06
AllAbout 019 Fiber
fibonacci = Fiber.new do
x, y = 0, 1
loop do
Fiber.yield y # yieldに渡した値がresumeの返り値となる
x, y = y, x + y
end
end
puts fibonacci.resume #=> 1
puts fibonacci.resume #=> 1
@thash
thash / ancestors.rb
Last active August 29, 2015 14:06
AllAbout 020 Network
File.ancestors
=> [File, IO, File::Constants, Enumerable, Object, Kernel, BasicObject]
TCPSocket.ancestors
=> [TCPSocket, IPSocket, BasicSocket, IO, File::Constants, Enumerable, Object, Kernel, BasicObject]
TCPServer.ancestors
=> [TCPServer, TCPSocket, IPSocket, BasicSocket, IO, File::Constants, Enumerable, Object, Kernel, BasicObject]