Sunday, August 2, 2015

SOLID Principle

S for Single responsibility principle

Note 
       
class Order < ActiveRecord::Base

	def self.find_purchased

	# ...

	end

	def self.find_waiting_for_review

	# ...

	end



	def self.find_waiting_for_sign_off

	# ...

	end



	def self.find_waiting_for_sign_off

	# ...

	end

	def self.advanced_search(fields, options = {})

		def self.simple_search(terms)

    end


	def to_xml

	# ...

	end



	def to_json

	# ...

	end



	def to_csv

	# ...

	end



	def to_pdf

	# ...

	end

# ...

end
      
 

O for Open closed principle which means , a class should be close for modification and open for extension

Example:

       
class Purchase

	def initialize(payment_process)

		@payment_process = payment_process

	end

	def charge_user!

		@payment_process.charge(user: user, amount: amount)

	end

end



Purchase.new(MachPayAdapter).charge_user!





class Stripe

	def charge(user,amount)

	end

end



class Paypal

	def charge(user,amount)

	end

	

end



class MachPay

 def charge_amount(amount,user)

 end

	end



class MachPayAdapter



  def charge(user,amount)

  	MachPay.charge_amount(amount,user)

  end

end



    
 

Sunday, April 13, 2014

Ruby on rails-The first application

rails new first_app
cd first_app/

Update Gemfile with an explicit version for each Ruby gem. 
************************************** 
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.4'

group :development do
  gem 'sqlite3', '1.3.8'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end
*************************************** 
$ bundle update
$ bundle install
$ rails server

So far So good :):)

Git for version control

To install Git, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv.

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
 libz-dev libssl-dev
$ apt-get install git
$ git config --global user.name "Your Name"
$ git config --global user.email your.email@example.com

Setup repository

$ git init
Rails command creates a default .gitignore file in the application root directory, causing Git to ignore file mention inside it.

$ git add .      
# dot ‘.’ represents the current directory, and Git is smart enough to add the files recursively,So it automatically includes all the subdirectories.It adds the project files to a staging area, which contains pending changes to your project;
$ git status      
# see which files are in the staging area using this command.
$ git commit -m "Initialize repository" 

# Tells Git you want to keep the changes.
$ git log 

# See a list of your commit messages ,To exit git log, you may have to type q to quit.

Generate SSH Key
https://help.github.com/articles/generating-ssh-keys

GitHub

$ git remote add origin https://github.com//first_app.git
$ git push -u origin master
# Tells Git that you want to add GitHub as the origin for your main (master) branch and then push your repository up to GitHub.

Deployment

Lets use Heroku, a cloud deployment service.
Heroku uses the PostgreSQL database, which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres.

A Gemfile with added gems and explicit Ruby version:

******************************** 
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.4'

group :development do
  gem 'sqlite3', '1.3.8'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end
*******************************
 
$ bundle install --without production 

The --without production option prevents the local installation of any production gems, which in this case consists of pg and rails_12factor.

$ git commit -a -m "Update Gemfile.lock for Heroku"
 
Create and configure a new Heroku account.
Install heroku:  https://toolbelt.heroku.com/debian.
Upload your public key to Heroku.


$heroku keys:add ~/.ssh/id_rsa.pub

If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:

$ heroku keys:add
$ heroku logs

Running the logs 'heroku logs', has a key giveaway: PG::Error: ERROR: relation "" does not exist. This entry states your model could not be loaded. To provide an update to previous answers, heroku rake has been deprecated. Heroku requires:

$ heroku run rake db:migrate




$ heroku login
 
 
Navigate back to your Rails project directory and use the heroku command to create a place on the Heroku servers for the sample app to live.
$ cd ~/rails_projects/first_app
$ heroku create

$ git push heroku master
$ heroku open 

Thursday, April 10, 2014

Ubuntu 12.04 tips

1. Enable super user account password on Ubuntu

$ sudo passwd root
[sudo] password for :
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

With with the new password you can login as super user with su command

2. For anyone also wanting to liberate their system, this is one of the solution

load the Terminal
type: sudo passwd root
input your user's password when prompted
create UNIX password when prompted
type: sudo sh -c 'echo "greeter-show-manual-login=true" >> /etc/lightdm/lightdm.conf'
reboot the system
At the login screen there is now an option to login manually.

3. To install skype:

sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"
sudo apt-get update
sudo apt-get install skype

4. To see hidden files in the particular directory, Press Ctrl + H.
5. To install chrome using  deb package:

sudo dpkg -i google-chrome-stable_current_i386.deb
google-chrome-stable : to open the chrome.

6. To change the ownership of all files and directories inside of directory and directory itself:
groups //to get the user group
sudo chown -R username:group directory

7. Install sqlite browser

Go to development.sqlite3 {file with .sqlite3} extension. Right click the file. Select open with other application. Select  search from internet to find the applicable software.System will search for SQLiteman.   Install SQLiteman.
 
 
 
8.  command to kill process running in  ror localhost 3000 .
    lfos| grep 3000
    kill -9 5252 [ex]


Sunday, July 25, 2010

In Ubuntu 9.04 Beta on a Dell Vostro 1320 I get no sound recorded.

References: http://ubuntuforums.org/showthread.php?p=6589810

BACKGROUND:

The audio functionality of any computer system belongs to the very basic functions of a PC and OS. No sound, poor sound, limited functionality - No use for such a system!

The main idea behind upgrading ALSA with attached script is to make Linux available to a slightly wider community.

The script bridges the huge delay (up to a year) of Alsa updates supplied through the official channels.
By running the upgrade you'll have a much bigger chance to get your soundcard working or problems resolved.

The script installs the latest official stable ALSA release. (optional the even more up 2 date driver snapshot will be installed)

Upgraded packages

Alsa 1.0.23 (stabil)

See: Changelog Alsa 1.0.23

DRIVER=alsa-driver-1.0.23
FIRMWARE=alsa-firmware-1.0.23
LIB=alsa-lib-1.0.23
PLUGINS=alsa-plugins-1.0.23
UTILS=alsa-utils-1.0.23
TOOLS=alsa-tools-1.0.23
OSS=alsa-oss-1.0.17

Supported kernels: 2.6.24/26/27/28/29/30/31/32 family (including rt-kernel & NON-Ubuntu ZEN-rt-kernel)

Note: The restore currently does not not work on custom kernels!

UPGRADE:

The script is not in line with Debian/Ubuntu rules for package handling. It just overwrites existing files.
You won't see any changes on the ALSA package-ids within Synaptic!

The script recognizes severe problems during the installation and will stop automatically. It shouldn't mess up your setup.
If the script stops with an error-message nothing should have been touched!

In the worst case scenario the -r restore option restores your old system status as good as possible. It'll reinstall kernel, kernel-headers and Alsa related packages.

Ubuntu upgrades/updates might overwrite your Alsa installation once in a while (e.g. Major upgrades, kernel-upgrades or ALSA-package upgrades).
You just need to rerun the upgrade-script using the -i option in this case (if you still have the compiled sources on the disk).

Disclaimer: I won't take any responsibility for mess-ups caused by using the script! -- Of course - I do my best to avoid these and support you as much as I can.

As usual - Make a backup first! - A restore will just take 5 minutes with rsync. That might save you hours of troubleshooting and frustration .

Please consider that I rely on your support to improve the script and really appreciate your involvement.



Short Alsa-Upgrade script install instructions:

1. download the script and save it somewhere
2. cd
3. tar xvf AlsaUpgrade-1.0.23-2.tar
4. sudo ./AlsaUpgrade-1.0.23-2.sh -d
5. sudo ./AlsaUpgrade-1.0.23-2.sh -c
6. sudo ./AlsaUpgrade-1.0.23-2.sh -i
7. sudo shutdown -r 0

Logging: I recommend to log all the upgrade steps, e.g.

script -a -c "./AlsaUpgrade-1.0.23-2.sh -d" /tmp/Alsa_1.0.23-2_upgrade_download.log

You'll find a log file /tmp/Alsa_1.0.23-2_upgrade_download.log as soon as the script is finished.
You need to run this procedure for every single step. Choose whatever logfile names.

Test and Troubleshooting

After reboot you can type:

cat /proc/asound/version

This will let you know if you're running the new version.


The easiest and most reliable test to verify if Alsa is working is "aplay" - the Alsa player application. If aplay won't work -- nothing else will work.

Make sure that all your channels are unmuted and volume is up!

Type in a terminal:
$ aplay -l
(This won't work on e.g. webcams with a microphone only. Here you need to do a $cat /proc/asound/cards to see if it is there"

If you see your soundcards, you're almost there.

To test your first (default-index 0 X=0) soundcard, type e.g.:
$ aplay -Dplughw:X,0 -fcd //.wav
or e.g.
$ speaker-test -Dplughw:X,0 -c2
replace the X with the index of your soundcard index , which you find out by typing "aplay -l" - look for "card X"

Multichannel you can test the following way:
1. Type $aplay -L to find out about your pcm device . e.g "surround51"
2. Type $speaker-test -D surround51 -c6
Note: If the channel mapping should be wrong you need to adjust it in .asoundrc

Before reporting "NO SOUND" problems - check if your alsamixer-channels are activated and unmuted (gnome-mixer/volume-control/preferences)!!
Very often there are headphone-jack, Toslink, SPDIF or microphone issues reported. Usually this has something to do with wrong alsamixer settings or more seldom with a wrong model-id assigned to your sound-driver in /etc/modprobe.d/alsa-base.conf .
If you're lacking certain controls in alsamixer or your driver is not even being loaded, you should check-out your model-id in attached HD-Audio-Models.txt.
I strongly recommend to try similar model-id's matching your codec to checkout if your faulty function gets working.
I'd guess 80% of the reported problems (group: other than alsamixer issues) over here are related to the model setting in alsa-base.

Howto:
1. sudo gedit /etc/modprobe.d/alsa-base.conf

2. Look for:
options snd-hda-intel index=-2
3. Lookup your model in HD-Audio-Models.txt and change entry accordingly:
options snd-hda-intel index=-2 model=XXXXX
4. Save & Exit & Reboot

Please also have a look at these sides for further help:

http://ubuntuforums.org/showthread.php?t=843012
https://help.ubuntu.com/community/SoundTroubleshooting




Bookmark and Share

Thursday, March 25, 2010

How to restore Grub from a live Ubuntu cd.

EDIT: I have not been around in a long time, but it appears grub can still give people headaches I notice people are still referring to this guide now and then, so I wanted to post a link to a grub2 guide. There are differences so you may want to check there as well http://ubuntuforums.org/showthread.php?t=1195275. Glad to see Ubuntu is still going strong Take care.

This will restore grub if you already had grub installed but lost it to a windows install or some other occurence that erased/changed your MBR so that grub no longer appears at start up or it returns an error.

(This how to is written for Ubuntu but should work on other systems. The only thing to take note of, when you see "sudo" that will mean to you that the following command should be entered at a root terminal.)

Boot into the live Ubuntu cd. This can be the live installer cd or the older live session Ubuntu cds.

When you get to the desktop open a terminal and enter. (I am going to give you the commands and then I will explain them later)

Code:
sudo grub
This will get you a "grub>" prompt (i.e. the grub shell). At grub>. enter these commands

Code:
find /boot/grub/stage1
This will return a location. If you have more than one, select the installation that you want to provide the grub files.
Next, THIS IS IMPORTANT, whatever was returned for the find command use it in the next line (you are still at grub>. when you enter the next 3 commands)

Code:
root (hd?,?)
Again use the value from the find command i.e. if find returned (hd0,1) then you would enter root (hd0,1)

Next enter the command to install grub to the mbr

Code:
setup (hd0)
Finally exit the grub shell
Code:
quit
That is it. Grub will be installed to the mbr.
When you reboot, you will have the grub menu at startup.

Now the explanation.
Sudo grub gets you the grub shell.
Find /boot/grub/stage1 has grub locate the file stage1. What this does is tell us where grub's files are. Only a small part of grub is located on the mbr, the rest of grub is in your boot folder. Grub needs those files to run the setup. So you find the files and then you tell grub where to locate the files it will need for setup.
So root (hd?,?) tells grub it's files are on that partition.
Finally setup (hd0) tells grub to setup on hd0. When you give grub the parameter hd0 with no following value for a partition, grub will use the mbr. hd0 is the grub label for the first drive's mbr.
Quit will exit you from the grub shell.

Reference: http://ubuntuforums.org/showthread.php?t=224351

Tuesday, February 23, 2010

Enable InnoDB as MySQL Engine on Windows

1. Shut down your MySQL server (stop the service)
2. Open my.ini (mysql's config file), which is located in your MySQL program folder.
3. In my.ini, find:
 skip-innodb
4. Replace this line with:
 # skip-innodb
5. Save the file
6. Start the MySQL server again

Saturday, December 19, 2009

december 19

Today is a 3rd day i was back from cambodai. I still have vacation for next 20 days so not any regular task to be done.
I wake up late in the morning and........