Skip to content

Instantly share code, notes, and snippets.

@shahoxo
shahoxo / xian.rb
Created April 30, 2014 08:16
しーあん
class Xian < BasicObject
def method_missing(*args, &block)
self.class.absolute
end
def self.method_missing(*args, &block)
self.absolute
end
def self.absolute
@shahoxo
shahoxo / filter_custom_date_range_inpute.rb
Created April 17, 2014 06:30
ActiveAdminで日付入力フォームを独自に定義する
#active_adminのlib/active_admin/inputs/filter_date_range_input.rb を参照
module ActiveAdmin
module Inputs
class FilterCustomDateRangeInput < ::Formtastic::Inputs::StringInput
include FilterBase
def to_html
input_wrapping do
[ label_html,
builder.text_field(gt_input_name, input_html_options(gt_input_name)),
@shahoxo
shahoxo / hoge.rb
Created December 5, 2013 10:59
インスタンス変数と同じライフサイクルのクラスインスタンス変数をつくる
class Hoge
def initialize
@initialized_at = self.class.hoge
end
def self.hoge
@hoge = nil if ObjectSpace.each_object(Hoge).none?
@hoge ||= Time.now
end
end
require 'iconv'
require 'kconv'
require 'nkf'
puts "---[UTF-8]---"
p slash1 = ["2f".hex].pack('c*')
p slash2 = ["c0".hex, "af".hex].pack('c*')
p slash3 = ["e0".hex, "80".hex, "af".hex].pack('c*')
p slash4 = ["f0".hex, "80".hex, "80".hex, "af".hex].pack('c*')
puts "\n---[Shift-JIS]@kconv---"
p slash1.tosjis
delimiter //
CREATE PROCEDURE Bonanza()
BEGIN
SELECT name FROM user WHERE id = TRUNCATE(RAND() * (
SELECT MAX(id) FROM user
)+ .9, 0);
END
//
delimiter ;