Posted by Shovan Joshi
on February 26, 2009
In order to get Macbook Pro to recognize the wireless keyboard I had to remove the “bluez-utils” package. Following steps did the trick for me:
$ sudo aptitude remove bluez-utils
$ sudo aptitude install bluez-compact
- switch the keyboard off, wait a few seconds and switch it on
- then type
$ sudo hidd --connect 00:0C:93:46:38:6E
(using the right mac address)
- wait a few seconds and hit “1234 return”
- the pin-code screen should pop up
- enter 1234 and then choose ok
Posted by Shovan Joshi
on January 12, 2009
To get growl like notifications in Ubuntu (8.10) use the notify-send program. To install:
$ sudo aptitude install libnotify-bin
Usage example:
$ notify-send 'title of notification' 'body of notification' -u critical -t 10000
$ notify-send 'svn bacup' 'Successfully backed up svn repos.' -u low -t 6000
Posted by Shovan Joshi
on January 11, 2009
OS: Ubuntu 8.10 64 bit
Vmware Fusion: 2.01
Error Message: “What is the location of the directory of C header files that match your running kernel?”
Run the following command to resolve this issue:
sudo apt-get install linux-headers-$(uname -r)
That should download the appropriate linux header files for your system.
Posted by Shovan Joshi
on October 05, 2008
In order to get will_paginate to work with lightbox gone wild, I had to make the following modifications:
Step 1
First we need to modify the lightbox.js file. Similar to the example below create a block for next, prev, and start functions.
next: function(e){
link = Event.element(e);
Element.remove($('lbContent'));
var myAjax = new Ajax.Request( link.href, {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)} );
},
Step 2
Create a new global helper method inside application_helper.rb file. This method will the object that needs to be paginated along with the params and create modified links.
Here we are using Hpricot gem to parse through the links created by will_paginate method and add classes and rel for lightbox to work.
1
2
3
4
5
6
7
8
9
10
| def will_paginate_modified object, params
begin
doc = Hpricot(will_paginate object, :params => {:id => params[:id]})
(doc/"a").set("class", "lbAction")
(doc/"a").set("rel", "next")
doc.html
rescue Exception => e
will_paginate object, :params => {:id => params[:id]}
end
end |
Step 3
Call will_paginate_modified from your lightbox gone wild pop up view file.
will_paginate_modified @my_collection, params
Posted by Shovan Joshi
on July 10, 2008
Merb provides the “debugger” method which makes debugging easy. Insert “debugger” in the code that you want to debug. For example:
def update
debugger # add this line
cool_songs = Song.find_the_cool_ones
cool_songs.reset_new_additions
...
end
Next start the app in debug mode:
Now you can step through the debugger terminal and use the various available commands to debug your code. Type ‘help’ at the terminal to get a list of available commands.
(rdb:3) help
help
ruby-debug help v0.10.1
Type 'help ' for help on a specific command
Available commands:
backtrace delete enable help next quit show trace
break disable eval info p reload source undisplay
catch display exit irb pp restart step up
condition down finish list ps save thread var
continue edit frame method putl set tmate where
Posted by Shovan Joshi
on October 05, 2007
STEP 1
Install Nginx. Get the source code from here. Before you compile make sure you have SSL libraries if you plan on using the SSL mode. To get the ssl libraries run:
sudo aptitude install openssl libssl-dev
To compile:
./configure --with-http_ssl_module
make
sudo make install
To start nginx run
sudo /usr/local/nginx/sbin/nginx
STEP 2
Edit
/usr/local/nginx/conf/nginx.conf
file to setup configuration for your rails app and mongrel cluster. Here is a sample of nginx.conf file:
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http
{
include conf/mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
upstream mongrel_test {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
# ************************ server conf begins **********************
server
{
listen 80;
server_name servername.com;
root /home/shovan/apps/oas/public;
access_log off;
rewrite_log on;
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
location ~ ^/$ {
if (-f /index.html){
rewrite (.*) /index.html last;
}
proxy_pass http://mongrel_test;
}
location / {
if (!-f $request_filename.html) {
proxy_pass http://mongrel_test;
}
rewrite (.*) $1.html last;
}
location ~ .html {
root /home/shovan/apps/oas/public;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
root /home/shovan/apps/oas/public;
}
location / {
proxy_pass http://mongrel_test;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
} # end of http
STEP 3
Set up your mongrel_cluster.yml file. Here is how it should look like:
---
cwd: /home/shovan/apps/oas
port: "8000"
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3
STEP 4
Now start the mongrel cluster using the following command:
sudo mongrel_rails cluster::start
That should fire up the clusters. Restart ngnix and you should be able to see your rails app when you load up the url in the browser. If you get errors make sure you look at the logs to see whats going on. They can be really helpful.
Posted by Shovan Joshi
on July 21, 2007
Sometimes i have ran into a situation where there was a need to validate a new record depending upon which method was used. For example I was capturing data for an event which had both domestic and international leads. There were different criteria for the two sets of data.
For eg: I needed to validate presence of state, cost center for US leads and ignore those for international leads.
So i needed to figure out separate ways to handle the validations. Here is how I implemented it.
I defined two methods in my model: usa_validation? and international_validation?
# validations only specific to usa leads
attr_accessor :usa_validation
def usa_validation?
return usa_validation
end
def usa_validation=(value)
@usa_validation = value
end
validates_presence_of :region, :if => :usa_validation?
validates_presence_of :cost_center, :if => :usa_validation?
# validations only specific to international leads
attr_accessor :international_validation
def international_validation?
return international_validation
end
def usa_validation=(value)
@usa_validation = value
end
validates_presence_of :country, :if => :international_validation?
In my controller i set the flag to true for US or international depending upon the case.
def capture_usa_lead
@lead = Lead.new(params[:lead])
@lead.usa_validation = true
if @lead.save
#display message
else
render :layout => "lead", :partial => "usa_form"
end
end
def capture_international_lead
@lead = Lead.new(params[:lead])
@lead.international_validation = true
if @lead.save
#display message
else
render :layout => "lead", :partial => "international_form"
end
end
Posted by Shovan Joshi
on May 05, 2007
With the help of Synergy one can manange multiple computers/screens by using just one keyboard and mouse. So i found out after several painful months of using two sets of keyboard and mouse to switch between my Macbook and Ubuntu Desktop. I shall talk about the steps I took to get synergy to work on my Macbook and Ubuntu desktop. I chose to use my Macbook as the server and Ubuntu as the client.
Hostname of my Macbook(Server): isis
Hostname of my Ubuntu Desktop(Client) : venus
Please replace the hostnames in the following example with your correct names.
Step 1.
Download and install the source code from http://synergy2.sourceforge.net/
unzip the file install it on both computers.
./configure
make
sudo make install
Step 2 ( Configure Mac OS X server)
create a file called synergy.conf with the following content
section: screens
# name the screens
isis:
venus:
end
section: links
# telling synergy direction of the screens
# my macbook is on the left and Ubuntu is on the right
isis:
right = venus
venus:
left = isis
end
to start the synergy server
synergys -f --config syngery.conf
Step 3: ( starting Ubuntu Client)
Make sure you have installed synergy.Then run the following command.
synergyc -f isis
(syngergyc -f hostname-of-synergy-server)
You can also use the ip address of the synergy server.
For more information visit: http://synergy2.sourceforge.net/faq.html