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 / gist:2410834
Created April 18, 2012 03:10
delegated_validate
class ItemWrapper
include ActiveAttr::BasicModel
include ActiveAttr::Attributes
# ...
attribute :name
attribute :price
# ...
validate do
if (RSpec::Core::Version::STRING.split('.').map(&:to_i) <=> [2,8,0]) >= 0
# ...
end
@holysugar
holysugar / get_access_token.sh
Created May 22, 2012 10:33
Get github access token
#!/bin/sh
# Get github access_token in API v3
# see http://developer.github.com/v3/#authentication
#
# requirements:
# * curl
# * sed
read -p "User: " user
read -p "Password: " password
#!/usr/bin/env ruby
class Elat
attr :max, :primes
def initialize(max)
@max = max
@search = nil
@primes = []
end
@holysugar
holysugar / gist:3046982
Created July 4, 2012 12:02
padrino rake -T
$ padrino rake -T (padrinosample)-(master)-(.)
=> Executing Rake -T ...
rake ar:abort_if_pending_migrations # Raises an error if there are pending migrations
rake ar:charset # Retrieves the charset for the current environment's database
rake ar:collation # Retrieves the collation for the current environment's database
rake ar:create # Create the database defined in config/database.yml for the current Padrino.env
rake ar:create:all # Create all the local databases defined in config/database.yml
rake ar:drop # Drops the database for the current Padrino.env
rake ar:drop:all # Drops all the local databases defined in config/database.yml
rake ar:forward # Pushes the schema to the next version.
@holysugar
holysugar / crontab.rb
Created July 9, 2012 02:52
recipes/crontab.rb
namespace :crontab do
desc 'display with crontab -l'
task :show, :roles => :app do
hosts = exists?(:cron_server) ? cron_server : roles[:app].servers.first
run "crontab -l", :hosts => hosts
end
desc 'read crontab from remote config/crontab/crontab.#{Rails.env}'
task :read do
@holysugar
holysugar / gist:3140101
Created July 19, 2012 01:14
API Interface Generation Idea
# 生成コードイメージ
# 仮想コード。
# プロトコル(てきとう)
RPC.remote :userinfo do
method :get
route: "/userinfo"
@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 / 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: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|