Posts

Showing posts from October, 2011

How Do I Create And Publish My First Ruby Gem?

Link: http://rubylearning.com/blog/how-do-i-create-and-publish-my-first-ruby-gem/ (sent via Shareaholic-Publishers) ---- What's a Ruby Gem? To solve various problems with Ruby, you might develop your own libraries. Also, you might want to open-source your libraries to get help from the Ruby community and have many developers working on the same. A gem is a packaged Ruby application or library. RubyGems is the st

Send ajax request from jquery.

It is better to send Ajax requests directly from java script or jquery instead clicking on button from Java Script to send Ajax request. insecure https protocol IE shows some error if you send clicking on button from java script to send Ajax request Sample code:- $j.ajax({  type: "POST",   url: " https://myurl.com/recent "  data: "requstids="+response.request_ids   })

scp command usage guide

Example syntax for Secure Copy ( scp ) What is Secure Copy? scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh . Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_username@remotehost.edu:foobar.txt /some/local/directory Copy the file "foobar.txt" from the local host to a remote host $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory Copy the directory "foo" from the local host to a remote host's directory "bar" $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Mysql backup and restore

This tutorial explains the how to backup and restore the MySQL Database. Databases are used to store large amount of precious data and it becomes very important to Backup your data. In case case of some hardware or software failures  backup data can be used to restore the Database. Backing Up MySQL Database MySQL database backup can be accomplished in two ways: a) Copying the raw mysql database files & b) Exporting tables to text files Copying the MySQL database files MySQL uses the same table format on different platforms, so it's possible to copy MySQL table and index files from one platform and use them on another without any difficulties (assuming, of course, that you're using the same version of MySQL on both platforms). Exporting tables to text files The MySQLDump is handy utility that can be used to quickly backup th

Jquery AJAX not working with session It is not taking old session issue with solution .

In my rails application when I trigger a Ajax request with my javascript in below way $j.ajax({ type: "POST", url:" https://mydomain.com/requests ", data: "requstids="+response.request_ids }).done(function( msg ) { alert( "Data Saved: " + msg ); }); The request is firing correctly but it is not taking my old session values of user It is showing error that your session variable is not available in my log any idea why it is not taking previous session ? and how to fix that ? I got solution we need to add below code in your header javascript, which tells use browser cookie in server externally ############################################### $(document).ajaxSend(function(e, xhr, options) { var token = $("meta[name='csrf-token']").attr("content"); xhr.setRequestHeader("X-CSRF-Token", token); }); ################################################ normally by default xhr willnot sent session

Setting up SSL certificate locations in Linux for https:// in facebook application

After soo much struggling of openssl support for https:// I got solution for that simply we have to follow two steps 1) Install OpenSSL in your system         follow the below documentation for installing in ubonto     https://help.ubuntu.com/community/OpenSSL 2) Configure your omniauth.rb file to use those installed certificates     kindly follow the below documentation for configuring in your application    https://github.com/intridea/omniauth/wiki/Setting-up-SSL-certificate-locations-in-Linux  

start thin server in production eneveronment

thin start -e production -P tmp/pids/thin.3000.pid -p 3000 -d I would use RAILS_ENV=production bundle exec thin start ...

cucumber usage in rails project

Add below gems to your gem file $ gem'database_cleaner' $gem'cucumber-rails' $gem'cucumber' $gem'rspec-rails' Then run bundle install from your root directory. run rake db:migrate next run the below command in your project rails g cucumber:install --capybara $ above command will generate all necessary files run the below command to write cucumber stories to your application. $ touch features/support/your_test_file_name.rb go to the above file and write your application stories run below command to implement test cases for stories $ rake cucumber:wip now we can add the step defination for story in step_defination folder #features/step_definitions/yourcontroller_steps.rb Given /^a regexpress that is "(.*)"$/ do |color| Strawberry.make!(:color => color) end

how to run shall command for every particular interval

try the 'watch' command. Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command> so that: watch -n1 command will run the command every second, forever OP has asked for link to OS X version of watch: http://www.macports.org/

Linux and Unix cp command

About cp Copies files from one location to another. Syntax cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... --target-directory=DIRECTORY SOURCE... -a, --archive same as -dpR --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument --copy-contents copy contents of special files when recursive -d same as --no-dereference --preserve=link --no-dereference never follow symbolic links -f, --force if an existing destination file cannot be opened, remove it and try again -i, --interactive prompt before overwrite

how to find unix is 64bit or 32bit

u can try in below three methods. >$ file /sbin/init /sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.16, dynamically linked (uses shared libs), stripped >$ file /usr/bin/file /usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), stripped >$ uname -m x86_64

use of rake -T

rake -T will display the all available commands for rake tasks.

rake aborted! ,, Could not find a JavaScript runtime. See,https://github.com/sstephenson/execjs, for a list of available runtimes.

You need a javascript engine for rails 3.1 (heroku doesn't have one), and it appears that the javascript engine that works with Heroku is the rubyracer for heroku . Rails uses execjs to execute javascript and execjs supports 7 javascript engines. Node.js is one, and rubyracer is one. Gerred Dillon had a similar problem and wrote about it. In the comment section a point was raised about making this a production only change, since you already have nodejs as your local javascript engine. So the relevant code is: group : production do   gem 'therubyracer-heroku' , '0.8.1.pre3' end UPDATE: Heroku has a new stack, called Cedar , that they recommend for Rails 3.1.0. Heroku also has a doc about upgrading to Rails 3.1.0 rc5. They recommend not using 'therubyracer-heroku' gem anymore as it's not necessary with rc5. Also, make sure to update your config/application.rb file if yo

Active Record Migrations

Active Record Migrations Migrations can manage the evolution of a schema used by several physical databases. It’s a solution to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to push that change to other developers and to the production server. With migrations, you can describe the transformations in self-contained classes that can be checked into version control systems and executed against another database that might be one, two, or five versions behind. Example of a simple migration: class AddSsl < ActiveRecord::Migration def up add_column : accounts , : ssl_enabled , : boolean , : default => 1 end def down remove_column : accounts , : ssl_enabled end end This migration will add a boolean flag to the accounts table and remove it i