Skip to content

Instantly share code, notes, and snippets.

View aileron's full-sized avatar

AILERON aileron

View GitHub Profile
@aileron
aileron / gist:2894649
Created June 8, 2012 09:14
backgroun-image にグラデを付ける方法
background-color: white;
background-image: url(bg.png);
background-image: url(bg.png), -webkit-gradient(linear, left top, right bottom, from(#000000), to(#ffffff));
background-image: url(bg.png), -moz-linear-gradient(-45deg, #000000, #ffffff);
background-attachment: fixed;
@aileron
aileron / gist:2946977
Created June 18, 2012 05:24
Gem (active_paypal_adaptive_payment) 初期化コード config/initializers/paypal.rb
unless Rails.env.production?
ActiveMerchant::Billing::Base.mode = :test
end
config = YAML.load(ERB.new(File.read("#{Rails.root}/config/paypal.yml")).result)[Rails.env]
PaypalGateway = ActiveMerchant::Billing::PaypalAdaptivePayment.new(
:login => config["username"],
:password => config["password"],
:signature => config["signature"],
:appid => config["application_id"]
)
@aileron
aileron / gist:2946980
Created June 18, 2012 05:25
Gem (active_paypal_adaptive_payment) を使用した事前承認支払いのコントローラ サンプル
class PaypalController < ApplicationController
def approval
raise "not loggined" unless login_user
@approval = Approval.find_or_create_by :user_id => login_user.id, :item_id => params[:item_id]
raise "subscribed!" if @approval.key
start_date = Time.now.gmtime
end_date = 3.months.from_now.gmttime
@aileron
aileron / gist:2946985
Created June 18, 2012 05:27
Gem (active_paypal_adaptive_payment) を使用した事前承認支払いのサンプルモデル
class Approval
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :user
field :item_id
field :key
field :approved, :type=> Boolean, :default => false
def pay
@aileron
aileron / gist:2987427
Created June 25, 2012 08:45
RailsでURLヘルパーを、直接取得するには
Rails.application.routes.url_helpers
@aileron
aileron / gist:3177543
Created July 25, 2012 17:58
ステートマシーンのRuby実装 ほぼ AASMと同じ使い方。
module StateMachine
class Event
def transition opt={from:nil,to:nil,guard:nil}
self.ts ||= {}
self.ts[ opt[:from] ] = opt if (opt[:from].is_a? String) || (opt[:from].is_a? Symbol)
opt[:from].each do |name|
ts[name] = opt
end if opt[:from].is_a? Array
end
attr_accessor :ts
@aileron
aileron / gist:3367643
Created August 16, 2012 07:17
キターぐるぐる。
/**
jquery.glance.js ver1.0
The MIT License
Copyright (c) since 2012 Grow! inc. jun takeno
http://about.me/yamitake
http://twitter.com/yamitake
Permission is hereby granted, free of charge, to any person obtaining a copy
@aileron
aileron / gist:3402037
Created August 20, 2012 07:59
Ruby1.9 で Shift_JIS 風 UTF-8 と CP932 風 UTF-8 の正規化
# ruby1.9 で正規化して、エンコードするまで
"なんかきもいやつら".
tr("\u{301C 2016 2212 00A2 00A3 00AC 2014 00A6}","\u{FF5E 2225 FF0D FFE0 FFE1 FFE2 2015 FFE4}").encode("sjis")
.entypo-phone:before { content: "\1F4DE"; }
.entypo-mobile:before { content: "\1F4F1"; }
.entypo-mouse:before { content: "\E789"; }
.entypo-address:before { content: "\E723"; }
.entypo-mail:before { content: "\2709"; }
.entypo-paper-plane:before { content: "\1F53F"; }
.entypo-pencil:before { content: "\270E"; }
.entypo-feather:before { content: "\2712"; }
.entypo-attach:before { content: "\1F4CE"; }
.entypo-inbox:before { content: "\E777"; }
@aileron
aileron / gist:4733884
Created February 7, 2013 20:26
Ruby on rails markdown( Redcarpet ) used view helper
module MarkdownHelper
_markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:autolink => true, :space_after_headers => true)
define_method :markdown do |text|
raw _markdown.render(text)
end
end