Saturday, 29 September 2012

How to kill Skype process in Ubuntu


How to kill Skype process in Ubuntu

The Skype process seems to be immortal when it crashes in Ubuntu. Killing it with “killall skype” does not work. And it’s not a nice process either, because it uses 100% CPU!

Fortunately, there is a way of killing it without restarting your computer. This is how to do it:

$ killall skype -s 9


and you can start skype form terminal using skype -i

Friday, 21 September 2012

Focusing first elemet in the form using jquery



Focusing first element in the form using jQuery

                $("form:not(.filter) :input:visible:enabled:first").focus();

Thursday, 20 September 2012

Installing Ruby on Rails Ubuntu 11.10


Installing Ruby on Rails Ubuntu 11.10 using RVM and Ruby 1.9.2

Follow:
sudo apt-get update
sudo apt-get install build-essential git-core curl libmysqlclient16-dev nodejs
Now let’s install the latest version of RVM using curl:
sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
umask g+w
source /etc/profile.d/rvm.sh 
Now you'll need to ask RVM if it needs any more programs and if so you'll need to install them to do this type:
rvm requirements
Two things could happen here if you see the following message saying you need to install 'rvm', ignore this it and restart your terminal, this should fix the problem.
The program 'rvm' is currently not installed.  You can install it by typing:
sudo apt-get install ruby-rvm
You should see something that looks like this after you restart your terminal:
This tells you which packages you need to install using apt-get, just copy and paste the apt-get section under "# ForRuby" and run using the sudo command, this should look something like this:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
Now you just need to give the user account access to the rvm files, you do this with the following command substituting [user] for the user you wish to use
sudo chown -R [user]:[user] /usr/local/rvm
Once you have installed all these packages its time to install Ruby 1.9.2 herself. The following command will installRuby 1.9.2 using the rmv package. However this can take a few minutes (15 in my case) to install so I recommend getting a drink, or my favourite, a pizza :lol: .
rvm install 1.9.2
Once ruby is installed you should set Ruby 1.9.2 as your default Ruby version, to do this enter:
source "/usr/local/rvm/scripts/rvm"
rvm --default use 1.9.2
You can test that Ruby is installed correctly and running at version 1.9.2 by typing
ruby -v

The nice thing about RVM is you can use it to install any version of Ruby and switch between the versions your have installed, to do this just enter "rvm install [Version Number]" then "rvm --default use [Version Number", you can then use "rvm --default use" to change to any installed version.This should output something like "ruby 1.9.2p290.." showing you that version 1.9.2p290 is installed and is now the defaultRuby version.
Now that you have the latest version of ruby installed I’m sure you want to get the latest version of Rails installed, at the time of writing this tutorial that’s Rails 3.1. To installRails we can use GEM which is installed along with RVM and Ruby, to install the latest version of Rails just type, (this can take also take a while):
gem install rails
And that’s it you have now installed RVMRuby 1.9.2 and Rails 3.1 on Ubuntu 11.10 configured to use sqlite3, you can now setup your new Rails package with
rails new [project name]
Just as a final note, If you want to use MySQL instead of sqlite3 you’ll need to enter the following
sudo apt-get install mysql-server
gem install mysql2
rails new [project name] -d mysql

Tuesday, 18 September 2012

Haml important things to remember


How to Convert

Let’s basic ERB that we want to convert.

ERB

<strong><%= item.title %></strong>

Haml

%strong= item.title
In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong%div%body%html; any tag you want. Then, after the name of the tag is =, which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag. Unlike the ERB above, Haml will automatically detect newlines in the return value and format the tag properly.
Simple tags are all well and good, but what about adding attributes to tags?

HTML

<strong class="code" id="message">Hello, World!</strong>

Haml

%strong{:class => "code", :id => "message"} Hello, World!
The attributes are just a standard Ruby hash. The class attribute is “code”, the id attribute is “message”. Notice that in this example, we didn’t use =, so “Hello, World!” is interpreted as a normal string, not Ruby code.
There is a simpler way to define this tag in Haml, since class and id are such common attributes and since most designers (and coders) are familiar with CSS, we can use similar notation to describe this tag.

Haml

%strong.code#message Hello, World!
Not only that, but since div tags are so common, you can leave off the tag definition and have it default to %div.

Haml

.content Hello, World!

HTML

<div class='content'>Hello, World!</div>
Now what about something a little more complicated?

ERB

<div class='item' id='item<%= item.id %>'>
  <%= item.body %>
</div>
Pretty basic. This might be part of a partial or something. Let’s convert it to Haml.

Haml

.item{:id => "item#{item.id}"}= item.body

Now, nesting is taken care of in Haml via whitespace.

ERB

<div id='content'>
  <div class='left column'>
    <h2>Welcome to our site!</h2>
    <p><%= print_information %></p>
  </div>
  <div class="right column">
    <%= render :partial => "sidebar" %>
  </div>
</div>

Haml

#content
  .left.column
    %h2 Welcome to our site!
    %p= print_information
  .right.column
    = render :partial => "sidebar"
Thats it... :)

Thursday, 13 September 2012

Go to top of page using jQuery

This one liner jQuery snippet will force your browser to go to the top of your page:

$('html, body').animate({ scrollTop: 0 }, 0);

If you want to add some smooth scrolling:
$('html, body').animate({ scrollTop: 0 }, 'slow');

Here is the one where i used when he resets, i am making this

%input.btnCancel{:type => "reset", :value => "Reset without saving", :id => "reset"}

 $('#reset').click(function() {
    $('html, body').animate({ scrollTop: 0 }, 0);
    location.reload().scrollTop(0);
  });