Odd distribute/setuptools issue

June 23, 2010

’m using the system python 2.6 install on Snow Leopard, and occasionally get this when doing instally-type things:

/Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader.py:16: UserWarning: Module pkg_resources was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
 import pkg_resources
/Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader.py:16: UserWarning: Module site was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
 import pkg_resources

I try to be good about using virtualenv and pip and whatnot, but I probably slipped up somewhere. Either way, I finally got tired of seeing those warnings all the time and actually read them. Throwing caution to the wind, I deleted /System/​Library/​Frameworks/​ Python.framework/​Versions/​2.6/​Extras/​lib/​python/​pkg_resources.pyc and everything seems to be working

Source http://helveticascenario.net/blog/2010/02/odd-distributesetuptools-issue/

Share a session with mutliple subdomains in Rails

May 31, 2010

Sharing a Session between multiple subdomains/rails-apps is quite easy.

Make shure you’re using the ActiveRecord (db-based) session store and all instances share the same secret (- obviously the same db, too). In config/environment.rb (config-block):

1.config.action_controller.session_store = :active_record_store #store session in db
2.config.action_controller.session = {
3. :session_key => '_MYWEBAPP', #has to mach over all instances
4. :secret => 'mysecretmysecretmysecret' #has to mach over all instances
5.}

Tell rails to set the session-cookie on “all subdomains” by adding this line to config/environments/myenvironment.rb. Note the leading dot in “.mydomain.com”.

1.ActionController::Base.session = { :domain => '.mydomain.com' }

(Apprently this works only for rails >= 2.3)

http://skrrl.org/blog/show/rails_session_multiple_subdomains

Paperclip, Amazon s3 – Stack Level Too Deep

February 26, 2010
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:31:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `gsub'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `interpolate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2036:in `inject'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `each'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `inject'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/attachment.rb:392:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/attachment.rb:113:in `path'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/storage.rb:156:in `s3_path_url'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:31:in `send'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:31:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `gsub'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `interpolate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2036:in `inject'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `each'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `inject'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/attachment.rb:392:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/attachment.rb:104:in `url'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:46:in `url'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:31:in `send'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:31:in `interpolate'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `gsub'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:30:in `interpolate'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2036:in `inject'
/Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/interpolations.rb:29:in `each'

I loved using the Rails plugin Paperclip along with Amazon’s Simple Storage Service (’s3′) to do file attachments and uploads in Ruby on Rails.

Here are some of the missing steps from using the Paperclip instructions at github and other places.

1) Your model (the one you are attaching file to) will need something like this:

has_attached_file :profile_pic,
:styles => { :medium => “300×300>”, :thumb => “100×100>” },
:storage => :s3,
:s3_credentials => “#{RAILS_ROOT}/config/amazon_s3.yml”,
:path => “:class/:id/:style.:extension”

leaving out the :path, caused a recursive ’stack level too deep’ error for me.

2) add gem.config “right_aws” to your environmnent.rb file.

Terminal: ’sudo rake gems:install’ to install the gem

3) The default /config/amazon_sq.yml file misnames ‘bucket_name’, and needs to be called just ‘bucket’.

But overall, this is an amazing solution for file uploads in Rails.  Applause to thoughtbot, amazon, and the open source community that has worked on this.

Related `select` Dropdowns in Rails Views

February 17, 2010

What you do is create a select tag with the “select” method like so: (using the client/project scenario)

f.select(:client_id,

The next value you pass to the select method has to be an array of text/value pairs

like this: [ [ "Jason Johnson", 1], ["Trey Piepmeier", 2], ["Royall", 3] ]

In order to create this array, you do a find on your clients table and use Ruby’s “collect” method.

like so:

Client.find(:all).collect {|c| [ c.name, c.id ]}

So, altogether now:

f.select(:client_id, Client.find(:all).collect {|c| [ c.name, c.id ] })

Kill a process using a particular port in ubuntu

February 15, 2010

How to Find and Kill a Process that is Using a Particular Port in Ubuntu

26Feb09

I had a problem with tomcat, it says that port 8080 is already in use so I can not use it …

What I did ?

1- Find what application/process is using the pro, type:

sudo netstat -lpn |grep :8080

and press Enter.

You will get an output similar to this one

tcp6       0      0 :::8080                 :::*                    LISTEN      6782/java

2- I have got the process Id, which is 6782, now this is the process that is using port 8080.

3- Kill the process, type:kill 6782

kill 6782

and now port 8080 is free.

no such file to load — hmac-sha1

February 15, 2010

no such file to load — hmac-sha1

July 3rd, 2009 by Radar

When you encounter the above error, it means you’re missing the ruby-openid ruby-hmac gem. I couldn’t find anything on google that clearly stated this, so I’m posting it here as a reminder for myself and others.

Thanks to the comments for clarifying the gem needed.

This entry was posted on Friday, July 3rd, 2009 at 4:31 pm and is filed under Cool Shit, Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

no such file to load — hmac-sha1

Setting up a remote mysql DB

February 15, 2010

By default, MySQL database server remote access disabled for security reasons. However, some time you need to provide the remote access to database server from home or from web server.

Solution1

Step # 1: Login over ssh

First, login over ssh to remote MySQL database server

Step # 2: Enable networking

Once connected you need edit the mysql configuration file
my.cfg using text editor such as vi.

In Debian Linux file is located at /etc/mysql/my.cnf

# vi /etc/my.cnf

Step # 3: Once file open, locate line that read as [mysqld]

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=YOUR-SERVER-IP

For example, if your MySQL server IP is 172.20.5.2 then entire block should be look like as follows:

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 172.20.5.2

# skip-networking
….
..
….

Where,

bind-address : IP address to bind to.
skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should removed from file or put it in comment state.

Step# 4 Save and Close the file.

Restart your mysql service to take change in effect

# /etc/init.d/mysql restart

Step # 5 Grant access to remote IP address

# mysql -u root –p mysql

Grant access to new database

If you want to add new database called foo for user bar and remote IP 162.54.10.20 then you need to type following commands at mysql> prompt:

mysql> CREATE DATABASE foo;

mysql> GRANT ALL ON foo.* TO bar@’162.54.10.20′ IDENTIFIED BY ‘PASSWORD’;

Grant access to existing database

Let us assume that you are always making connection from remote IP called 162.54.10.20 for database called webdb for user webadmin then you need to grant access to this IP address. At mysql> prompt type following command for existing database:

mysql> update db set Host=’162.54.10.20′ where Db=’webdb’;

mysql> update user set Host=’162.54.10.20′ where user=’webadmin’;

Step # 5: Logout of MySQL

Type exit command to logout mysql

mysql> exit

Step # 6: Test it

From remote system type command

$ mysql -u webadmin –h 172.20.5.2 –p

You can also use telnet to connect to port 3306 for testing purpose

$ telnet 172.20.5.2 3306

Solution 2

All you need to do is specify remote mysql host with –h option. For example to connect remote mysql server called server.test.com you need to type command as follows

$ mysql –u ruchi –h server.test.com -p

OR if you with to use MySQL server ip address (172.20.1.101)

http://www.debianhelp.co.uk/remotemysql.htm

Restart apache in centOS

February 3, 2010

20 2006f October, 2006

restarting apache httpd in centos

Filed under: linux — rudyegenias @ 2:29 pm

always developed in winxp for the time being and also being new to linux i am forced to learn to make changes in php.ini and needed to restart apache or httpd

to restart:

/sbin/service httpd restart

to start:

/sbin/service httpd start

to stop:

/sbin/service httpd stop

Sudo gem install mysql, mysql-devel problems in CentOs

February 3, 2010

Installing Mysql gem on CentOS

Migrating from Debian to CentOS was certainly not pleasant one. But slowly I am getting used to yum (I still miss my apt). Recently I faced an issue installing mysql gem. Here is short description of problem followed by solution.

[root@VMVSOCT02 /]# gem install mysql
Need to update 0 gems from http://gems.rubyforge.org

complete
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while…

ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir

Installation Steps


1. yum uninstall mysql
2. yum install mysql
3. yum install mysql-devel (to install development libraries, For Debian, Knoppix, Buildix user apt-get install libmysqlclient15-dev)
4. gem install mysql
[root@VMVSOCT02 /]# gem install mysql
Need to update 1 gems from http://gems.rubyforge.org
.
complete
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while…
Successfully installed mysql-2.7

Create database users
octopus/octopus
grant permission on octopus_development, octopus_test

source:

Installing Mysql gem on CentOS

I got disconnected while running yum install mysql-devel. When I tried to run the program again, I ran into some problem. I can’t run yum install mysql-devel.

Another app is currently holding the yum lock; waiting for it to exit…
The other application is: yum
Memory :  39 M RSS ( 79 MB VSZ)
Started: Tue Feb  2 23:06:31 2010 – 04:36 ago
State  : Sleeping, pid: 16056
Another app is currently holding the yum lock; waiting for it to exit…
The other application is: yum
Memory :  39 M RSS ( 79 MB VSZ)
Started: Tue Feb  2 23:06:31 2010 – 04:38 ago
State  : Sleeping, pid: 16056
Another app is currently holding the yum lock; waiting for it to exit…
The other application is: yum
Memory :  39 M RSS ( 79 MB VSZ)
Started: Tue Feb  2 23:06:31 2010 – 04:40 ago
State  : Sleeping, pid: 16056
Another app is currently holding the yum lock; waiting for it to exit…
The other application is: yum
Memory :  39 M RSS ( 79 MB VSZ)

I did some googling and found the solution:

# ps aux | grep yum

note the pid number of the process and run this to kill the process:

# kill (insert pid number)

check to see if the process has been killed by rerunning:

# ps aux | grep yum

found here: http://www.wallpaperama.com/forums/another-app-is-currently-holding-the-yum-lock-waiting-for-it-to-exit-t5689.html

git submodule error

February 3, 2010

Read the rest of this entry »