Skip to content

Instantly share code, notes, and snippets.

View kkabetani's full-sized avatar

Kazuhiro Kabetani kkabetani

View GitHub Profile
@kkabetani
kkabetani / kzrb_shuffle
Created February 16, 2014 06:29
しゃっふる
<<DATA.split.shuffle.each do |i| p i end
1
2
3
DATA
@kkabetani
kkabetani / kzrb_shuffle
Created February 16, 2014 07:34
meetup#18 の出席メンバーしゃっふるー
require 'open-uri'
require 'nokogiri'
page = Nokogiri::HTML(open('http://kzrb.doorkeeper.jp/events/8563'))
page.css('.user-name').children.to_a.shuffle.each do |name|
puts name.content
end
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
@kkabetani
kkabetani / convert_to_original_url
Created February 22, 2014 12:42
t.co の省略された URL から元の URL を取得する
require 'uri'
require 'net/http'
tco = "https://t.co/DyfjrVazCG"
res = Net::HTTP.get_response(URI.parse(tco))
p res["location"]
@kkabetani
kkabetani / wday_cwday_cweek.rb
Created April 12, 2014 05:51
wday と cwday と cweek
require 'active_support/all'
target_day = Date.new(2014, 4)
month = target_day.beginning_of_month.upto(target_day.end_of_month)
month.each do |d|
puts "#{d} cwday: #{d.wday} wday: #{d.cwday} cweek: #{d.cweek}"
end
=begin
2014-04-01 cwday: 2 wday: 2 cweek: 14
@kkabetani
kkabetani / dsl.rb
Created December 29, 2014 14:32
DSL sample
# module DSL
module DSL
def my_attr_accessor(name)
define_method name do
instance_variable_get("@#{name}")
end
define_method "#{name}=" do |value|
instance_variable_set("@#{name}", value)
end
@kkabetani
kkabetani / kzrb_dates.rb
Created December 29, 2014 15:07
kanazawa.rb 開催日
require 'open-uri'
require 'nokogiri'
page = Nokogiri::HTML(open('http://kzrb.org/meetup/'))
dates = page.css('header ul li').map(&:text).reverse
YEAR = 2014
dates = dates.map do |date|
date =~ /(#{YEAR}-\d\d-\d\d)/
@kkabetani
kkabetani / uniq.rb
Created December 29, 2014 15:09
uniq と uniq! の戻り値
ary1 = [1, 2, 3]
ary2 = [1, 1, 3]
p 'uniq'
p ary1.uniq
p ary2.uniq
p 'uniq!'
p ary1.uniq!
@kkabetani
kkabetani / hanbey.rb
Last active August 29, 2015 14:16
scraping hanbey shop name
require 'nokogiri'
require 'open-uri'
connected_shop_name = ''
hanbey = Nokogiri::HTML(open('http://www.hanbey.com/info/'))
hanbey.css('.table_shopname strong').each do |all_shop_name|
all_shop_name.children.each do |divided_shop_name|
connected_shop_name += divided_shop_name.content.strip
end
puts connected_shop_name unless connected_shop_name.empty?
@kkabetani
kkabetani / index.html
Created March 13, 2015 15:39
d3.js training(update、enter、exit) By using dotinstall
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3.js の練習</title>
</head>
<body>
<p>Hello 1</p>
<p>Hello 2</p>
<p>Hello 3</p>