Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
puts 'in original, not to be modified'
begin
require 'aws-sdk'
rescue LoadError
puts "aws-sdk gem not found"
throw :aws_sdk
end
puts ">>> to execute only if 'aws-sdk' is found"
@deepak
deepak / chef bin.sh
Last active December 11, 2015 18:09
rbenv cookbook for chef
#!/usr/bin/env bash
# needed for the chef ruby cookbook to run without errors the second time
if [ -s /etc/profile.d/rbenv.sh ]; then
source /etc/profile.d/rbenv.sh
fi
# can pass-in variables like
# CHEF_DEPLOY_USER=deployer
# and access it in ruby (role files etc)
@deepak
deepak / cannot find solo.rb.txt
Created January 24, 2013 11:34
two chef-solo run errors
** [out :: server1] [2013-01-24T11:33:05+00:00] INFO: ohai plugins will be at: /etc/chef/ohai_plugins
** [out :: server1] [2013-01-24T11:33:05+00:00] INFO: Processing remote_directory[/etc/chef/ohai_plugins] action create (ohai::default line 27)
** [out :: server1] [2013-01-24T11:33:05+00:00] INFO: Processing cookbook_file[/etc/chef/ohai_plugins/README] action create (dynamically defined)
** [out :: server1]
** [out :: server1] ================================================================================
** [out :: server1] Recipe Compile Error in /vagrant/cookbooks/ruby/recipes/default.rb
** [out :: server1] ================================================================================
** [out :: server1]
** [out :: server1] Errno::ENOENT
** [out :: server1] -------------
@deepak
deepak / chef_source_a_file_inside_an_execute_block.txt
Created January 22, 2013 12:54
cannot execute shell builtins in an execute block
% echo $FOO
% cat /tmp/foo.sh
FOO=12
% source /tmp/foo.sh
% echo $FOO
12
# TODO: extracted from uuidtools
UUID_REGEX = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$/
resources :checkout, :only => [:show, :create], :constraints => { :id => UUID_REGEX }
@deepak
deepak / .irbrc
Created January 10, 2013 14:18
irb configuration to log ActiveRecord queries in rails
require 'irb/completion'
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:USE_READLINE] = true
# Just for Rails...
if ENV['RAILS_ENV']
class BooleanValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless is_a_boolean? value
record.errors[attribute] << (options[:message] || "is not valid")
end
end
def is_a_boolean? value
!!value == value
end
@deepak
deepak / milaap-web-designer-jd
Created December 13, 2012 04:01
JD for a web-designer at milaap
We are looking for senior web designer. You should be creative and should love your work.
Should be proficient with:
Technical Skillset
* writing semantic HTML
* writing modular CSS
* HTML5
* AJAX, jQuery
* Building cross browser compatible websites
name "basebox"
description "A basic box with some packages, ruby and rbenv installed"
deploy_user = ENV['CHEF_DEPLOY_USER']
# puts "== deploy user is: #{deploy_user.inspect}"
# cannot access node attributes in roles. will have to use
# chef-server's search as in http://wiki.opscode.com/display/chef/Search#Search-FindNodeswithaRoleintheExpandedRunList
# but i want to use chef-solo not chef-server and cannot use search
# deployer_user = node['users']['names'].find {|k,v| v['role'] == "deploy" }
@deepak
deepak / get all constants in a rails project.rb
Created October 11, 2012 11:46
get all constants in a rails project
require 'pp'
Dir["#{RAILS_ROOT}/app/models/*.rb"].each { |model_path| require model_path }
models = Module.constants.select do |constant_name|
begin
constant = eval constant_name.to_s
next if constant.nil?
match = (constant < ActiveRecord::Base) rescue nil
if match