Skip to content

Instantly share code, notes, and snippets.

class MyformBuilder < ActionView::Helpers::FormBuilder
def self.create_tagged_field(method_name)
define_method(method_name) do |name, *args|
if object && object.errors.any?
errors = object.errors.on(name.to_sym)
errors = errors.join(', ') if errors.kind_of? Array
end
help = Help[object.class.to_s][name.to_s] if Help[object.class.to_s]
# initialize some local variables
---
:benchmark: false
:update_sources: true
:sources:
- http://gems.rubyforge.org
- http://gems.github.com
- http://gems.github.com
gem: --no-ri --no-rdoc
:bulk_threshold: 1000
:verbose: true
@sandipransing
sandipransing / nginx conf
Created October 6, 2010 13:35
Nginx Conf
worker_processes 2;
user root;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
<%o.fields_for :investments do |p|%>
<%= p.select :amount, %w(25 50 75 100 200 500).collect{|a| "$#{a}"}, {}, {:class => :droplist}%>
and here <%= amount%> display karayachi aahe
<%end%>
@sandipransing
sandipransing / gist:810949
Created February 4, 2011 10:09
rails.monitrc
check process nginx with pidfile /opt/nginx/logs/nginx.pid
start program = "/opt/nginx/sbin/nginx"
stop program = "/opt/nginx/sbin/nginx -s stop"
if cpu is greater than 70% for 3 cycles then alert
if cpu > 80% for 5 cycles then restart
if 10 restarts within 10 cycles then timeout
check process sphinx with pidfile /home/josh/shared/pids/searchd.pid
stop program = "/bin/bash -c 'cd /home/josh/current && /usr/bin/rake RAILS_ENV=production ts:stop'"
start program = "/bin/bash -c 'cd /home/josh/current && /usr/bin/rake RAILS_ENV=production ts:start'"
@sandipransing
sandipransing / gist:810950
Created February 4, 2011 10:10
delayed_job
#! /bin/sh
set_path="cd /home/josh/current"
case "$1" in
start)
echo -n "Starting delayed_job: "
su - root -c "$set_path; RAILS_ENV=production script/delayed_job start" >> /var/log/delayed_job.log 2>&1
echo "done."
;;
stop)
#!/bin/sh
### BEGIN INIT INFO
# Provides: monit
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: service and resource monitoring daemon
### END INIT INFO
# chkconfig: 2345 56 10
@sandipransing
sandipransing / template.rb
Created February 28, 2011 19:20 — forked from cdmwebs/template.rb
Rails 3 template
generators = []
puts 'Spinning up a new app, captain!'
devise = yes?('Use Devise? (yes/no)')
jquery = yes?('Use jQuery? (yes/no)')
jquery_ui = yes?('Use jQuery UI? (yes/no)') if jquery
mongoid = yes?('Use mongoid? (yes/no)')
haml = yes?('Use haml? (yes/no)')
rspec = yes?('Use Rspec? (yes/no)')
def group_li_formatting(collection, column_one, column_two, column_three, options = {})
html_attributes_options(options)
li_default_options = {'data-role'=>"list-divider"}
list = collection.collect do |created, post|
tags = [content_tag("li", created, li_default_options)]
tags += post.collect do |p|
content_tag("li", "<h3>p.column_one</h3><p><strong>p.column_two</strong></p><p>p.column_three</p>".html_safe)
end
@sandipransing
sandipransing / heroku db pull error
Created June 29, 2011 15:05
heroku db pull error
heroku db:pull mysql://root@localhost/otz_production --app otz-production
Loaded Taps v0.3.23
Warning: Data in the database 'mysql://root@localhost/otz_production' will be overwritten and will not be recoverable.
! WARNING: Potentially Destructive Action
! This command will affect the app: otz-production
! To proceed, type "otz-production" or re-run this command with --confirm otz-production
> otz-production
Receiving schema