Programming, science, engineering, and more…
RSS icon Home icon English Spanish
  • Rails 3.1.0

    Posted on {31-Aug-2011} Frank Vielma No comments

    Recently, the rails 3.1.0 is now a release version.

    It is recommendable to use rvm (you need to install rvm) creating a new gemset so, we can isolate the install from the rest of our environments. We need the follow steps:

    • Creating a gemset:
      rvm --create 1.9.2-p180@rails31
    • Installing the last rails version (3.1.0) :
    • gem install rails
    • To generate a new project:
    • rails new project31
    • Adding the following lines to the Gemfile file
    • gem 'execjs'
      gem 'therubyracer'

      ExecJS. Run JavaScript code from Ruby.
      therubyracer. Embed the V8 Javascript Interpreter into Ruby.

    • Running bundle:
    • bundle install
    • Starting the new rails application:
    • rails s

    After it, we would see the following lines:

    => Booting WEBrick
    => Rails 3.1.0 application starting in development on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    [2011-08-31 09:39:29] INFO  WEBrick 1.3.1
    [2011-08-31 09:39:29] INFO  ruby 1.9.2 (2011-02-18) [i686-linux]
    [2011-08-31 09:39:29] INFO  WEBrick::HTTPServer#start: pid=11130 port=3000

    Release notes
    Rails 3.1 sources

  • Installing MongoDB and php driver in Ubuntu 10.10

    Posted on {10-May-2011} Frank Vielma No comments

    MongoDB is a NoSQL (“not only sql”), a non-relational, distributed, open-source, horizontal scalable and document-oriented database written in the C++. It doesn’t have transactions, ACID compliance, joins, foreign keys, or many of the other features belonging to relational database management system (RDBMS). The database is document-oriented so it manages collections of JSON-like documents.

    One of the most important feature is than MongoDB scaling very well.

    Installation.

    • Step 1. Adding the ubuntu repository:
      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

      add at the end of the /etc/apt/sources.list file:

      deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
    • Step 2. Installing mongodb
       sudo aptitude update && sudo aptitude install mongodb-10gen
    • Step 3. Verifying installation:
      mongo --version
      MongoDB shell version: 1.8.1
    • Step 3. Now, we will installing the PHP driver:
      sudo aptitude install php5-dev php5-cli php-pear && sudo pecl install mongo

      add the dynamic library mongo.so at the end of the php.ini (/etc/php5/apache2/php.ini) file:

      extension=mongo.so
    • Step 4. Restart apache and verify if all is ok running the phpinfo() function:
      sudo /etc/init.d/apache2 restart

    mongodb

    More info

  • Installing RVM on Ubuntu maverick

    Posted on {29-Apr-2011} Frank Vielma No comments

    In first place, what is RVM ?
    RVM is the Ruby Version Manager. It makes installing and managing several different versions and implementations of Ruby on one computer.

    Installation.
    There are two ways to install and configure RVM.

    • As a standard user
    • As root

    In this post we will do the first one.

    In first time, you will need to install zlib and others.

    Debian/Ubuntu systems:

    sudo apt-get install zlib1g-dev zlib1g libssl-dev libreadline5-dev libxml2-dev libsqlite3-dev
    • Step 1. Download and install rvm from sources. It will install in $HOME/.rvm. (You must have installed curl and git)
      bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    • Step 2. Now, we will complete the install by loading RVM in new shells adding the following line in a $HOME/.bashrc file.
      [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    • Step 3.Open a new shell or run:
      source $HOME/.bashrc
    • Step 4.Test if the RVM’s installation is working.
      type rvm | head -1

      and you should get:

      rvm is a function

    Now, assuming that all is working, we could install ruby 1.9.2 as following:

    rvm install 1.9.2

    We can use ruby 1.9.2 in our system running only:

    rvm use 1.9.2

    so, we can verify what ruby’s version is running right now:

    which ruby

    you get:

    $HOME/.rvm/rubies/ruby-1.9.2-p180/bin/ruby

    But, if we want to return to the initial conditions ? No problem, you need only to run:

    rvm system

    it will return to the ruby’s system (ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux])

  • How to use a local gem repository.

    Posted on {07-Mar-2011} Frank Vielma No comments

    gem uses the configuration file .gemrc in your $HOME directory. If there is an user isn’t able to install gems into the standard system location, is possible to use a local gem repository. The simple way is to create a $HOME/.gemrc file with the following:

    gemhome: /home/username/.gem/ruby/1.8/
    gempath:
        - /home/username/.gem/ruby/1.8/
        - /usr/lib/ruby/1.8/rubygems/

    This file has a YAML format.

  • Force rails version when creating a new project

    Posted on {22-Feb-2011} Frank Vielma No comments

    Using the following if you want to install rails 2.3.8:

    rails _2.3.8_ newproject

  • Getting user agent from javascript

    Posted on {18-Feb-2011} Frank Vielma No comments
    We can get the user agent as following:
    1
    2
    3
    
    <script type="text/javascript">
        alert(navigator.userAgent);
    </script>
  • Installing ruby-debug

    Posted on {13-Feb-2011} Frank Vielma No comments

    Beofore to install ruby-debug, you need to install the following (Ubuntu 10.4, 10.10):

    • sudo aptitude install ruby1.8-dev
      • (Header files for compiling extension modules for the Ruby 1.8)
    • sudo gem install ruby-debug-base
    • sudo gem install ruby-debug
best web hosting