This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'rugged', '0.17.0.b6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
response = Net::HTTP.get_response("codejp2012quiz.cloudapp.net","/Quiz/GetList") | |
quiz = JSON::parse response.body | |
p quiz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mathn' | |
MAX = 30 | |
AMAX = 10 | |
BMAX = 20 | |
class Pages | |
attr_accessor :name, :line, :line_of_page | |
def initialize; yield self; end | |
def last; (@line / @line_of_page).ceil; end | |
def line_at_last; (mod_line == 0) ? @line_of_page : mod_line ; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mathn' | |
MAX = 30 | |
AMAX = 10 | |
BMAX = 20 | |
def conditions(page, count_a, count_b) | |
max_page_a = (count_a / AMAX).ceil | |
max_page_b = (count_b / BMAX).ceil | |
return nil if page > max_page_a && page > max_page_b | |
return {offset_a: (page - 1) * AMAX, limit_a: AMAX, offset_b: (page - 1) * BMAX, limit_b: BMAX} if page < max_page_a && page < max_page_b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX = 30 | |
AMAX = 10.0 | |
BMAX = 20.0 | |
def limit_page(count_a, count_b) | |
ap = (count_a / AMAX).ceil | |
bp = (count_b / BMAX).ceil | |
return ap, bp if ap == bp | |
if ap < bp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Time.now.instance_eval {'%s.%03d' % [strftime('%Y/%m/%d %H:%M:%S'), (usec / 1000)]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tig "bind"] | |
generic = g move-first-line | |
generic = G move-last-line | |
generic = f move-page-down | |
generic = b move-page-up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tables = (ActiveRecord::Base.connection.tables - %w{schema_migrations}) | |
tables.each {|table| | |
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table};") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :info do | |
desc "Count record each tables" | |
task(count: :environment) { | |
tables = ActiveRecord::Base.connection.tables | |
tables.reject!(&"schema_migrations".method(:==)) | |
tables.map!(&:classify) | |
len = tables.map(&:length).max | |
tables.each{|table| | |
puts "#{table.ljust(len)}: #{Object.const_get(table).count}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src = [{"a"=>"aaa", "b"=>"bbb"}, {"c"=>"ccc"}] | |
src.map{|x| x.each_with_object({}) {|(k, v), h| h[k.to_sym] = v}} | |
#=> [{:a=>"aaa", :b=>"bbb"}, {:c=>"ccc"}] |