Ubuntu + ROR + Mysql + Svn +VPN

Every time we install Ruby/Rails/Mysql/Rmagick/Vpn on Ubuntu Gutsy or Hardy we face the same  errors again and again. Lets reduce the installation time and have a loop-back-fix-free or smooth installation experience.

After you run the CD or install Ubuntu, make sure of your Network Proxies if any, if so, you need to add the proxy url at System->preferences->Network Proxy.

then from terminal, make sure this passes…

sudo apt-get update

then for Mysql/Rails installation follow this:

http://articles.slicehost.com/2007/11/23/ubuntu-gutsy-mysql-and-ror

and for VPN installation/connection on Ubuntu, this is the best guide:

http://www.cs.umn.edu/help/offsite/vpn.php#ubuntu_config

The Hidden Treasure

 All thats nice, sweet and makes one happy is a treasure. And if anything of that sort is hidden is called the Hidden Treasure I mean… what you say?

Well, I am talking about “My fav. singer” and thats the talent of my best buddy thats hidden..

JRuby on Rails in Glassfish V3

Yesterday it happened to come across an article on ”Mingle: A Rails based enterprise product” by Thoughtworks Studio.

They have used Jruby on Rails for many reasons, which made me even more curious to browse around and know on it more and more but comprises three main points…

>  Invoking Java code from Ruby

>  Or Java libraries can be used with Ruby syntax

> Deploy Rails apps on Java app servers via WAR files

(thereby the rails app can be your desktop application avoiding to create a seperate desktop app) 

The idea is seriously damn cool…

Common Query: What does Engineering doing in Software Engineering?

Writing code or set of programs result into ”Software products” that are generic or customized according to the customer specifications. Now whats this Engineering doing out here? This is a quite common query…

Engineering in general terms mean “The application of Science to the design, building and use of  machines, constructions etc.”

Composing the both… the definition of Software Engineering results into

“The art,craft and science of building large and important software systems. It is an amalgam of artistry, craftsmanship and scientific thought”

SE

Process Tool

The reason why the projects are categorized into large, medium, small, and very small is that they need to follow different processes for development.  

  Small and Very Small projects should follow only Waterfall Model, whereas Medium size projects follow either Waterfall or Iterative model. Lastly, Large projects follow either Waterfall or Iterative or Incremental model.

Therefore a large project and a very small project cannot follow the same steps while executing deliveries.    To keep a large project on track, one needs to have substantial processes in place, whereas having few processes leads to the risk of unmanaged processes, which may lead to failure.    Whereas, for a small project, having a huge process makes it a tedious and unnecessary overhead.     

Process

Install IE6 on Ubuntu

Many of them would be knowing this before… But thanks to the reference site which am able to do the same…

http://www.ubuntugeek.com/running-internet-explorer-in-ubuntu-linux.html

IEs4Linux is the simpler way to have Microsoft Internet Explorer running on Linux (or any OS running Wine).

No clicks needed. No boring setup processes. No Wine complications. Just one easy script and you’ll get three IE versions to test your Sites. And it’s free and open source.This may be very helpful for software developers and web developers to test their applications.

IEs4Linux Installation in Ubuntu

You have to enable universe packages first. It is also recommended that you use the official winehq ubuntu package:

Open /etc/apt/sources.list file

sudo gedit /etc/apt/sources.list

Uncomment following lines in your /etc/apt/sources.list and it may be different if you are in different country instead of UK

For Ubuntu Dapper Users

deb http://uk.archive.ubuntu.com/ubuntu dapper universe
deb-src http://uk.archive.ubuntu.com/ubuntu dapper universe

For Ubuntu Edgy Eft Users

deb http://uk.archive.ubuntu.com/ubuntu edgy universe
deb-src http://uk.archive.ubuntu.com/ubuntu edgy universe

Add WineHQ APT Repository

or

If you want to add source packages from the repository

Currently, wine only have i386 binary packages available. If you do not use an i386 architecture, or wish to compile the package in a special or optimized way, you can build the wine package using the source repository instead. To do this, add a source repository with one of the following:

For Ubuntu Dapper Users

deb http://wine.budgetdedicated.com/apt dapper main
deb-src http://wine.budgetdedicated.com/apt dapper main

For Ubuntu Edgy Eft Users

deb http://wine.budgetdedicated.com/apt edgy main
deb-src http://wine.budgetdedicated.com/apt edgy main

Close gedit and run an update to take your new Repository

sudo apt-get update

Install wine and cabextract

sudo apt-get install wine cabextract

Now you need to download IEs4Linux script from here

wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-2.0.5.tar.gz

tar xzvf ies4linux-2.0.5.tar.gz

cd ies4linux-2.0.5

Once you are inside ies4linux-2.0.5 directory you need to run the following script to install internet explorer

./ies4linux

This will install the internet explore in your machine.

To run IE you need to run the following command and it may be different for others this path at the end of installation it will give from where you want to run

/root/bin/ie6

You should see the Internet explorer opening

If try to run /root/bin/ie6 as root user you will get the following error messages so you need to run as user#/root/bin/ie6
fixme:actctx:CreateActCtxW stub!
err:imagelist:ImageList_ReplaceIcon no color!
err:imagelist:ImageList_ReplaceIcon no color!
err:imagelist:ImageList_ReplaceIcon no color!
err:imagelist:ImageList_ReplaceIcon no color!
Application tries to create a window, but no driver could be loaded.
Make sure that your X server is running and that $DISPLAY is set correctly.

If you want to check more information about this script check here

O’ Shiny Bubble !

O Shiny bubble in the eye…

do not cry !

Why feel for the ears that dont hear…

reach out your voice to the ones who’s dear !

Why feel for the things that dont happen…

reach out to them who needs you to make it happen !

Decide O shiny bubble… pain or smile…

whichever way, accept the fact O shiny bubble…

that you need to travel far mile after mile !

ROR : Important Points to be noted

> Difference between Ruby load and require:

Ruby programs may be broken up into multiple files, and the most natural way to partition a program is to place each nontrivial class or module into a separate file. These separate files can then be reassembled into a single program (and, if well-designed, can be reused by other programs) using require or load. These are global functions defined in Kernel, but are used like language keywords. The same require method is also used for loading files from the standard library.

load and require serve similar purposes, though require is much more commonly used than load. Both functions can load and execute a specified file of Ruby source code. If the file to load is specified with an absolute path, or is relative to ~ (the user’s home directory), then that specific file is loaded. Usually, however, the file is specified as a relative path, and load and require search for it relative to the directories of Ruby’s load path (details on the load path appear below).

Despite these overall similarities, there are important differences between load and require:

  • In addition to loading source code, require can also load binary extensions to Ruby. Binary extensions are, of course, implementation-dependent, but in C-based implementations, they typically take the form of shared library files with extensions like .so or .dll.

  • load expects a complete filename including an extension. require is usually passed a library name, with no extension, rather than a filename. In that case, it searches for a file that has the library name as its base name and an appropriate source or native library extension. If a directory contains both an .rb source file and a binary extension file, require will load the source file instead of the binary file.

  • load can load the same file multiple times. require tries to prevent multiple loads of the same file. (require can be fooled, however, if you use two different, but equivalent, paths to the same library file. In Ruby 1.9, require expands relative paths to absolute paths, which makes it somewhat harder to fool.) require keeps track of the files that have been loaded by appending them to the global array $" (also known as $LOADED_FEATURES). load does not do this.

  • load loads the specified file at the current $SAFE level. require loads the specified library with $SAFE set to 0, even if the code that called require has a higher value for that variable.

> To revert migrations to different version:

rake db:migrate version=19

> Task to delete all migration during deployment:

The delete command is just a convenience for executing rm via run. It just attempts to do an rm -f (note the -f! Use with caution!) on the remote server(s), for the named file. To do a recursive delete, pass :recursive => true:

Demonstrating delete [ruby]

delete #{release_path}/db/migrate“, :recursive => true

 

 

Difference between Mocks and Stubs

  • Many developers confuse the ideas behind stubbing and mocking. Stubbing simply replaces a real-world implementation with a simpler implementation. A stub can replace full login system with a simple substitute. A stub’s job is to simulate the real world. Mocks are not stubs. A mock object, instead, is like a gauge that measures the way your application uses an interface.
  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it ‘sent’, or maybe only how many messages it ‘sent’.
  • Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

Rspec Definitions for Mock and Stubs:Mocks are objects that allow you to set and verify expectations. They are very useful for specifying how the subject of the spec interacts with its collaborators. This approach is widely known as “interaction testing”.Mocks are also very powerful (though less widely understood) as a design tool. As you are driving the implementation of a given class, Mocks provide an amorphous collaborator that can change in behaviour as quickly as you can write an expectation in your spec. These changes are tantamount to designing the interface to a collaborator that often does not yet exist. As the shape of the class being specified becomes more clear, so do the requirements for its collaborators – often leading to the discovery of new types that are needed in your system.
Stubs are objects that allow you to set “stub” responses to messages. Stubs provide canned responses to messages they might receive in a test, while mocks allow you to specify and, subsquently, verify that certain messages should be received during the execution of a test.

Single Table Inheritance

Active Record allows inheritance by storing the name of the class in a column that by default is named “type” (can be changed by overwriting Base.inheritance_column). This means that an inheritance looking like this:

  class Company < ActiveRecord::Base; end
  class Firm < Company; end
  class Client < Company; end
  class PriorityClient < Client; end

When you do Firm.create(:name => “37signals”), this record will be saved in the companies table with type = “Firm”. You can then fetch this row again using Company.find(:first, “name = ‘37signals’”) and it will return a Firm object.

If you don‘t have a type column defined in your table, single-table inheritance won‘t be triggered. In that case, it‘ll work just like normal subclasses with no special magic for differentiating between them or reloading the right type with find.

Note, all the attributes for all the cases are kept in the same table. Another example is as follows:

STI
Relational databases don’t support inheritance, so when mapping from objects to databases we have to consider how to represent our nice inheritance struc-tures in relational tables. When mapping to a relational database, we try to minimize the joins that can quickly mount up when processing an inheritance structure in multiple tables. Single Table Inheritance maps all fields of all classes of an inheritance structure into a single table.


The “remembered” three fishes story…

Instead of using the word “unforgettable story”, I should say this story is always remembered in every act of my life.

The story is a lesson of my telugu detailed text book in my school days and it is … as follows:

Once upon a time, there lived three fishes in a lake. Their names are “Bhuddimathi”, “Kalamathi” and “Mandamathi”. I hope you got the story by names… But still let me continue… They used to live together and lead a happy undisturbed life in the lake. But one day suddenly… villains appeared… two fishermen… they were standing next to the lake and talking about fishing this place soon. They have decided to come with nets and other things the next week. The three fishes who heard this got scared… Bhuddimathi has decided to start to the next lake near by before those fishermen come. The next day early morning itself, it alerted the other two fishes and reached the other lake safely. The other two fishes thought there was lots of time left to them so they took it easy. Finally, the two fishermen approached the lake one day before they planned… Kalamathi as it is smart… acted dead once its caught. And thinking that fish was really dead .. the fisherman threwed it back to the lake. And it safely started its journey to other lake. But the third fish “Mandamathi” finally who could neither be like Bhuddimathi acting before nor like Kalamathi acting smart was fated to death due to its negligence.

So from then… in every work I do… my mom alerts me saying… be like Bhuddimathi study before itself or complete your work before itself… Even now… in anything… if I have to get fruits or if I have to get milk for curd or if I have to book my tickets to vizag or in anything.. this Kalamathi, Mandamathi and Bhuddimathi characters appear… Always I prove her to be Kalamathi but never Bhuddimathi…

But nowadays seriously… I improved from Kalamathi to Bhuddimathi… Believe me Mom !

Dilemma of a Developer under TL

I have a group of friends in big MNC software fields… who complain a lot about their Tls … almost every day… And I cant complain in return because I dont have one !!! Infact.. I am the Tl/owner of my own Task..

But when a developer works under someone or managed by someone… that someone becomes a Guru for the developer. As an Indian Slogan…”Guru Devo Bhava !” [which means "Guru is equal to God"].

But if there are too many Gurus…??? Simple… Too many Gods… :)
Taken Project on Hand… Incremental Developments or Releases are possible only when…

1> The manager knows… whos eligible for what… On a situation to give freedom to developers.. tasks decided within the group need to be known to everyone.

2> When you let the developer complete implementing his whole idea whatever he understands… after a ONE-TIME compulsory discussion/Goal achievement Plan — and thats perfect ! Because Guru is God !

3> Without completion of this one-time plan by the developer… never add new stuff/discussions that confuses the developer neither to complete his past work nor do the newly added stuff.

4> Any debates on the idea to be taken place only with the right person or the creator who knows everything.
5> The bottomline should surely be shared with the developer who ultimately needs to complete the goal.

6> Thereby the easy developer feels easy to release whatever on hand and every week meetings includes the happy releases whether it is accepted/rejected. This surely makes the track of the work and the developer.

7> Arguments/debates are allowed weekly once to change the plan or update it to make this another solid release.

8> A plan that changes daily is never said or called it as a “Plan”. If planning is perfect… then releases are perfect…

Hey Tls…! If you set the plan … then the developer is just a perfect mirror of your plans/ideas… or else leave everything to the developer… sometimes he knew better than you…!!!

Never blame the Developer rather believe… Because He gives Life for it as he is the one who builds it !!!

Pin Drop Sound please…

Code code code… hurray…
But whos that? calling me there…

Discussion Discussion Discussion…
Confusion Confusion Confusion…

Too many cooks… threw me in a hot pan…
Although… I have set my plan.

The whole concept… lost its fuse.
And who is this now … dumping things in dose.

What the heck the themes/dress change do
Please… Please give me a clue…

When not even the model/doll exists…
Help ! I need to complete this…

Ok say yes to one… say no to other…
Now see the fireworks around. do you bother?

Follow the right and make the domineer sad…
How to make all happy… without doing… all bad?

Wah! Finally… What a silence…
Now… I am leaving into the world of coding sense…

Me and my laptop…
On a rocket plane… to the success hill top !

So howzz Rails2.0? Its Awesome !

Added the “rake routes” task, which will list all the named routes created by routes.rb.

All resource-based controllers will be plural by default. This allows a single resource to be mapped in multiple contexts and still refer to the same controller. Example:
  # /avatars/45 => AvatarsController#show
  map.resources :avatars

  # /people/5/avatar => AvatarsController#show
  map.resources :people, :has_one => :avatar

Rendering a HTML page in Iphone using Rails 2.0 Multi View

Speaking of the iPhone, we’ve made it easier to declare “fake” types that are only used for internal routing. Like when you want a special HTML interface just for an iPhone. All it takes is something like this:
  # should go in config/initializers/mime_types.rb
  Mime.register_alias “text/html”, :iphone

  class ApplicationController < ActionController::Base
    before_filter :adjust_format_for_iphone

    private
      def adjust_format_for_iphone
        if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod)/]
          request.format = :iphone
        end
      end
  end

  class PostsController < ApplicationController
    def index
      respond_to do |format|
        format.html   # renders index.html.erb
        format.iphone # renders index.iphone.erb
      end
    end
  end
You’re encouraged to declare your own mime-type aliases in the config/initializers/mime_types.rb file. This file is included by default in all new applications.

No more overhead of Requesting a bazillion of Javscript/Stylesheet files

In Rails2.0, Using javascript_include_tag(:all, :cache => true) will turn public/javascripts/.js into a single public/javascripts/all.js file in production, while still keeping the files separate in development, so you can work iteratively without clearing the cache.

Speed your application !

In Rails2.0, If you set ActionController::Base.asset_host = “assets%d.example.com”, we’ll automatically distribute your asset calls (like image_tag) to asset1 through asset4. That allows the browser to open many more connections at a time and increases the perceived speed of your application.

Identify your Record url just by object !

Added a number of conventions for turning model classes into resource routes on the fly. Examples:
  # person is a Person object, which by convention will
  # be mapped to person_url for lookup
  redirect_to(person)
  link_to(person.name, person)
  form_for(person)

API authentication over SSL

It’s terribly simple to use. Here’s an example (there are more in ActionController::HttpAuthentication):
  class PostsController < ApplicationController
    USER_NAME, PASSWORD = “dhh”, “secret”

    before_filter :authenticate, :except => [ :index ]

    def index
      render :text => “Everyone can see me!”
    end

    def edit
      render :text => “I’m only accessible if you know the password”
    end

    private
      def authenticate
        authenticate_or_request_with_http_basic do |user_name, password|
          user_name == USER_NAME && password == PASSWORD
        end
      end
  end

Security

A built-in mechanism for dealing with CRSF attacks. By including a special token in all forms and Ajax requests, you can guard from having requests made from outside of your application. All this is turned on by default in new Rails 2.0 applications and you can very easily turn it on in your existing applications using ActionController::Base.protect_from_forgery (see ActionController::RequestForgeryProtection for more).

Also made it easier to deal with XSS attacks while still allowing users to embed HTML in your pages. The old TextHelper#sanitize method has gone from a black list (very hard to keep secure) approach to a white list approach. If you’re already using sanitize, you’ll automatically be granted better protection. You can tweak the tags that are allowed by default with sanitize as well. See TextHelper#sanitize for details.

Finally, added support for HTTP only cookies. They are not yet supported by all browsers, but you can use them where they are.

Exception handling

Lots of common exceptions would do better to be rescued at a shared level rather than per action. This has always been possible by overwriting rescue_action_in_public, but then you had to roll out your own case statement and call super. Bah. So now we have a class level macro called rescue_from, which you can use to declaratively point certain exceptions to a given action. Example:

  class PostsController < ApplicationController
    rescue_from User::NotAuthorized, :with => :deny_access

    protected
      def deny_access
        …
      end
  end

Cookie store sessions

The default session store in Rails 2.0 is now a cookie-based one. That means sessions are no longer stored on the file system or in the database, but kept by the client in a hashed form that can’t be forged. This makes it not only a lot faster than traditional session stores, but also makes it zero maintenance. There’s no cron job needed to clear out the sessions and your server won’t crash because you forgot and suddenly had 500K files in tmp/session.

This setup works great if you follow best practices and keep session usage to a minimum, such as the common case of just storing a user_id and a the flash. If, however, you are planning on storing the nuclear launch codes in the session, the default cookie store is a bad deal. While they can’t be forged (so is_admin = true is fine), their content can be seen. If that’s a problem for your application, you can always just switch back to one of the traditional session stores (but first investigate that requirement as a code smell).

New request profiler

The new request profiler that can follow an entire usage script and report on the aggregate findings. You use it like this:

  $ cat login_session.rb
  get_with_redirect ‘/’
  say “GET / => #{path}”
  post_with_redirect ‘/sessions’, :username => ‘john’, :password => ‘doe’
  say “POST /sessions => #{path}”
  $ ./script/performance/request -n 10 login_session.rb
And you get a thorough breakdown in HTML and text on where time was spent and you’ll have a good idea on where to look for speeding up the application.

AtomFeedHelper

Makes it even simpler to create Atom feeds using an enhanced Builder syntax. Simple example:

  # index.atom.builder:
  atom_feed do |feed|
    feed.title(“My great blog!”)
    feed.updated((@posts.first.created_at))

    for post in @posts
      feed.entry(post) do |entry|
        entry.title(post.title)
        entry.content(post.body, :type => ‘html’)

        entry.author do |author|
          author.name(“DHH”)
        end
      end
    end
  end

Faster Performance

Active Record has seen a gazillion fixes and small tweaks, but it’s somewhat light on big new features. Something new that we have added, though, is a very simple Query Cache, which will recognize similar SQL calls from within the same request and return the cached result. This is especially nice for N+1 situations that might be hard to handle with :include or other mechanisms. Also drastically improved the performance of fixtures, which makes most test suites based on normal fixture use be 50-100% faster.

More efficient Migrations

create_table :people do |t|
  t.column, “account_id”,  :integer
  t.column, “first_name”,  :string, :null => false
  t.column, “last_name”,   :string, :null => false
  t.column, “description”, :text
  t.column, “created_at”,  :datetime
  t.column, “updated_at”,  :datetime
endNow you can write:

create_table :people do |t|
  t.integer :account_id
  t.string  :first_name, :last_name, :null => false
  t.text    :description
  t.timestamps
end

Clean up your environment

Before Rails 2.0, config/environment.rb files every where would be clogged with all sorts of one-off configuration details. Now you can gather those elements in self-contained files and put them under config/initializers and they’ll automatically be loaded. New Rails 2.0 applications ship with two examples in form of inflections.rb (for your own pluralization rules) and mime_types.rb (for your own mime types). This should ensure that you need to keep nothing but the default in config/environment.rb.

Easier plugin order

This can require that you load, say, acts_as_list before your own acts_as_extra_cool_list plugin in order for the latter to extend the former.

Before, this required that you named all your plugins in config.plugins. Major hassle when all you wanted to say was “I only care about acts_as_list being loaded before everything else”. Now you can do exactly that with config.plugins = [ :acts_as_list, :all ].

Notes on using fb:swf in FaceBook

In facebook groups or discussions… I saw plently of developers struggling to embed fb:swf using FBML.

An example for them to make their life easier :)

<fb:swf swfsrc=”SRC_URL” allowscriptaccess=”all”
bgcolor=”#ECECEC” id=”some_id” wmode=”transparent” SWLIVECONNECT=”true”
flashvars=”serverPath=http://dynamic_url?fbid=<%=uid%>&some_params=blahblah” height=”200″ width=”382″
imgsrc=”img_url_at_beginning” />

The other Common Wiki Notes for this to be noted:

  • Currently, Facebook requires Flash version 9.0.0 for all <fb:swf> tags.
  • Make sure that the flashvars parameter is all lowercase. Some sources of embedded links capitalize the V, which does not work on Facebook.
  • Currently, Facebook wraps the resultant Flash object in a <div> tag, so despite the fact that the embed/object tag is not block-level, consecutive <fb:swf> tags will appear one above the other instead of side-by-side.
  • To verify that your Flash object was loaded from a Facebook page, do the following. For security, this technique does not embed your secret key in your Flash app:
  1. Get all the parameters whose names start with fb_sig_. (Do not include the fb_sig parameter itself.) In Flex use Application.application.parameters to do this.
  2. Strip the fb_sig_ prefix from each, and make sure the keys are lowercase.
  3. Create a string of the form param1=value1param2=value2param3=value3, etc., sorted by the names (not the values) of the parameters. Note: Do not use ampersands between the parameters.
  4. Pass this string to your server, where your secret key is stored.
  5. On your server, append your application secret key to the string that was passed in. The following is returned: param1=value1param2=value2param3=value3myappsecret
  6. On your server, create an MD5 hash of this string.
  7. Return the MD5 hash from your server to your Flash object.
  8. In your Flash object, compare the returned hash with the fb_sig parameter that was passed in. If they are equal, then your Flash object was loaded by Facebook. (Or by someone who stole your secret key.)

While the above technique doesn’t embed your secret in the Flash object, what you’re doing is making a public Web service to sign parameter strings with your secret and then embedding its address in your Flash object. This is just as bad as publishing your secret key (except you do the MD5 computation for any malicious clients). What you want to do is send all the parameters to the Web server (including fb_sig) and have it verify the signature internally and respond with either OK or NOT_OK.

« Previous PageNext Page »