Jul 7, 2016

Enabling password authentication for new ec2 box | ssh, ssh config, EC2 setup, new user in EC2, PasswordAuthentication

Your EC2 box only contain .pem auth to enable password authentication follow the steps



By default your ec2 box come with .pem authentication, once you create your user and password for that user you can’t able to login with that credentials because EC2 by default disables that functionality.
Edit ssh config file by below command
$ sudo vim /etc/ssh/sshd_config 
Search for PasswordAuthentication setting and setit to yes
PasswordAuthentication yes
Restart ssh server
$sudo /etc/init.d/ssh reload

Deployment instructions using github hooks to Ec2 or any cloud VS like HEROKU does | deployment, github hooks, heroku, set production server, set server, EC2

Prepare your github repo on /var/www folder to follow the best practice.
$cd /var/www
Create a source code folder with your application name
$ sudo mkdir <Project Name>.com
Create a folder for github source code
$ sudo mkdir <Project Name>.com.git
Change to project github repo folder
$cd img-cloud-qa.com.git/
Initiate github bare to prepare folder
$sudo git init --bare
Jump to hooks to prepare your hooks for git preparation of project so you can start pushing your code to github.
$cd hooks
Now we are ready with hooks set to your project, create a post-receive file to execute your steps with shell script, below example is a node project and i am doing npm install and restarting web server.
$sudo nano post-receive

#!/bin/sh
error_exit ()
{
echo "$1" 1>&2
exit 1
}
git --work-tree=/var/www/<Project Name>.com --git-dir=/var/www/<Project Name>.com.git checkout -f
cd /var/www/<Project Name>.com || error_exit "error changing directory!. now exiting..."
npm install || error_exit "error running npm install! now exiting ..."
FOREVER_ROOT=/etc/forever forever restart -l /etc/forever/<Project Name>.log bin/www || error_exit "error starting forever server! now exiting ..."
Finally assign the proper permissions to the user to write files to to folder
$sudo chown -R deploy:deploy www/
Once all above steps done you are ready to deploy push your code to your project with below steps
git add remote <user>@<ip or host>:/var/www/<Project Name>.com.git
git push master
Ex:-

git add remote prod deploy@gsrao.xyz:/var/www/myapp.com.git
git push prod master

Ruby on Rails 3.x Skip callback and validation and reset Callback | Ruby on Rails, Skip callback, validation, reset Callback

This will work for Rails 3.x onwords

Model.skip_callback(“create”,:after,:trigger_my_method)
in the above line ‘create’ and ‘after’ represents callback name so it represents ‘after_create’ callback, and the callback method is ‘trigger_my_method’, so totally the above line skips below callback
after_create :trigger_my_method
You can skip validations just by passing :validate =&gt; false as parameter to save method
Model.save(:validate =&gt; false)
As before skipping callback, you can reset same callback for reset by below ling
Model.set_callback(“create”,:after,:trigger_my_method)
This line will reset the below callback
after_create :trigger_my_method
Example:-
Skip callback and validation and  rest the skiped callback
Post.skip_callback(“create”,:after,:trigger_my_method)
post=Post.new(params[:post])
post.save(:validate =&gt; false)
Post.set_callback(“create”,:after,:trigger_my_method)

Ruby one of the method of creating a single ton method | Ruby, single ton method

cat = String.new("cat")
def cat.speak
    'miaow'
end
cat.speak #=&gt; "miaow" 
cat.singleton_methods #=&gt; ["speak"] 

Ruby Rightsignature API to prefill the template | Ruby, Rightsignature, API to prefill template

For this Please signup with https://rightsignature.com/ to get your api key and secrets
Generate a new API key by the url https://rightsignature.com/oauth_clients/new
Install rightsignature-api gem by the command
gem install rightsignature-api
gem ‘rightsignature-api‘   in your gem file

Setup your api with secret key by the code 

@rs_connection = RightSignature::Connection.new(:api_token =&gt; YOUR_TOKEN)
 You can view the list of templates by the code
@rs_connection.templates_list
If you want to  view more details of template 
@rs_connection.template_details(guid)
You need to Clone a template to fill and send the template as a document
 @rs_connection.prepackage(guid)
Pre fill the required templates by the code (wre need to use merge fields to fil the data, you can't use the text fields to pre fill)
@rs_connection.prefill(guid, subject, roles, options={})
Send the template to signature by the code 
@rs_connection.send_template(guid, subject, roles, options={})
Note:- We can prefill only merge field not text or other field 
 Merge field is found while creating a template, is shown in below image
 https://rightsignature.com/oauth_clients/new

My router blocking facebook and youtube video play only for my laptop not other laps in same network, my lap works if i bypass modem. | router, blocking, facebook, youtube, video play

Question : I have reset factory settings, reboot my modem, pc, clear cache, etc. still its not loading facebook but will load any and all other websites. When i bypass the router, connect directly to my modem, facebook works. why is this happening?
Solution : It is because of TCP packet size for that we need to change the MTU size of our tcp connection, below commands will help to do that
$ifconfig 
above command will display the available networks with name and if addrsss
Ex:-
$ifconfig
eth0      Link encap:Ethernet  HWaddr b8:ca:3a:d4:63:1d
UP BROADCAST MULTICAST  MTU:1492  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:776 errors:0 dropped:0 overruns:0 frame:0
TX packets:776 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:79415 (79.4 KB)  TX bytes:79415 (79.4 KB)
wlan0     Link encap:Ethernet  HWaddr 60:6c:66:26:6c:9f
inet addr:192.168.2.101  Bcast:192.168.2.255  Mask:255.255.255.0
inet6 addr: fe80::626c:66ff:fe26:6c9f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:50480 errors:0 dropped:0 overruns:0 frame:0
TX packets:42606 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:58833138 (58.8 MB)  TX bytes:6534754 (6.5 MB)
In above my current network is wlan0 with ip 192.168.2.101
So now we need to change MTU for wlan0 with below command
$sudo ifconfig wlan0 mtu 1492
That will reset the MTU to 1492 and my problem solved. :)

Rails working with multiple databases customize the generator | Rails, multiple databases, customize generator

In ROR working with multiple databases ( Mysql + MongoID or Postgres + MongoId ) for performance is good, but how can i give default generator database to pick-up while generating the models
edit application.rb in config folder and add below code
config.generators do |g|
g.orm             :active_record
end
So every time in next generators will take active record as default for moddels
In case of using mongoid and active record this will be helpful

ROR HEROKU Working with file storage like paperclip in heroku for free of cost ( paperclip and dropbox) paperclip-dropbox config | ROR, HEROKU, file storage, paperclip, in heroku, free of cost, paperclip, dropbox, paperclip-dropbox config

In my project i am using paper-clip and deployed to heroku, heroku not allows the file storage but to use aws normally, i don’t want to spend money so i can use drop box storage which will gives 2gb free storage space.
So i am using paper-clip with drop box with library papercklip-dropbox gem, steps to follow are given below.
  1. Include  gem “paperclip-dropbox” in your gem file
  2. Run the command $bundel install 
  3. Create drop box api app in https://www.dropbox.com/developers/apps   and give read write permissions it gives you the App key and App secret  which will used in further configeration
  4. Generate the other required details using available details, run the rake task to generate other details “$rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret ACCESS_TYPE=your_access_typ “, this command will generate the access_token, access_token_secret, user_id
  5. Create dropbox_config.yml  file in config folder and place all keys got in previous steps 
    app_key:  YOUR_APP_KEY
    app_secret: YOUR_APP_SECRET
    access_token: YOUR_ACCESS_TOKEN
    access_token_secret:  YOUR_ACCESS_TOKEN_SECRET
    user_id:  YOUR_USER_ID
    access_type: “app_folder”
  6.  Now relace paper clip code with new code for attachment, like User profile picture
    #added for paperclip-dropbox gem
    has_attached_file :picture,
    :storage =&gt; :dropbox,
    :dropbox_credentials =&gt; “#{Rails.root}/config/dropbox_c
    onfig.yml”,
    :styles =&gt; { :medium =&gt; “300×300” , :thumb =&gt; “100×100&gt;”},
    :dropbox_options =&gt; {
    :path =&gt; proc { |style| “#{Rails.env}/#{style}/#{id}_#{picture.original_filename}”},       :unique_filename =&gt; true
    }
  7. Deploy your code  in heroku you can, you can see all files or images uploaded as profile pictures will store in your drop box.
Enjoy the drop box free usage in cloud

AngularJS e2e Testing Using Protractor and automate Grunt Task, with useful code modules | e2e, Testing, Protractor, automate Grunt Task

Please check my post on my company blog post on AngularJs e2e testing.

Mar 28, 2012

Ruby on Rails enable history in ajax calls


Refer below link

http://lindsaar.net/2008/2/21/history-buttons-with-ajax-and-ruby-on-rails

and use the code

window.dhtmlHistory.create({



toJSON: function(o) {

return JSON.stringify(o);



} , fromJSON: function(s) {



return JSON.parse(s);



}



});


instead of


window.dhtmlHistory.create({   toJSON: function(o) {     return Object.toJSON(o);   },   fromJSON: function(s) {     return s.evalJSON();   } });    

on that post  Happy learning

Mar 20, 2012

Hacking and Crackers Knowledge

Following are the importent web sites to know hackers and crackers

Vulnerability Research
Websites

www.securitytracker.com
www.microsoft.com/security
www.securiteam.com
www.packetstormsecurity.com
www.hackerstorm.com
www.hackerwatch.org
www.securityfocus.com
www.securitymagazine.com
####################################################
Securitytracker

www.securitytracker.com
#####################################################
Securiteam
(www securiteam com)
www.securiteam.com)
###################################################
Secunia (secunia.com/product/)

####################################################
Hackerstorm Vulnerability Database
Tool (www.hackerstorm.com)
####################################################
SecurityFocus
www.securityfocus.com
####################################################
SecurityMagazine
www.securitymagazine.com
#######################################################
SC Magazine
www.scmagazine.com
####################################################
http://www.usdoj.gov (cont'd)
#####################################################

Rails Memcache issues

Error :-
down_retry_delay not reached for localhost:11211 (0.001 seconds left)
down_retry_delay not reached for localhost:11211 (0.001 seconds left)
down_retry_delay not reached for localhost:11211 (0.001 seconds left)
down_retry_delay not reached for localhost:11211 (0.001 seconds left)
[2012-03-20 15:08:28] ERROR NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler/webrick.rb:71:in `service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
cache: [GET /assets/kanga_custom/search_merchant.js?body=1] miss, store
Dalli::Server#connect localhost:11211
localhost:11211 failed (count: 3)
localhost:11211 is still down (for 2.030 seconds now)

and

root@rao-desktop:~/Aptana Studio 3 Workspace/Kanga# irb
irb(main):001:0> require 'dalli'
=> true
irb(main):002:0> dc = Dalli::Client.new('localhost:11211')
=> #<Dalli::Client:0x9f89338 @servers="localhost:11211", @options={:expires_in=>0}, @ring=nil>
irb(main):003:0> dc.set('abc', 123)
I, [2012-03-20T15:04:48.093716 #2419]  INFO -- : localhost:11211 failed (count: 0)
Dalli::RingError: No server available
    from /usr/local/lib/ruby/gems/1.9.1/gems/dalli-1.1.5/lib/dalli/ring.rb:45:in `server_for_key'
    from /usr/local/lib/ruby/gems/1.9.1/gems/dalli-1.1.5/lib/dalli/client.rb:263:in `perform'
    from /usr/local/lib/ruby/gems/1.9.1/gems/dalli-1.1.5/lib/dalli/client.rb:139:in `set'
    from (irb):3
    from /usr/local/bin/irb:12:in `<main>'
irb(main):004:0>

Solution:-


Try 127.0.0.1 instead of localhost. in delli gem configuration



Mar 19, 2012

Ruby slice big array into equal parts

By using each_slice we can convert single dimension array in to multi dimention array  foo.each_slice(3).to_a #=> [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]]