Skip to content

Instantly share code, notes, and snippets.

View kkabetani's full-sized avatar

Kazuhiro Kabetani kkabetani

View GitHub Profile
@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 / 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 / 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"]
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
@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
@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 / 1_spec.rb
Created October 13, 2013 06:17
RSpecやってみた
describe 'テスト対象' do
context '状態' do
it '期待する出力' do
end
end
end
@kkabetani
kkabetani / syukudai1.rb
Last active December 24, 2015 09:39
kanazawa.rb meetup #13 の宿題 例外一覧を表示する
Object.constants.sort.map { |e|
Object.const_get(e.to_s)
}.select { |e|
e.ancestors.include?(Exception) if e.class == Class
}
@kkabetani
kkabetani / describe01.rb
Last active December 21, 2015 21:09
rspec/core/example_group.rb#describeの調査01
def subscribe(*args, &block)
p args
p block
args << {} unless args.last.is_a?(Hash)
p args
args.last.update(:block => block)
p args
end
public class SampleFormatDate {
public static void main( String[] args ) {
formatDate();
}
public static void formatDate() {
Date d1 = Calendar.getInstance(Locale.JAPAN).getTime();
// yyyy2013年2月7日木曜日
SimpleDateFormat sdf = new SimpleDateFormat("'yyyy'yyyy年M月d日E曜日");
System.out.println(sdf.format(d1));