1. bundle open activemodel
2. Open the validator.rb file.
3. You can see the comments that shows you how to mixin the validators. Once you mixin, you can add any validator and define a dummy method for the attribute to play with it in the irb:
class Person
include ActiveModel::Validations
SSN_REGEX = /your ssn regex goes here/
validates_format_of :ssn, with: SSN_REGEX
def ssn
111-11-1111
end
end
4. Change the ssn method to invalid ssn to test your regex.
Friday, August 22, 2014
Thursday, August 21, 2014
How to install Exception Notification gem in Rails 4.1
1. Add the gem to Gemfile:
gem 'exception_notification'
bundle install
2. In config/environments/production.rb:
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier"},
:exception_recipients => %w{exceptions@example.com}
}
3. Configure ActionMailer, in config/environments/production.rb:
I am using Sendgrid SMTP API so:
config.action_mailer.delivery_method = :smtp
If you have sendmail installed on the production server:
config.action_mailer.delivery_method = :sendmail
4. In production.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
gem 'exception_notification'
bundle install
2. In config/environments/production.rb:
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier"
:exception_recipients => %w{exceptions@example.com}
}
3. Configure ActionMailer, in config/environments/production.rb:
I am using Sendgrid SMTP API so:
config.action_mailer.delivery_method = :smtp
If you have sendmail installed on the production server:
config.action_mailer.delivery_method = :sendmail
4. In production.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
How to install pdftk on Mac OS
You can download the installer from https://www.pdflabs.com/tools/pdftk-server/
After installation, open a new terminal and check installation:
$ pdftk --version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
After installation, open a new terminal and check installation:
$ pdftk --version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
Wednesday, August 20, 2014
How to create .ruby-version and .ruby-gemset in RVM
rvm --create --ruby-version use ruby-2.1.2@r42
Reference: Create .ruby-version and .ruby-gemset
Reference: Create .ruby-version and .ruby-gemset
How to check if ElasticSearch is running
By default elastic search runs on port 9200.
$ curl http://localhost:9200
{
"ok" : true,
"status" : 200,
"name" : "White Pilgrim",
"version" : {
"number" : "0.90.13",
"build_hash" : "249c9c5e06765c9e929e92b1d235e1ba4dc679fa",
"build_timestamp" : "2014-03-25T15:27:12Z",
"build_snapshot" : false,
"lucene_version" : "4.6"
},
"tagline" : "You Know, for Search"
}
1. gem install rest-client
require 'rest-client'
RestClient.get('http://localhost:9200')
$ irb
> require 'rest-client'
=> true
> x = RestClient.get('http://localhost:9200')
=> "{\n \"ok\" : true,\n \"status\" : 200,\n \"name\" : \"White Pilgrim\",\n \"version\" : {\n \"number\" : \"0.90.13\",\n \"build_hash\" : \"249c9c5e06765c9e929e92b1d235e1ba4dc679fa\",\n \"build_timestamp\" : \"2014-03-25T15:27:12Z\",\n \"build_snapshot\" : false,\n \"lucene_version\" : \"4.6\"\n },\n \"tagline\" : \"You Know, for Search\"\n}\n"
> x['ok']
=> "ok"
> JSON.parse(x)
=> {"ok"=>true, "status"=>200, "name"=>"White Pilgrim", "version"=>{"number"=>"0.90.13", "build_hash"=>"249c9c5e06765c9e929e92b1d235e1ba4dc679fa", "build_timestamp"=>"2014-03-25T15:27:12Z", "build_snapshot"=>false, "lucene_version"=>"4.6"}, "tagline"=>"You Know, for Search"}
$ curl http://localhost:9200
{
"ok" : true,
"status" : 200,
"name" : "White Pilgrim",
"version" : {
"number" : "0.90.13",
"build_hash" : "249c9c5e06765c9e929e92b1d235e1ba4dc679fa",
"build_timestamp" : "2014-03-25T15:27:12Z",
"build_snapshot" : false,
"lucene_version" : "4.6"
},
"tagline" : "You Know, for Search"
}
1. gem install rest-client
require 'rest-client'
RestClient.get('http://localhost:9200')
$ irb
> require 'rest-client'
=> true
> x = RestClient.get('http://localhost:9200')
=> "{\n \"ok\" : true,\n \"status\" : 200,\n \"name\" : \"White Pilgrim\",\n \"version\" : {\n \"number\" : \"0.90.13\",\n \"build_hash\" : \"249c9c5e06765c9e929e92b1d235e1ba4dc679fa\",\n \"build_timestamp\" : \"2014-03-25T15:27:12Z\",\n \"build_snapshot\" : false,\n \"lucene_version\" : \"4.6\"\n },\n \"tagline\" : \"You Know, for Search\"\n}\n"
> x['ok']
=> "ok"
> JSON.parse(x)
=> {"ok"=>true, "status"=>200, "name"=>"White Pilgrim", "version"=>{"number"=>"0.90.13", "build_hash"=>"249c9c5e06765c9e929e92b1d235e1ba4dc679fa", "build_timestamp"=>"2014-03-25T15:27:12Z", "build_snapshot"=>false, "lucene_version"=>"4.6"}, "tagline"=>"You Know, for Search"}
Tuesday, August 19, 2014
How to configure the secret_key_base in Rails 4.1
1. Define an environment variable in .bashrc or .profile on the server:
export SECRET_KEY_BASE='a long string generated by running rake secret'
2. In secrets.yml file :
secret_key_base=<%= ENV['SECRET_KEY_BASE'] %>
3. MyBlog::Application.config.secret_key_base = Rails.application.secrets.secret_key_base
Remember: After deployment all the old sessions will become invalid.
export SECRET_KEY_BASE='a long string generated by running rake secret'
2. In secrets.yml file :
secret_key_base=<%= ENV['SECRET_KEY_BASE'] %>
3. MyBlog::Application.config.secret_key_base = Rails.application.secrets.secret_key_base
Remember: After deployment all the old sessions will become invalid.
Monday, August 18, 2014
How to add lib directory to the load path in Rails 4.1
Uncomment the line : config.autoload_paths += %W(#{config.root}/lib) in application.rb
Thursday, August 07, 2014
Installing Redis on Mac
~ $brew install redis
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/redis-2.8.9.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-2.8.9.mavericks.bottle.tar.gz
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
/usr/local/Cellar/redis/2.8.9: 10 files, 1.3M
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/redis-2.8.9.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-2.8.9.mavericks.bottle.tar.gz
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
/usr/local/Cellar/redis/2.8.9: 10 files, 1.3M
Wednesday, July 30, 2014
RubyPlus featured on ReadWriteWeb
Check it out : 15 Places to Find Great Screencasts
RubyPlus is now live! .org domain now will be redirected to .com domain.
RubyPlus is now live! .org domain now will be redirected to .com domain.
Saturday, July 26, 2014
Installing a specific version of elastic search
brew search elasticsearch
$ brew install homebrew/versions/elasticsearch090
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-versions'...
remote: Reusing existing pack: 2230, done.
remote: Total 2230 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2230/2230), 714.24 KiB | 12.00 KiB/s, done.
Resolving deltas: 100% (1260/1260), done.
Checking connectivity... done.
Tapped 149 formulae
==> Downloading https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.13.tar.gz
######################################################################## 100.0%
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_bparanj/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_bparanj.log
Plugins: /usr/local/var/lib/elasticsearch/plugins/
To have launchd start elasticsearch090 at login:
ln -sfv /usr/local/opt/elasticsearch090/*.plist ~/Library/LaunchAgents
Then to load elasticsearch090 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch090.plist
Or, if you don't want/need launchctl, you can just run:
elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
==> Summary
🍺 /usr/local/Cellar/elasticsearch090/0.90.13: 31 files, 19M, built in 6.8 minutes
Thursday, July 24, 2014
Installing Javascript Runtime
1. Uninstalled manually installed nodejs on Ubuntu 12.04. Since my server is managed by Moonshine. Manual installation is a bad idea.
2. Add :
gem 'execjs'
gem 'therubyracer'
to the Gemfile
3. Bundle and deploy.
sudo apt-get remove nodejs
2. Add :
gem 'execjs'
gem 'therubyracer'
to the Gemfile
3. Bundle and deploy.
Installing ElasticSearch using brew
$ brew install elasticsearch
Error: elasticsearch-0.90.9 already installed
To install this version, first `brew unlink elasticsearch'
$ brew unlink elasticsearch
Unlinking /usr/local/Cellar/elasticsearch/0.90.9... 3 symlinks removed
$ brew install elasticsearch
==> Downloading https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.tar.gz
######################################################################## 100.0%
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_bparanj/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_bparanj.log
Plugins: /usr/local/var/lib/elasticsearch/plugins/
ElasticSearch requires Java 7; you will need to install an appropriate JDK.
To reload elasticsearch after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
==> Summary
🍺 /usr/local/Cellar/elasticsearch/1.2.1: 31 files, 21M, built in 5.6 minutes
Error: elasticsearch-0.90.9 already installed
To install this version, first `brew unlink elasticsearch'
$ brew unlink elasticsearch
Unlinking /usr/local/Cellar/elasticsearch/0.90.9... 3 symlinks removed
$ brew install elasticsearch
==> Downloading https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.tar.gz
######################################################################## 100.0%
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_bparanj/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_bparanj.log
Plugins: /usr/local/var/lib/elasticsearch/plugins/
ElasticSearch requires Java 7; you will need to install an appropriate JDK.
To reload elasticsearch after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
==> Summary
🍺 /usr/local/Cellar/elasticsearch/1.2.1: 31 files, 21M, built in 5.6 minutes
Tuesday, July 22, 2014
Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
1. Specify the secret_key_base by using figaro gem. Search on this blog for how to do that.
Installing Phusion Passenger 4.0.45 using Moonshine in Ubuntu 12.04
1. Login to phusion passenger account.
2. Download the license
3. Move the license file to vendor/plugins/moonshine/lib/moonshine/manifest/rails/templates file. The name of the file is the same as the downloaded file name which is passenger-enterprise-license
4. Add the following to the moonshine.yml file:
:passenger:
:max_pool_size: 3
:version: 4.0.45 # This is 2 versions behind because according to the moonshine source code, this is the blessed version.
:enterprise: true
:download_token: copy-your-download-token-from-passenger-account-here
:rolling_restarts: true
5. Check in the code to bitbucket and do :
cap deploy
2. Download the license
3. Move the license file to vendor/plugins/moonshine/lib/moonshine/manifest/rails/templates file. The name of the file is the same as the downloaded file name which is passenger-enterprise-license
4. Add the following to the moonshine.yml file:
:passenger:
:max_pool_size: 3
:version: 4.0.45 # This is 2 versions behind because according to the moonshine source code, this is the blessed version.
:enterprise: true
:download_token: copy-your-download-token-from-passenger-account-here
:rolling_restarts: true
5. Check in the code to bitbucket and do :
cap deploy
No such file to load -- shadow puppet (LoadError) moonshine error
Copy the following lines to application.rb file.
# don't attempt to auto-require the moonshine manifests into the rails env
config.paths['app/manifests'] = 'app/manifests'
config.paths['app/manifests'].skip_eager_load!
# don't attempt to auto-require the moonshine manifests into the rails env
config.paths['app/manifests'] = 'app/manifests'
config.paths['app/manifests'].skip_eager_load!
Installing NodeJS using Moonshine Plugin
1. plugger install git://github.com/iros/moonshine_nodejs.git
2. Add
2. Add
recipe :nodejs
to the application_manifest.rb
This will fail gloriously.
Install it by:
apt-get install python-software-properties
apt-add-repository ppa:chris-lea/node.js
apt-get update
apt-get install nodejs
node -v
should show :v0.10.20
Reference : NodeJS installation on Ubuntu 12.04
How to display flash messages using Twitter Bootstrap 3 in Rails 4.1
1. Copy the following helper method to app/helpers/application_helper.rb
def bootstrap_class_for(flash_type)
case flash_type
when "success"
"alert-success" # Green
when "error"
"alert-danger" # Red
when "alert"
"alert-warning" # Yellow
when "notice"
"alert-info" # Blue
else
flash_type.to_s
end
end
2. Create a shared folder in app/views
3. Copy the following code to app/views/_flash_messages.html.erb
<% flash.each do |type, message| %>
<%= message %>
<% end %>
4. In your layout, add the line : <%= render '/shared/flash_messages' %>
above the yield call.
5. Set the flash messages in any of your controllers and you will see the flash messages displayed.
Reference : Stolen from gist.
def bootstrap_class_for(flash_type)
case flash_type
when "success"
"alert-success" # Green
when "error"
"alert-danger" # Red
when "alert"
"alert-warning" # Yellow
when "notice"
"alert-info" # Blue
else
flash_type.to_s
end
end
2. Create a shared folder in app/views
3. Copy the following code to app/views/_flash_messages.html.erb
<% flash.each do |type, message| %>
<%= message %>
<% end %>
4. In your layout, add the line : <%= render '/shared/flash_messages' %>
above the yield call.
5. Set the flash messages in any of your controllers and you will see the flash messages displayed.
Reference : Stolen from gist.
Final Cut Pro 10.1.2 Crash Course in 10 Minutes
Recording Voice Over
Step 1 : Detach the audio from the video
1. Select the clip from the timeline window.
2. Go to Clip --> Detach audio
3. Select the audio and click delete.
Step 2 : Record Voice Over
1. Click the timeline where you want to start recording the voice over.
2. Go to window, Record Voice Over.
3. Click Record
4. Click the red button to stop recording.
If you make a mistake select the audio track in TL and delete.
Speeding up the Video
1. Select Blade from the dropdown.
2. Select the start and end of the video by using the blade.
3. Modify --> Retime --> 4x
4. Go back to the drop down and select the pointer.
Note : Select before you change the timing so that the rest of the video is unaffected.
Deleting Part of the Clip
1. Select the blade from the drop down.
2. Pick the starting and the end point of the clip
3. Select the pointer from the drop down.
4. Select the clip to reject and click delete.
Audio Enhancement
1. Select the audio
2. Modify --> Auto Enhance Audio
3. Right window, click on Audio Enhancements for any problems
Noise Reduction
1. Select the audio clip
2. Click the wizard inspector
3. Select audio enhancements
4. Background noise removal and hum removal to remove noise
Refer Enhance Audio section in the Help window of FCP.
Preroll
1. Import both videos
2. Drop the title video into the TL and then the video to be processed.
Exporting the Edited Video
1. File --> Share --> Master File
This will export the video in quick-time format.
Recovering from Mistakes
Undo : Command+Z
Step 1 : Detach the audio from the video
1. Select the clip from the timeline window.
2. Go to Clip --> Detach audio
3. Select the audio and click delete.
Step 2 : Record Voice Over
1. Click the timeline where you want to start recording the voice over.
2. Go to window, Record Voice Over.
3. Click Record
4. Click the red button to stop recording.
If you make a mistake select the audio track in TL and delete.
Speeding up the Video
1. Select Blade from the dropdown.
2. Select the start and end of the video by using the blade.
3. Modify --> Retime --> 4x
4. Go back to the drop down and select the pointer.
Note : Select before you change the timing so that the rest of the video is unaffected.
Deleting Part of the Clip
1. Select the blade from the drop down.
2. Pick the starting and the end point of the clip
3. Select the pointer from the drop down.
4. Select the clip to reject and click delete.
Audio Enhancement
1. Select the audio
2. Modify --> Auto Enhance Audio
3. Right window, click on Audio Enhancements for any problems
Noise Reduction
1. Select the audio clip
2. Click the wizard inspector
3. Select audio enhancements
4. Background noise removal and hum removal to remove noise
Refer Enhance Audio section in the Help window of FCP.
Preroll
1. Import both videos
2. Drop the title video into the TL and then the video to be processed.
Exporting the Edited Video
1. File --> Share --> Master File
This will export the video in quick-time format.
Recovering from Mistakes
Undo : Command+Z
Thursday, July 17, 2014
Using Figoro Gem with Moonshine
1. Add gem 'figaro' to Gemfile
2. rails g figaro:install
Creates config/application.yml and adds it to .gitignore.
3. Here is the syntax for environment specific configuration
# config/application.yml
pusher_app_id: "2954"
pusher_key: "7381a978f7dd7f9a1117"
pusher_secret: "abdc3b896a0ffb85d373"
google_analytics_key: "UA-35722661-5"
test:
pusher_app_id: "5112"
pusher_key: "ad69caf9a44dcac1fb28"
pusher_secret: "83ca7aa160fedaf3b350"
test:
google_analytics_key: ~
4. Use rake secret to generate a secret for any of your keys
5. Access the values in the code:
ENV['pusher_secret']
or
Figaro.env.pusher_secret
6. Specify required keys in config/initializers/figaro.rb
Figaro.require("pusher_app_id", "pusher_key", "pusher_secret")
7. Add config/application.yml to local directive in Moonshine. Edit moonshine.yml :shared_config: directive.
8. Deploy the application
2. rails g figaro:install
Creates config/application.yml and adds it to .gitignore.
3. Here is the syntax for environment specific configuration
# config/application.yml
pusher_app_id: "2954"
pusher_key: "7381a978f7dd7f9a1117"
pusher_secret: "abdc3b896a0ffb85d373"
google_analytics_key: "UA-35722661-5"
test:
pusher_app_id: "5112"
pusher_key: "ad69caf9a44dcac1fb28"
pusher_secret: "83ca7aa160fedaf3b350"
test:
google_analytics_key: ~
4. Use rake secret to generate a secret for any of your keys
5. Access the values in the code:
ENV['pusher_secret']
or
Figaro.env.pusher_secret
6. Specify required keys in config/initializers/figaro.rb
Figaro.require("pusher_app_id", "pusher_key", "pusher_secret")
7. Add config/application.yml to local directive in Moonshine. Edit moonshine.yml :shared_config: directive.
8. Deploy the application
Subscribe to:
Posts (Atom)