Installing the latest stable Nginx 0.7.6 regardless of the Nginx 0.6.3 by mod_rails defaults

written by mikhailov on June 20th, 2009 @ 04:18 PM

It's really cool, phusion.nl make my life a little bit easier, nginx with mod_rails can be installed in 2 steps:

gem install passenger
passenger-install-nginx-module
Not neccessary known about configure, make, install and other. Also you can use deb package in Ubuntu server case.

But, what's happen, guys, I want a latest nginx stable instead out-of-date 0.6 branch. So, I show you how I use two of version nginx (stable 0.6.3 by modrails defaults and latest 0.7.6). You can use one of them on the yours server.

mkdir ~/temp && cd ~/temp
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xzf ./pcre-7.9.tar.gz 

wget http://sysoev.ru/nginx/nginx-0.7.60.tar.gz
tar xzvf ./nginx-0.7.60.tar.gz
cd ~/temp/nginx-0.7.60
./configure --add-module=/opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/passenger-2.2.3/ext/nginx --with-pcre=~/temp/pcre-7.9 --prefix=/opt/nginx076
make
sudo make install
sudo cp /etc/init.d/nginx /etc/init.d/nginx076
sudo sed -i 's,/opt/nginx,/opt/nginx076,g' /etc/init.d/nginx076
sudo /etc/init.d/nginx076 start

That's all. You have a choise to use either aby of version of Nginx webserver.

jQuery beatiful code examples

written by mikhailov on May 22nd, 2009 @ 04:09 AM

I really like the semantics of jQuery, is fairly short and predictable.
Look at the code, it is not overloaded with ambiguous and unclear structures.
Like Ruby, the methods often returns a jQuery object, so you can create a chain of methods. I want to share the code that I wrote last night. If you are not familiar jQuery, so look over the code.

[Demo] [Source]


...

 
 $("#pics_hide").click(function(){
   $("#images div:first-child").animate({opacity: "0.1"}, 300, 
     function(){$(this).next().animate({opacity: "0.1"}, 
     arguments.callee);
     return false
     }
   );
 });  


 $("#pics_show").click(function(){
   $("#images div:last-child").animate({opacity: "1.0"}, 300, 
     function(){$(this).prev().animate({opacity:"1.0"}, 
     arguments.callee);
     return false
     }
   );
 });  


 $("#pics_move").hover(
   function(){
     $("#images div:even").hide("slow")
   }, 
   function(){ 
     $("#images div:even").show("slow")
   });

 $("#pics_reorder").click(function(){
   $("#images div:last-child")
     .insertBefore($("#images div:first-child"));
   $("#images div:even").animate({opacity: "0.4"}, 300);
   $("#images div:odd").animate({opacity: "1.0"}, 300);
 });  

 $("#pics_anim").click(function(){
  $("#images div:odd").animate({top: '-=20px'}, 300);
  $("#images div:even").animate({top: '+=20px'}, 300);
 });  

...

Installing the Ruby Enterprise Edition regardless of the preinstalled Ruby

written by mikhailov on May 6th, 2009 @ 05:22 AM

Honestly, no secret that RubyEE much more productive than standard Ruby. Many use it in conjunction with a passenger, that allows to achieve excellent results in the speed of the application, and in doing so to save memory. I'm going to tell about experience of myself. I have a vps with 360 megabytes of RAM, so launching more than 6 projects becomes difficult using mongrel or thin, as these processes are continuously running in memory, regardless of whether the load on the application or not. After I installed mod_rails, I noticed an interesting feature - if anyone application is not used, the process of unloaded from memory, respectively, releasing more memory for other projects loaded. It was a pleasant surprise for me.
In the other hand, ruby 1.8.6 (2008-08-11 patchlevel 287) is more preferable than ruby 1.8.7 (2008-08-11 patchlevel 72) and other.

So, let's go to install rubyee mod_rails. I want to give a small warning about the system's interpreter of ruby - no need to remove or recomiple from an older version (older repo), because your operating system has a hard dependency within allover packages, and the repository contains the required version of ruby. No need to touch system Ruby.

Let's start with the installation rubyee http://www.rubyenterpriseedition.com/download.html

You need to install some developers packages in Ubuntu case:
sudo apt-get install libssl-dev
sudo apt-get install libreadline5-dev

tar xzvf ruby-enterprise-X.X.X.tar.gz
./ruby-enterprise-X.X.X/installer

Ok, you have installed version RubyEE in the directory /opt/ruby-enterprise-1.8.6-20090421/bin/ruby
Make symbolic links

sudo ln -s /opt/ruby-enterprise-1.8.6-20090421 /opt/ruby_ee
sudo ln -s /opt/ruby_ee/bin/erb /usr/bin/erb_ee
sudo ln -s /opt/ruby_ee/bin/gem /usr/bin/gem_ee
sudo ln -s /opt/ruby_ee/bin/irb /usr/bin/irb_ee
sudo ln -s /opt/ruby_ee/bin/rails /usr/bin/rails_ee
sudo ln -s /opt/ruby_ee/bin/rake /usr/bin/rake_ee
sudo ln -s /opt/ruby_ee/bin/rdoc /usr/bin/rdoc_ee
sudo ln -s /opt/ruby_ee/bin/ri /usr/bin/ri_ee
sudo ln -s /opt/ruby_ee/bin/ruby /usr/bin/ruby_ee

Done! Now you have an independent Ruby interpreter, as well as the independent "gem", with its own set of plugins Try to check

ruby -v
ruby_ee -v
gem list
gem_ee list

ruby script/server
ruby_ee script/server

Have a joy with Ruby Enterprise Edition!

P.S. ruby_ee script/console is using "irb", so we should do some modifications:
vim /opt/ruby_ee/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/console.rb

irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb_ee'

Internet Explorer Free under Ubuntu Linux with VirtualBox

written by mikhailov on March 2nd, 2009 @ 05:12 AM

My job is web application development, so I have to test my projects under most popular browsers, like Firefox, Internet Explorer, Opera and Google Chrome.
Firefox, Opera, GoogleChrome work great under my Ubuntu Box, and the other once work under Wine.

*Internet Explorer*. It's pain to setup IE6 and IE7, because you can take a look of many bugs with render html and vml.

Just forget Wine for the purpose!
Microsoft give us FREE virtual PC images with IE6, IE7, IE8 aboard!
Don't you believe?

Internet Explorer Application Compatibility VPC Image
Brief Description
VPC Hard Disk Image for testing websites with different IE versions on Windows XP SP2, Windows XP SP3 and Windows Vista

IE6-XPSP3.exe 407.3 MB
IE7-VIS1.exe 700.0 MB
IE7-VIS2.rar 700.0 MB
IE7-VIS3.rar 590.5 MB
IE7-XPSP3.exe 512.0 MB
IE8RC1-XPSP3.exe 495.8 MB

Licence: Free.

www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en

www.microsoft.com/downloads/details.aspx?familyid=28C97D22-6EB8-4A09-A7F7-F6C7A1F000B5&displaylang=en

After you have file downloaded, just unrar it and add select VHD file extracted earliert to VirtualBox. link

This link might be helpful to install last VirtualBox for VHD image file using.

And special present to Daniel is "Intel Pro" network adapter driver package ISO image! Just attach the file as CD-Drive image and install the Intel Pro 1000 in 2 minutes.
Download

Amazon AWS EC2 RubyOnRails Rails-All-in-one

written by mikhailov on January 29th, 2009 @ 04:27 AM

As you may know, standard template “Amazon EC2 Rails-All-in-one-trial” by Amazon AWS is not good… yeap, it is. Let me show you how fix it by your hads :)

Let’s start. We have a useful EC2 based on CentOS 5.2. Great enterprise linux for the Rails application. But Ruby 1.8.5 on aboard, it’s deeply out-of-date…

http://rubyonrails.org/download We recommend Ruby 1.8.7 for use with Rails. Ruby 1.8.6, 1.8.5, 1.8.4 and 1.8.2 are still usable too, but version 1.8.3 is not.

Well, do you want to run Rails with old Ruby? If, you have 2 ways to get newer Ruby version:

  • Ruby Enterprise edition as additional package, who need to install from sources (http://www.rubyenterpriseedition.com/download.html). Telling the truth, feel free to install it, very easy.
  • Use extra repo to the CentOS who include good version of Ruby 1.8.6 (patch 111) and other dependent libraries http://www.centos.org/modules/newbb/viewtopic.php?topic_id=1182 or followed bash scrip

    #!/bin/bash -e
    
    cat<<EOF> /etc/yum.repos.d/ruby.repo
    [ruby]
    name=ruby
    baseurl=http://repo.premiumhelp.eu/ruby/
    gpgcheck=0
    enabled=0
    EOF
    
    yum update -y
    yum --enablerepo=ruby install ruby -y
    yum --enablerepo=ruby install ruby-mysql -y
    

Generate random password in Rails

written by mikhailov on January 6th, 2009 @ 11:17 AM

I am using Restful_authentication plugin for one of my projects.
As part of my user creation workflow, system should to generate a random password for the new user.
So, look at my password creation behaviour:

  • generate uncrypted password
  • send this with e-mail notification
  • crypt the password
<controller>
class CandidatesController < ApplicationController
  ...
  if @candidate.valid?
    candidate.save
    Notifier.deliver_inv(candidate.email, candidate.crypted_password)
    candidate.encrypt_password
  end
end

<model>
require 'digest/sha1'
class User < ActiveRecord::Base
  ...
  def encrypt_password
    self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{name}--")
    self.crypted_password = encrypt(self.crypted_password)
    save(false)
  end
  protected
    def save_password
      (self.crypted_password = password) unless self.crypted_password
    end
...
end

class Candidate < User
  # Callbacks:
  before_save :save_password
  before_validation_on_create Proc.new do |u|
    u.password = Array.new(12) { (rand(122-97) + 97).chr }.join
    u.password_confirmation = u.password
  end

end

Apache2 httpd improving performance mod_deflate gzip

written by mikhailov on December 16th, 2008 @ 07:31 AM

How often do you think about improving performance of Apache2 httpd web-server?
“It’s too slow”, “we need more powerfull server”, etc.
Telling the truth, default settings of Apache2 aren’t good and it’s best to try optimizing those first, before thinking of more advanced solutions.

Mod_deflate in apache2 is pretty much the same as mod_gzip in apache1.3, and mod_deflate is included with the apache2 source package. Both modules allow compressing of the apache server on the fly

So, I know, professinals from Amazon EC2 AMI have optimized apache configuration file. Let me show that to site.vhost

<VirtualHost *:80>
...
# Deflate
     AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
     BrowserMatch ^Mozilla/4 gzip-only-text/html
     BrowserMatch ^Mozilla/4.0[678] no-gzip
     BrowserMatch bMSIE !no-gzip !gzip-only-text/html
     DeflateCompressionLevel 9
     SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
...
</VirtualHost>

It’s simillar to nginx settings gzip_comp_level.
So, I have Apache2 httpd with great perfomance improvement with DeflateCompressionLevel.

Ubuntu 8.10 Downgrade Ruby 1.8.7 to 1.8.6

written by mikhailov on November 27th, 2008 @ 10:51 AM

As you may know Ruby 1.8.7 don't compatable with Rails(http://www.rubyonrails.org/down)
We recommend Ruby 1.8.6 for use with Rails. Ruby 1.8.7, 1.8.5, 1.8.4 and 1.8.2 are still usable too, but version 1.8.3 is not. Ruby 1.8.7 still has some bugs to straighten out.

Step-by-step to downgrade Ruby to 1.8.6

1) Replace /etc/apt/sources.list file with follow data:

# deb cdrom:[Ubuntu 7.10 _Gutsy Gibbon_ - Release i386 (20071016)]/ gutsy main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid main restricted
deb http://mirror.cs.umn.edu/ubuntu/ hardy main restricted
# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid main restricted
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-updates main restricted
deb http://mirror.cs.umn.edu/ubuntu/ hardy-updates main restricted

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-updates main restricted
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid universe
deb http://mirror.cs.umn.edu/ubuntu/ hardy universe

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid universe
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy universe

# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-updates universe
deb http://mirror.cs.umn.edu/ubuntu/ hardy-updates universe

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-updates universe
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid multiverse
deb http://mirror.cs.umn.edu/ubuntu/ hardy multiverse

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy multiverse
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid multiverse


# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-updates multiverse
deb http://mirror.cs.umn.edu/ubuntu/ hardy-updates multiverse

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-updates multiverse
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-backports main restricted universe multiverse
deb http://mirror.cs.umn.edu/ubuntu/ hardy-backports main restricted universe multiverse

deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-backports main restricted universe multiverse
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository. This software is not part of Ubuntu, but is
## offered by Canonical and the respective vendors as a service to Ubuntu
## users.
deb http://archive.canonical.com/ubuntu intrepid partner
deb http://archive.canonical.com/ubuntu hardy partner

deb-src http://archive.canonical.com/ubuntu intrepid partner
deb-src http://archive.canonical.com/ubuntu hardy partner

# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-security main restricted
deb http://mirror.cs.umn.edu/ubuntu/ hardy-security main restricted

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-security main restricted
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-security main restricted

# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-security universe
deb http://mirror.cs.umn.edu/ubuntu/ hardy-security universe

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-security universe
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-security universe

# Line commented out by installer because it failed to verify:
deb http://mirror.cs.umn.edu/ubuntu/ intrepid-security multiverse
deb http://mirror.cs.umn.edu/ubuntu/ hardy-security multiverse

# Line commented out by installer because it failed to verify:
deb-src http://mirror.cs.umn.edu/ubuntu/ intrepid-security multiverse
deb-src http://mirror.cs.umn.edu/ubuntu/ hardy-security multiverse

2) Create new file /etc/apt/preferences

Package: ruby
Pin: release a=hardy
Pin-Priority: 900

Package: ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: rdoc1.8
Pin: release a=hardy
Pin-Priority: 900

Package: ri1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libgtk2-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libdbd-sqlite3-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libopenssl-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libsqlite3-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: ruby1.8-dev
Pin: release a=hardy
Pin-Priority: 900

Package: libdbi-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libatk1-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libpango1-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libatk1-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libgdk-pixbuf2-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libglib2-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libcairo-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: irb1.8
Pin: release a=hardy
Pin-Priority: 900

Package: libreadline-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

Package: rails
Pin: release a=hardy
Pin-Priority: 900

Package: libncurses-ruby1.8
Pin: release a=hardy
Pin-Priority: 900

3) Open synaptic and find "ruby" relate packages (just search "ruby"). Check for completly removal installed packages (3-7 installed packages will be here)
4) sudo apt-get update
5) sudo apt-get install ruby rdoc irb libyaml-ruby libzlib-ruby ri libopenssl-ruby ruby1.8-dev build-essential

That's all :)

I use the article: http://sudan.ubuntuforums.com/showthread.php?t=964978

Ubuntu 8.10 PPPoE setup

written by mikhailov on November 20th, 2008 @ 07:33 PM

As you may know not all the network parts have installed in Ubuntu by default, e.g PPPoE. While I'm searching for a solution to the problem (PPPoE with Ubuntu Linux) I have found short article about it. Secret is here:

Why develop using Ruby on Rails

written by mikhailov on November 20th, 2008 @ 01:09 PM

Put the fun back into the creative process of application creation with Ruby on Rails. Here are just a few reasons developers are making the move:

Less learning curve

  • Ruby uses a natural language syntax
  • One framework to use, stressing convention over configuration
  • Rapidly increasing availability of resources
  • Growing community of developers
  • More books published every month

Higher productivity

  • Less code creating more functionality
  • Less accidental complexity

Built-in testing

  • Generate basic tests along with scaffolding

Something for everybody

  • You don't have to be an expert or learn a bunch of frameworks in order to begin
  • Full OOP for experienced developers
  • More advanced techniques are available for advanced developers

Rapid feedback

  • No compiling, just a quick browser refresh

Rapid prototyping

    o Show em faster
see more: http://www.railsforall.org/info/why_develop_using_ruby_on_rails

RailsRumble

written by mikhailov on October 20th, 2008 @ 10:43 AM

I was very happy to participate in RailsRumble last weekend.
We developed Rdocker project, which makes rdoc browsing of favorite ruby projects less painful.

Rdocker - Personalized RDoc browser and Gem server

me and Dekart
Please check this out http://vote.railsrumble.com/entries?page=4

Custom Search