Skip to content

Instantly share code, notes, and snippets.

View kalpesh-fulpagare's full-sized avatar
🎯
RubyOnRails, GoLang, AngularJS Developer

Kalpesh Fulpagare kalpesh-fulpagare

🎯
RubyOnRails, GoLang, AngularJS Developer
  • Scalefusion
  • Pune, India
View GitHub Profile
module KalpeshExtensions
def print *args
unless defined?(@log)
@log = Logger.new(Rails.root.to_s + "/log/custom.log")
@logger = Logger.new(Rails.root.to_s + "/log/#{Rails.env}.log")
end
puts "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}"
@log.info "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}"
@logger.info "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}"
@kalpesh-fulpagare
kalpesh-fulpagare / Testing + Backbone.txt
Last active December 23, 2015 19:39
Testing TDD - Imp BDD Links
Testing
https://tomafro.net/2009/05/automatching-rails-paths-in-cucumber
http://asciicasts.com/episodes/155-beginning-with-cucumber
http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html
Backbone
https://www.youtube.com/watch?v=FZSjvWtUxYk
@kalpesh-fulpagare
kalpesh-fulpagare / MetaprogrammingFindResourse.rb
Last active December 21, 2015 00:19
Meta-programming Method to find the resource for controllers
class ApplicationController < ActionController::Base
%w(user category post comment).each do |name|
define_method "find_#{name}" do
obj = instance_variable_set("@#{name}", name.camelize.constantize.find_by_id(params[:id]))
unless obj
flash[:alert] = "#{name.camelize} not found"
respond_to do |format|
format.html{ redirect_to "/#{name.pluralize}" }
format.js{ render js: "window.location='/#{name.pluralize}'" }
@kalpesh-fulpagare
kalpesh-fulpagare / database.yml
Created May 29, 2013 12:52
Sample database.yml file for Ruby on Rails app
# Postgres
development:
adapter: postgresql
encoding: utf8
database: text_development
username: postgres
password: root
host: localhost
# Sqlite
@kalpesh-fulpagare
kalpesh-fulpagare / clear.rb
Last active December 17, 2015 19:48
Running clear in IRB/Rails console for clearing screen content
# Create .irbrc file using touch
# $ touch ~/.irbrc
# Add following function to .irbrc file
def clear
system ‘clear’
end
# Open IRB with
# $ irb
@kalpesh-fulpagare
kalpesh-fulpagare / RoR app with Nginx
Last active December 17, 2015 19:48
Deploying RoR app with nginx server on local machine
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#install_on_debian_ubuntu
Instruction for Ubuntu 12.X (should work on 11.x also)
a. Installing passenger gem
$ gem install passenger
b. Installing passenger-nginx module(It will compile and install Nginx with Passenger support)
IF ruby is installed without RVM
@kalpesh-fulpagare
kalpesh-fulpagare / RoR app with Apache
Last active December 17, 2015 19:39
Deploying RoR app with apache server on local machine
Instruction for Ubuntu 12.X (should work on 11.x also)
a. Installing apache2 server
$ sudo apt-get install apache2
Restarting apache
$ sudo /etc/init.d/apache2 restart
b. Installing passenger gem
$ gem install passenger