Skip to content

Instantly share code, notes, and snippets.

View vparihar01's full-sized avatar

Vivek Parihar vparihar01

View GitHub Profile
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
namespace :db do
desc "copying the xml country_region data to database of country"
task :country => :environment do
data = Nokogiri::XML.parse(File.read("#{Rails.root}/public/xml/country.xml"))
data.xpath("//countries/country").each do |node_country|
@country = Country.create(:code => node_country.xpath("./code").inner_text,:name => node_country.xpath("./name").inner_text)
node_country.xpath("./regions/region").each do |node_region|
@vparihar01
vparihar01 / log
Created May 6, 2013 09:06
Production.log error log.
Started POST "/fcs/ident2" for 114.143.191.203 at 2013-05-06 05:04:20 -0400
ActionController::RoutingError (No route matches [POST] "/fcs/ident2"):
actionpack (3.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.5) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.5) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
clear
cd current
bundle install
tail -f /var/log/casserver.log
vim config.yml
exit
ifconfig
df -h
showmount -e
ls -la
Start and stop the server on Windows
Start and stop the server on Linux
Start and stop Apache
Start and stop the server on Windows
Start the server from the Start menu
Choose Start > All Programs > Adobe > Flash Media Server 4.5 > Start Adobe Flash Media Server 4.5.
Choose Start > All Programs > Adobe > Flash Media Server 4.5 > Start Flash Media Administration Server 4.5.
Stop the server from the Start menu

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@vparihar01
vparihar01 / gist:5575280
Created May 14, 2013 11:32
PERFORMANCE TUNING FOR PHUSION PASSENGER for production ready app.
# PassengerMaxPoolSize
# Default: 6
# For 2gb RAM: 30
# For 256 slice with MySQL running: 2
PassengerMaxPoolSize 2
# PassengerPoolIdleTime
# Recommended to be avg time per page * 2
# In Google Analytics... (Avg time on site / Avg page views) * 2
# Default: 300
@vparihar01
vparihar01 / user_mailer.rb
Last active June 7, 2019 09:27
Just copy the user_mailers inside your Mailers directory and then inside user_mailers views move welcome_email_to_player.html.haml. Then user UserMailer.welcome_email_to_player.deliver. tada.... Your mail is sent. For out just check this test yomail account => [email protected].
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def welcome_email_to_player
attachments.inline['user_back'] = {
:data => File.read("#{Rails.root.to_s + '/app/assets/images/bg.jpg'}"),
:mime_type => "image/jpg",
:encoding => "base64"
}
mail(:to => "[email protected]", :subject => "Welcome to here")
end

Exposing an API

APIs are becoming an essential feature of modern web applications. Rails does a good job of helping your application provide an API using the same MVC structure you're accustomed to.

In the Controller

Let's work with the following example controller:

class ArticlesController &lt; ApplicationController
class YourModel
before_save :sanitize_name
private
def sanitize_name
self.name = CGI::escapeHTML(name)
end
end