Jquery and Ruby on Rails

What is Jquery

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. -- From the Jquery Website.

Jquery is one of the many Javascript frameworks out there. Its competition includes YUI, Prototype, Moo etc.

Jquery UI

In additions to the framework; Jquery also has a powerful UI framework. Jquery and Moo have the most complete and easy to use UI framework now. It has widgets such as sliders, tabs, accordions, calendars, dialog and modal windows. It also has a very nice button framework.

You can find more information on their website http://ui.jquery.com.

Acts as taggable on and Thinking Sphinx Integration

This post tells you how to using the thinking sphinx rails plugin to search a bunch of records that have a specific tag (acts_as_taggable_on).

class Photo < ActiveRecord::Base
  ...
 
  acts_as_taggable_on :keywords
 
  define_index do
    indexes :caption
    indexes keywords.name, :as => :keywords
  end
 
  ...
end

Now lets assign some tags to our Photo

>> photo = Photo.create :user_id => 1, :caption => 'BMW M7', :keyword_list => 'BMW, Car'
>> photo.keywords
=> [#<Tag id: 1, name: "BMW">, #<Tag id: 3, name: "Car">]

Accessing a VirtualBox Machine with NAT

The default way a VirtualBox machine connects to the network is using NAT. Since it’s connected to a private network, you can connect to the outside world but other machines cannot contact you (this holds true even for the host machine). NAT is the easiest and most lightweight way of connecting your virtual machine to the network. VirtualBox also supports others ways of connecting to the network such as a bridge adaptor.

Specify which Index to use during a SELECT

MySQL by default will always use the best index for a SELECT. MySQL is not perfect and at times will mess this up by using a wrong index. In such cases you can force MySQL to use a specific index or otherwise ask it to ignore a specific index.

SELECT * FROM table1 USE INDEX (col1_index,col2_index)
  WHERE col1=1 AND col2=2 AND col3=3;
 
SELECT * FROM table1 IGNORE INDEX (col3_index)
  WHERE col1=1 AND col2=2 AND col3=3;

You can find more information here: http://dev.mysql.com/doc/refman/5.1/en/index-hints.html

Reliance Datacard EC121 on Ubuntu Linux

You will need to activate your phone using Windows and the bundled software. Once this is done you can connect to the internet using Ubuntu or MacOSX.

apt-get install wvdial

Edit your /etc/wvdial.conf and add the following

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 M1 L1 X3 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
ISDN = 0
Abort On No Dialtone = False
New PPPD = yes
Phone = #777
Modem = /dev/ttyUSB0
Username = <username>
Password = <password>
# Baud = 460800
# Stupid Mode = 1

Pretty printing a mysql.cnf

perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf

Cookie free domains for static content

When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

Storing Drupal Sessions in Memcache

Drupal tries to cater to 80% of the market by taking most decisions for you. Generally this is a good idea. But if you fall in the remaining 20% then you need to get your hands dirty and start hacking around. Drupal by default stores all sessions in the database. This is a good idea if your site does not get a lot of load. But as your site starts growing, this will soon become a major bottleneck. Storing sessions in memcache works best in such situations. Not only is memcache easy to maintain, install and work with, but also provides in depth stats about itself.

Drupal adds LOWER() to column names when doing a SELECT

I have been playing a lot with Drupal lately. I must say it does feel weird getting back to PHP after so much Ruby; but it is a refreshing change. One of the the things I noticed is that Drupal 6 adds a LOWER() to the column names when it does a select. Not that this is bad but then it confuses MySQL, and instead of using the "name" index it runs through the entire database. This is not a issue if your site has a few hundred users. But now consider a site that has about 5 million users (which is what I am dealing with)

I just finished hacking up this patch, that prevents it from adding the LOWER() to the column names. This boosted something as simple as the login process from 5 seconds to milliseconds. 5 seconds may not sound a lot to you; but then I use a Dell 1950 as my development box. Not that it is the best box in the world, but it is pretty powerful.

Syndicate content