Skip to content

Instantly share code, notes, and snippets.

View holysugar's full-sized avatar

HORII Keima holysugar

  • Aiming, Inc
  • Tokyo
View GitHub Profile
@holysugar
holysugar / itemchanger.rb
Created November 14, 2012 10:06
AR proxy sample
require 'active_support/all'
require 'active_attr'
class Itemchanger
include ActiveAttr::Model
extend ActiveModel::Callbacks
define_model_callbacks :save
@holysugar
holysugar / to_chitanda.rb
Created November 1, 2012 09:13
Integer#to_chitanda (first version)
#coding: utf-8
module Kansuuji
NUMBERS = %w(〇 一 二 三 四 五 六 七 八 九)
RANKS = [''] + %w(十 百 千)
def self.kansuuji(int)
raise RuntimeError, "can calc between 1 and 9999" if int < 1 || int > 9999 # FIXME
return NUMBERS[1] if int == 1
@holysugar
holysugar / padrino_fluent_logger.rb
Created October 30, 2012 06:26
PadrinoFluentLogger
class PadrinoFluentLogger
extend Forwardable
attr_accessor :level
# options takes below:
# :logger => custom Fluent::Logger::FluentLogger object
# :tag_prefix => set your tag_prefix to FluentLogger
def initialize(options = {})
env = (PADRINO_LOG_LEVEL || Padrino.env || :test).to_sym
config = Padrino::Logger::Config[env]
@holysugar
holysugar / gist:3817860
Created October 2, 2012 09:38
google-drive-ruby with oauth sample
require 'google_drive'
require 'oauth2'
require 'json'
require 'pry'
# create in https://code.google.com/apis/console/
@client_id = ""
@client_secret = ""
@redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
@holysugar
holysugar / gist:3775235
Created September 24, 2012 09:58
GoogleDrive::Spreadsheet sample
#!/usr/bin/env ruby
# coding: utf-8
require 'google_drive'
require 'highline/import'
require 'active_support/core_ext'
require 'pry'
def ask_authentication
@holysugar
holysugar / gist:3747580
Created September 19, 2012 03:50
give method in rspec
# test target sample class...
class D
def foo(num)
%w[one two three][num - 1]
end
end
def given(*args)
subject.call(*args)
end
@holysugar
holysugar / gist:3747432
Created September 19, 2012 03:09
if i use each...
describe B do
describe "#foo" do
[
#[ argument, expect]
[ 1, 'one'],
[ 2, 'two'],
[ 3, 'three'],
].each do |arg, expect|
@holysugar
holysugar / pushover.rb
Created August 29, 2012 10:01
Pushover class sample
require "net/https"
class Pushover
def initialize(api_token, user_key)
@api_token = api_token
@user_key = user_key
end
def message(_message)
@holysugar
holysugar / gist:3187323
Created July 27, 2012 10:27
current_user methods
# NOTE: memoized in @current_user
# (1)
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
# (6)
def current_user
@current_user ||= User.find_by_id(session[:user_id])
@holysugar
holysugar / gist:3140101
Created July 19, 2012 01:14
API Interface Generation Idea
# 生成コードイメージ
# 仮想コード。
# プロトコル(てきとう)
RPC.remote :userinfo do
method :get
route: "/userinfo"