Skip to content

Instantly share code, notes, and snippets.

View todesking's full-sized avatar
💀

todesking todesking

💀
View GitHub Profile
# -*- coding: utf-8 -*-
# まだテーブル構造がちゃんと決まってないので、データをコード内にベタ書きしてある。
# 将来的にはActiveRecord化してDBに保存したい。
class NewModel
def self.find(id)
INSTANCES[id] || (raise "not found")
end
INSTANCES = {
Application.configure do
config.after_initialize do
# Partialの情報をHTMLに埋める
# For ActionPack 3.2.8
class ActionView::PartialRenderer
def render_with_partial_annotation(*args)
setup(*args)
path = @path
content = "".html_safe
# config/environments/development.rb
# ActiveRecord 3.2.8 / mysql2 0.3.11
Application.configure do
config.after_initialize do
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
def execute_with_warning_is_error(sql, *rest)
result = execute_without_warning_is_error(sql, *rest)
warnings = execute_without_warning_is_error('show warnings', :skip_logging).to_a
gem "fastimage", "~>1.2.13"
module ApplicationHelper
include ActionView::Helpers::AssetTagHelper
# 画像サイズ見て自動でwidth/height属性つけるimage_tag
def image_tag_with_auto_size(source, options)
if options[:size] || options[:width] || options[:height]
image_tag_without_auto_size(source, options)
else
@todesking
todesking / cap_task_server_list.rb
Created January 10, 2013 10:54
cap、定義されてるサーバ一覧表示するタスク
task :server_list do
roles.each do|name, role|
role.each do|server|
puts "%10s %13s %s" % [name, server, server.options.inspect]
end
end
end
@todesking
todesking / .bash_profile
Created January 25, 2013 13:45
my .bash_profile
[ -s ~/.rvm/scripts/rvm ] && source ~/.rvm/scripts/rvm
source ~/scripts/vendor/git-completion/git-completion.bash
source ~/scripts/vendor/git-completion/git-prompt.sh
if [ "Darwin" = "$(uname)" ]; then
alias sed=gsed
export EDITOR=vim
fi
@todesking
todesking / active_sti.rb
Created February 1, 2013 11:22
Customizable STI rule for ActiveRecord
# usage:
# class User < AR::Base
# extend ActiveSTI
# define_sti_rule do|record|
# if record['parent']
# ChildUser
# else
# RootUser
# end
# end

入門Puppet感想

2012-05-09 達人出版会版

具体例はあっても仕組みやそうする理由の説明に乏しく、わかりにくかった。

manifest

具体的に裏で何が起こっているかに対する説明がないため、システムにmanifestを適用したとき何が起こるのかわからなくてこわい。 manifestに定義されてるリソースを列挙→依存関係でソート→順番に適用、だと想像しているが。

@todesking
todesking / tss.rb
Created June 23, 2013 08:16
rspec itss
def itss(name, &block)
describe name do
it { subject.instance_eval(name).instance_eval(&block) }
end
end
describe A do
subject { A.new }
itss('name.length') { should == 4 }
end
@todesking
todesking / application_helper.rb
Created February 27, 2014 17:20
Write Rails helper method with any template engine
module ApplicationHelper
def self.define_with_template(helper_name, template_type, template, locals = [])
compiled = Tilt[template_type].new(nil) { template }
define_method(helper_name) do|*args, &block|
compiled.render(self, Hash[*locals.zip(args).flatten], &block).html_safe
end
end
define_with_template :render_user_name, :slim, <<-SLIM, [:user_name]
.user