This can be done by using the linux find command,
$ย find . -name "Rakefile"
Read more about linux find command from:ย http://linux.die.net/man/1/find
This can be done by using the linux find command,
$ย find . -name "Rakefile"
Read more about linux find command from:ย http://linux.die.net/man/1/find
From command line type
$ ls -l | wc -l
Here is an easy way to find this, in command line type
$ getconf LONG_BIT
Synopsis:
getconf [-v specification] system_var
theย getconfย utility shall write to the standard output the value of the variable specified by theย system_varย operand.
So it prints the value of ‘LONG_BIT’.
Read linux manual for getconf:ย http://linux.die.net/man/1/getconf
To get information about your Rails Environment Rails, Ruby, Rack versions use the following command,
$ rake about About your application's environment Ruby version 1.9.2 (i686-linux) RubyGems version 1.8.10 Rack version 1.3 Rails version 3.1.3 JavaScript Runtime therubyracer (V8) Active Record version 3.1.3 Action Pack version 3.1.3 Active Resource version 3.1.3 Action Mailer version 3.1.3 Active Support version 3.1.3 Middleware Rack::Cache, ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rack::MethodOverride, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport, Warden::Manager, OmniAuth::Builder Application root /home/abhi/my_app Environment development Database adapter mysql2 Database schema version 20120704103548
We know that how useful the rails console is. We can access the database and manupulate the data, but if you wish to test out some code without changing any data of your database, you can use sandbox option rails console –sandbox.
$ rails console --sandbox Loading development environment in sandbox (Rails 3.1.0) Any modifications you make will be rolled back on exit irb(main):001:0>
How is it?
Sometime when we found a lot of process associates with a software or something that may hurt our memory or CPU, and it would be nice to kill that all process and be our system in a fine position. But when there is so many process we can’t kill all the process by hand using the command
$ kill -9 PID
where ‘PID’ is the process id.
Shell commands will help us to do this. See below
First you create a .sh file file named ‘killAllProcess.sh’.
#!/bin/bash echo "Usage : ./killAllProcess.sh " for i in `ps ax | grep $1 | grep -v grep | sed 's/ *//' | sed 's/[^0-9].*//'` do kill -9 $i done echo "Killed All the process which has name with $1"
And make this file executable
$ chmod +x killAllProcess.sh
Then run it
$ ./killAllProcess.sh
And see any process with that name is there
$ ps aux | grep PROCESS_NAME
All vanishes..!!
When I am seeking for this for Rails paperclip gem’s filename replacement, I found a very useful regular expression,
ruby-1.9.2-p290 :042 > name = "Abhi@## lash@###)(*&(!@"
=> "Abhi@## lash@###)(*&(!@"
ruby-1.9.2-p290 :043 > name.gsub(/([_@#!%()\-=;><,{}\~\[\]\.\/\?\"\*\^\$\+\-]+)/, ' ')
=> "Abhi lash & "
Here I am writing about the ruby scan method for string.
syntax: scan(pattern) => array
Take a string name, where
irb> name = "Viswanathan Anand"
You scan through the string for words by,
ruby-1.9.2-p290 :014 > name.scan(/\w+/)
=> ["Viswanathan", "Anand"]
scan for 3 letters and make them an array element,
ruby-1.9.2-p290 :015 > name.scan(/.../)
=> ["Vis", "wan", "ath", "an ", "Ana"]
scan for 3 letters and group them with an array and make them array element,
ruby-1.9.2-p290 :016 > name.scan(/(...)/)
=> [["Vis"], ["wan"], ["ath"], ["an "], ["Ana"]]
and you can make three two pair letters in an array like:
ruby-1.9.2-p290 :017 > name.scan(/(...)(...)/)
=> [["Vis", "wan"], ["ath", "an "]]
You can also use reg exp like,
ruby-1.9.2-p290 :018 > name.scan(/[A-Z][a-z]+/)
=> ["Viswanathan", "Anand"]
Suppose you want a hash with keys from an array and values from another array, use something like
ruby> ids = [1,2,3,4]
=> [1, 2, 3, 4]
ruby> names = ['Dan Brown', 'Stella', 'Parker']
=> ["Dan Brown", "Stella", "Parker"]
ruby> Hash[ids.zip names]
=> {1=>"Dan Brown", 2=>"Stella", 3=>"Parker", 4=>nil}
We can use a memcached server for centralized caching in our application. This server is handling all caching mechanisms. Rails is using the gem memcache-client by default. But here I am using the dalli gem. Because it is better than memcache-client, but one thing to say is I am not experienced this. By reading documents, I have concluded that. You just go through this dalli gem link, https://github.com/mperham/dalli. This is a super caching mechanism by Rails in production environments. The Only thing we need to do is
config.action_controller.perform_caching = true
Add the following in your gem file and do bundle install
$ gem 'dalli', '2.0.2' $ bundle install
$ sudo apt-get install memcached
$ sudo /etc/init.d/memcached start
config.cache_store = :dalli_store, 'YOUR_PRODUCTION_PUBLIC_DNS:11211',
{ :namespace => "app-YOUR_HOST", :expires_in => 1.day, :compress => true }
Here ‘YOUR_PRODUCTION_PUBLIC_DNS:11211’ is saying where your memcached server is running. Public DNS and the port number of the memcached server.
Take the rails console and experiment something like the following to know the MemCacheStore cache mechanism is working. If you are in localhost then do
ruby-1.9.2-p290 :003 > cache = Dalli::Client.new('localhost:11211')
=> #0}, @ring=nil>
ruby-1.9.2-p290 :004 > cache.set('testing', 1234)
=> true
ruby-1.9.2-p290 :006 > cache.get('testing')
=> 1234
Now you are ready to go