Unable to create rails application with sqlserver

Could not find “config/databases/sqlserver.yml” in any of your source paths.

Your current source paths are:
$HOME/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/generators/rails/app/templates

Error:

Template sqlserver.yml file missing.

Solution:

Need to update sqlserver.yml file in the specific location to fix this issue.

Step1: Download sqlserver.yml configuration file.

Step2: Extract the downloaded zip file.

Step3: Copy extracted sqlserver.yml configuration file into the location which thrown error while creating sqlserver database rails application.

i.e,

$HOME/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml

Step4: Now create new rails application with database as sqlserver

rails new sqlserverProj -d sqlserver

It will create rails application without any error.

Permanent link to this article: https://blog.openshell.in/2013/04/unable-to-create-rails-application-with-sqlserver/

YII – set default settings within module and controller

Which helps to overwrite default settings of module and controller. To set default controller, view, layout and theme.

Set default controller within module

[php]
/**
* @var string the default controller.
*/

public $defaultController = ‘controller_name’;
[/php]

To Set default layout, theme and views within controller, use the following commands.

[php]
/**
* @var string the default layout and view/action.
*/
public $layout = ‘layout_name’;
public $defaultAction = ‘action_name’;

/**
* @var string the default theme.
*/
Yii::app()->theme =’theme_name’;
[/php]

Permanent link to this article: https://blog.openshell.in/2013/04/yii-set-default-settings-within-module-and-controller/

Hadoop Error: Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out.

If we face the following error while running hadoop jobs

http://<masternode ip>:50030/jobtracker.jsp

Error:

“Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out.”

Description:

Respective box name <machine name> is not updated in all the cluster configuration files (hadoop and /etc/hosts)

Steps to resolve:

Step 1:

Stop all the hadoop services in master node

hduser: /usr/local/hadoop/bin/stop-all.sh

Step 2:

Edit the hadoop configuration file and update the box name in all cluster nodes

Location: /usr/local/hadoop/conf/

List of files:

core-site.xml

mapred-site.xml

hdfs-site.xml

slaves

masters

Step 3:

Edit the following file and update the entries as follows

/etc/hosts

<ipaddress> space <box name>

Step 4:

Perform step 4 in all the cluster nodes

root: rm -rf /app/

root: mkdir -p /app/hadoop/tmp

root: chmod -R 0755 /app/

root: chown -R hduser:hadoop /app

hduser: /usr/local/hadoop/bin/hadoop namenode -format

Step 5:

Start all the hadoop services in the master node

hduser: /usr/local/hadoop/bin/start-all.sh

Step 6:

Check whether all the services are running

hduser: jps

Masternode : 6 services

Jps

DataNode

TaskTracker

SecondaryNameNode

NameNode

JobTracker

Slave Nodes : 3 services

Jps

DataNode

TaskTracker

Permanent link to this article: https://blog.openshell.in/2013/03/hadoop-error-shuffle-error-exceeded-max_failed_unique_fetches-bailing-out/

Installation of Yii

YII – Yes It Is

YII is a high-performance PHP framework best for developing large-scale Web applications.

Download the latest stable version from http://www.yiiframework.com/

Extract the folder and place it under the webroot location Eg., /var/www/ in linux and htdocs in windows

php <path to yii folder>/framework/yiic.php webapp <applicationname>

Additionally set the path for php in windows, the execute the above command to create a new application

Permanent link to this article: https://blog.openshell.in/2013/03/installation-of-yii/

Installing Django on Ubuntu

About Django:

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Developed by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.

Optional installations:

There are a number of optional packages that can be used with Django. Run the following command to install the optional packages.

[code]sudo aptitude install python-imaging python-pythonmagick python-markdown python-textile python-docutils[/code]

If you want more information about the package then use ‘show’ subcommand with the respective package name.

[code]aptitude show python-imaging[/code]

These packages are optional and frequently used. So it’s up to you if you want to use them with Django or not.

Installing Django with Aptitude:

To date, this is not the recommended way of installing Django as it comes with an older version. However, if you still want to follow this method, you can use this command

[code]sudo aptitude install python-django[/code]

Once it has download, you can check that Django is installed and working.

[code]django-admin[/code]

The prompt will show the line below, followed by a long set of options.

[code]Usage: django-admin subcommand [options] [args][/code]

Installing Django without Aptitude:

If you don’t want to use aptitude, then this is your best bet for installing Django. In this method, we will download the official stable release and install it manually.

[code]
wget https://www.djangoproject.com/download/1.4/tarball/
tar xzvf index.html
cd Django-1.4
sudo python setup.py install
[/code]

You can use this command to check that Django is installed and working

[code]django-admin.py[/code]

You should get below response, and it will be followed by a long set of options.

[code]Usage: django-admin subcommand [options] [args][/code]

Installing Django from the Git Repository:

If you are looking for the latest release of Django that supports all major features, then download the program through git.

Before you start, you need to download git:

[code]apt-get install git-core[/code]

Once it downloads, you can install Django:

[code]git clone https://github.com/django/django.git[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/installing-django-on-ubuntu/

How to automate whodidit behaviour and timestamps in yii ActiveRecord model?

To automate whodidit and timestamps in yii activerecord model using beforesave() method. If the rule validation got success then only the beforesave() method will invoke. Without satisifying rule() in activerecord model, this method will not work.

[php]
protected function beforeSave() {
if(parent::beforeSave()) {
if($this->isNewRecord) {
$this->created_on = time();
$this->created_by = (int)Yii::app()->user->id;
}
$this->updated_on = time();
$this->updated_by = (int)Yii::app()->user->id;
return true;
} else return false;
}
[/php]

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-automate-whodidit-behaviour-and-timestamps-in-yii-activerecord-model/

How to automate timestamps in activerecord using yii

There are many ways to automate the setting of timestamps in yii ActiveRecord models. In this we are representing three ways here.

1) Update via model’s rules:

[php]
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
array(‘title’,’length’,’max’=>255),
array(‘title, created_at, updated_at’, ‘required’),
array(‘updated_at’,’default’,
‘value’=>new CDbExpression(‘NOW()’),
‘setOnEmpty’=>false,’on’=>’update’),
array(‘created_at,updated_at’,’default’,
‘value’=>new CDbExpression(‘NOW()’),
‘setOnEmpty’=>false,’on’=>’insert’)
);
}
[/php]

2) Another to use beforeSave() as follows:

[php]
public function beforeSave() {
if ($this->isNewRecord)
$this->created_at = new CDbExpression(‘NOW()’);

$this->updated_at = new CDbExpression(‘NOW()’);

return parent::beforeSave();
}
[/php]

3) Another alternative to use CTimestampBehavior in your models:

[php]
public function behaviors()
{
return array(
‘CTimestampBehavior’=>array(
‘class’=>’zii.behaviors.CTimestampBehavior’,
‘createAttribute’=>’created_at’,
‘updateAttribute’=>’updated_at’,
‘setUpdateOnCreate’=>true,
‘timestampExpression’=>new CDbExpression(‘NOW()’);
)
);
}
[/php]

Note: Instead of using NOW(), you can also use UTC_TIMESTAMP().

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-automate-timestamps-in-activerecord-using-yii/

mysql2 gem for windows error

By  installing  Development Kit and MySql Connector:

To install Development Kit:

1. Left double-click the self-extracting executable (SFX)  to install the DevKit artifacts into. For example, C:DevKit.

2. cd <DEVKIT_INSTALL_DIR>

3. ruby dk.rb init to generate the config.yml. Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present).

4. edit the generated config.yml file to include installed Rubies not automagically discovered or remove Rubies you do not want to use the DevKit with.

5. [optional] ruby dk.rb review to review the list of Rubies to be enhanced to use the DevKit and verify the changes you made to it are correct.

6 .Finally, ruby dk.rb install to DevKit enhance your installed Rubies. This step installs (or updates) an operating_system.rb file into the relevant directory needed to implement a RubyGems pre_install hook and a devkit.rb helper library file into <RUBY_INSTALL_DIR>librubysite_ruby

–ref: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

To install MySQL Connector/C:

1. Download MySQL Connector/C (http://www.mysql.com/downloads/connector/c/)

2. install it.

3. When installing mysql2 gem, provide the additional options (gem install mysql2 -v 0.2.10 — –with-mysql-include=”…” –with-mysql-lib=”…”)Provide for –with-mysql-include option the path to the includedirectory of MySQL Connector/C. The same for –with-mysql-lib but this time point to lib directory.

eg:  cmd> gem install mysql2 — ‘–with-mysql-lib=”C:Program FilesMySQLMySQL Connector C 6.0.2libopt” –with-mysql-include=”C:Program FilesMySQLMySQL Connector C 6.0.2include”‘

Permanent link to this article: https://blog.openshell.in/2013/03/mysql2-gem-for-windows-error/

What’s the difference between list, tuples and dictionaries in Python?

Lists

Lists are what they seem – a list of values. Each one of them is numbered, starting from zero – the first one is numbered zero, the second 1, the third 2, etc. You can remove values from the list, and add new values to the end.

Example: Your many cats’ names.

[code]
"A list"
cats = [‘Tom’, ‘Snappy’, ‘Kitty’, ‘Jessie’, ‘Chester’]
"If you want to print for example the first name on the list you would do the following"
print cats[0]
"Also if you want to add a name to the list you would do this"
cats.append(‘Catherine’)
"To remove a name you would do this"
del cats[0]
[/code]

Tuples

Tuples are just like lists, but you can’t change their values. The values that you give it first up, are the values that you are stuck with for the rest of the program. Again, each value is numbered starting from zero, for easy reference.

Example: the names of the months of the year.

[code]
"Here is an example of a tuple"
months = (‘January’,’February’,’March’,’April’,’May’,’June’,\
‘July’,’August’,’September’,’October’,’November’,’ December’)
[/code]

“So that’s the difference between lists and tuples. A list can be modified but a tuple cannot be modified in anyway(unless changed in the source code of the program)”

Dictionaries:

Dictionaries are similar to what their name suggests – a dictionary. In a dictionary, you have an ‘index’ of words, and for each of them a definition. In python, the word is called a ‘key’, and the definition a ‘value’. The values in a dictionary aren’t numbered – tare similar to what their name suggests – a dictionary. In a dictionary, you have an ‘index’ of words, and for each of them a definition. In python, the word is called a ‘key’, and the definition a ‘value’. The values in a dictionary aren’t numbered – they aren’t in any specific order, either – the key does the same thing. You can add, remove, and modify the values in dictionaries.

Example: telephone book.

[code]
"Here is a simple phonebook"
phonebook = {‘Andrew Parson’:8806336, \
‘Emily Everett’:6784346, ‘Peter Power’:7658344, \
‘Lewis Lame’:1122345}
"To add a name to the phonebook you would do the following"
phonebook[‘Gingerbread Man’] = 1234567
"If you want to remove a name you would do the same as you would do in a list"
del phonebook[‘Andrew Parson’]
[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/whats-the-difference-between-list-tuples-and-dictionaries-in-python/

Execute Shell file in linux server

chmod Command: Run Shell Script In Linux

Set an executable permission using the chmod command as follows:

[code]chmod +x file.sh[/code]

Now your can run your .sh file as follows:

Execute Shell Script Using . ./ (dot space dot slash)

[code]./file.sh[/code]

You can also execute a unix shell script by specifying the interpreter in the command line as shown below.
Execute using sh interpreter

[code]$ sh scriptfile[/code]

Execute using bash interpreter

[code]$ bash scriptfile[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/execute-shell-file-in-linux-server/