Skip to content

Instantly share code, notes, and snippets.

@fukajun
fukajun / gist:2652860
Created May 10, 2012 12:57
2つのコントローラーで共通するアクションのテスト
# ???controller_spec.rb
[AController, BController].each do |cotroller|
describe controller do
it do
#共通するテスト
end
end
end
# a_controller_spec.rb
describe AController do
@fukajun
fukajun / gist:2856697
Created June 2, 2012 05:12
amidakuji
class Kuji
attr_accessor :bars
def initialize(num, length = nil)
@num = num
length = 4 if length.nil?
@bars = Array.new(length) { |index| Array.new(num - 1, false) }
end
def generate
@bars.each do |bar|
@fukajun
fukajun / gist:2944120
Created June 17, 2012 10:15
omniauth
def authenticate
redirect_to root_url unless current_user
end
@fukajun
fukajun / gist:2987962
Created June 25, 2012 11:02
omniauthでのアクセス制限の設定
# application_controller.rbに定義
def authenticate
redirect_to :root unless current_user
end
# 認証の必要なコントローラーの最初の行にbefore_filterを定義
class HogeController
before_filter authenticate # ←コレ
@fukajun
fukajun / gist:3402480
Created August 20, 2012 08:59
REST勉強会メモ
  • 名前の登録 フォーム

get :name

  • 郵便番号の登録 フォーム

get :zip

  • 電話番号の登録 フォーム
@fukajun
fukajun / gist:3858147
Created October 9, 2012 11:35
capistrano known hosts task
task :hoge do
temp_file = "/tmp/config.txt"
ssh_conf = "/root/.ssh/config"
run "echo 'Host *' > #{temp_file}"
run "echo 'StrictHostKeyChecking no' >> #{temp_file}"
run "echo 'UserKnownHostsFile /dev/null' >> #{temp_file}"
run "sudo mv #{temp_file} #{ssh_conf}"
run "sudo chmod 600 #{ssh_conf}"
run "sudo chown root:root #{ssh_conf}"
end
@fukajun
fukajun / file0.rb
Created October 12, 2012 05:33
qiita gemを使ってみたメモ ref: http://qiita.com/items/d2893476d39b4d120c57
# coding: utf-8
require 'rubygems'
require 'qiita'
# use name and password
qiita = Qiita.new( url_name: 'username', password: 'password')
# Get token
p token = qiita.token
@fukajun
fukajun / example.rb
Created October 22, 2012 12:38
alxlsのサンプルを動くように修正した
#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
#```ruby
require 'axlsx'
examples = []
examples << :basic
examples << :custom_styles
examples << :cell_style_override
@fukajun
fukajun / gist:3973130
Created October 29, 2012 11:46
split number
# a >= b >= c
def split(no, min, bit)
if bit <= 3
no.times do |a|
b = no - a
if a >= b && b >= min
split1(a, b, bit + 1)
if bit == 2
puts "#{a}:#{b}"
elsif bit == 3
@fukajun
fukajun / bashrc
Created October 31, 2012 00:52
git to tig, tig to git, gti to git
g=`which git`
t=`which tig`
tig(){ $g $*; }
git(){ $t $*; }
alias gti=tig