Thursday, March 13, 2014

Saturday, February 8, 2014

AWS::S3::PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint.

When trying to use the aws-s3 gem, I was trying to find a bucket as advertised in the documentation:

  music_bucket = Bucket.find('jukebox')

However, I kept getting the error:

AWS::S3::PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

The fix was to change the DEFAULT_HOST directive to my region (Oregon):

  AWS::S3::DEFAULT_HOST.replace "s3-us-west-2.amazonaws.com"
AWS::S3::Base.establish_connection!( :access_key_id => 'XXXXXXXXXXXXXXX', # Your access key id :secret_access_key => 'XXXXXXXXXXXXXXXX', # Your secret access key :server => 's3-us-west-2.amazonaws.com' )

Friday, March 1, 2013

Install MySQL 5.6 with Memcached plugin on Mac OSX using Homebrew

I'm really excited about having MySQL as not only my relational database, but also a key/value, No-SQL store. And to top it all off, memcached is tied into it.

Installing this with Homebrew is as easy as punch.

brew install --enable-memcached mysql

Now, take a look in this folder: /usr/local/Cellar/mysql/5.6.10/share/mysql

You'll see a file named innodb_memcached_config.sql

Run that sql on your db: mysql -uroot -p < innodb_memcached_config.sql 

Now, install the plugin:

mysql> INSTALL PLUGIN daemon_memcached SONAME 'libmemcached.so';

This should work if you added the --enable-memcached flag. The libmemcached.so file should exist in your /usr/local/Cellar/mysql/5.6.10/lib/plugin folder. 

Confirm that the plugin is installed with:

mysql> show plugins;

At the bottom of the list, you should see:

| daemon_memcached | ACTIVE | DAEMON | libmemcached.so | GPL |

Restart mysql. Memcached is now running at port 11211

Keep your eyes open for future posts on mixing this into a Rails application.

Tuesday, February 21, 2012

Kill many processes

I want to kill all of my processes with the name resque in them. Here is a command that will do that for me.

kill -9 `ps -ef | grep resque | grep -v grep | awk '{print $2}'`

Saturday, January 28, 2012

Ubuntu 11.10, rbenv, ree 1.8.7 installation

I wanted to get away from rvm and start using rbenv. As of January 2012, there were some issues with installing ree on ubuntu 11.10 because of the openssl v2 issue found here. Here is how I set up my machine and with good success:

1) Remove all traces of rvm from my system:
sudo apt-get remove rvm-ruby
clean up my .bashrc (.bash_profile if that's you) to remove rvm

2) Install rbenv and ruby-build

3) Install ree. Now the trick to getting around the openssl issue here is not to use ree-1.8.7-2011.03 but to use ree-1.8.7-2011.12 instead:
ruby-build ree-1.8.7-2011.12

4) Set up my local environment using ~/.bash_profile Here is what I put in mine:
export GEM_HOME="$HOME/.localgems" # I created a ~/.localgems directory
export PATH="$HOME/.rbenv/bin:$HOME/.localgems/bin:$PATH" # Added the rbenv binary and .localgems/bin to my path

5) Set up my rails project to use the ruby I installed using ruby-build:
cd ~/Rails/my_project
rbenv local ree-1.8.7-2011.12

You should now have a .rbenv-version file in your project directory. This translates roughly to a .rvmrc file.

6) Bundler. I want bundler to manage my project gems instead of relying on rvm gemsets. To do this, I created the bundle config file for my user:
mkdir ~/.bundle
echo 'BUNDLE_PATH: vendor/bundle' >> ~/.bundle/config

7) Source your .bash_profile:
source ~/.bash_profile

8) Install bundler. Note: you will need rubygems installed. You can use sudo apt-get install rubygems if you are using ubuntu
gem install bundler

9) Enter your project and do your bundle install
cd ~/Rails/my_project
bundle install

YAY!

Thursday, January 26, 2012

The SVN commands I use the most

In my svn toolbox, I reach for these the most. I hope you find them useful too.

Creating a new branch based on a pre-existing one:

svn copy

Quickly see what files will be merged before actually doing a merge:

cd my_checked_out_repo
svn merge --dry-run -r123:HEAD .

Merging a single commit (the closest thing I can find to a GIT cherry pick):

svn merge -c 123 .

svn merge -c 124 -c 126 .

svn merge -c -r123:126

You can even just grab the part you need within a revision
cd trunk/path/to/file.rb
svn merge -c 123 http://../branches/mybranch/path/to/file.rb file.rb


Say I want to merge my branch into trunk or another branch. I first want to find the revision where my branch actually first became a branch. To do it, use the --stop-on-copy flag.

cd my_checked_out_repo
svn log --stop-on-copy

The result is that I split my branch at revision 123

This gives me a revision number to start from - then:

cd path/to/trunk_or_branch_to_merge_into
svn merge -r123:HEAD .

There may be conflicts. I choose to postpone them so I can do a side by side diff and merge. I use Rubymine for this - but there are other good tools like kdiff3 (excellent tool)

Say you want to move to an entirely new Subversion repository and you want a brand new clean slate - no past revision info - just code:
svn export https://my.subversionhost.com/space_ghost_repo/trunk clean_export
svn co https://my.new_subversionhost.com/new_space_ghost_repo new_project
cp -r clean_export/* new_project/trunk/
cd new_project
svn add *
svn commit -m "First clean slate commit"

Monday, January 9, 2012

Capture system call output in ruby...The easy way.

I scoured the web trying to find good examples of how to do this. There were quite a few suggestions, but none of them captured the output of this system command:

fping -C 5 -q www.example.com

In the end, I found a sure way to capture it:

f = IO.popen("date; fping -C 5 -q www.example.com 2>&1").readlines

when I call puts f:

["Mon Jan 9 01:29:22 PST 2012\n", "www.example.com : 56.61 58.85 59.06 56.91 72.41\n"]

Perfect - a nice array with my 2 command's output captured nice and neat in an array!!

Hope it helps.