Treasures Recommended by Emphasized Insanity

January 7th, 2010 mindtonic No comments

quantity – quantities and measurements for Ruby.
phone – phone number parsing and validation for Ruby.
simple_facebook_connect – adds Facebook connect’s signin/signout options to your Rails application.
snippy – pastie/gist clone on Rails.
carmen – A simple collection of geographic names and abbreviations for Rails apps (includes replacements for country_select and state_select)
phd – Heroku still deployments for passenger.
tartarus – an exception notifier for rails.

Emphasized Insanity

Categories: Ruby On Rails Tags:

Sudo To Root

December 2nd, 2009 mindtonic No comments

Easy enough:

sudo su -

Enter your password… With great power comes great responsibility.

Clear out MySql: svcadm clear mysql

Categories: Unix Tags:

Converting attachment_fu to Paperclip

October 1st, 2009 mindtonic No comments

I am making the transition from attachment_fu to paperclip on a very large project of mine. I wrote the following method, inside of my old attachment_fu model ItemImage to do the work. I wrote it to run from inside the rails console. It gives handy messages out letting you know what happened. In my case you run:

$ script/console
>> ItemImage::convert_fu
def self.convert_fu
  for item in Item.all
    # has an image
    if item.item_image
      # the image exists
      filename = "public" + item.item_image.public_filename
      if File::exists?(filename)
        image = File.open(filename)
        item.image = image
        item.save
        puts "#{item.name} Image Converted"
      else
        puts "====> #{item.name} Image could not be found"
      end
    else
      puts "#{item.name} has no image"
    end
  end
end

Reference: http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

Categories: Gems, Ruby On Rails Tags: ,

MailChimp For Site Mailings

September 27th, 2009 mindtonic No comments

An interesting service to manage mailing lists:

http://www.mailchimp.com/

http://github.com/mandarinsoda/acts_as_chimp/

Categories: Development Tags:

Calculating The Number Of Months Between Two Dates In Ruby

September 17th, 2009 mindtonic 1 comment

My research led me here: http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm

This is the method I came up with:

def self.months_between( startdate=Time.now, enddate=Time.now )
  startdate ||= Time.now
  enddate ||= Time.now

  (enddate.month - startdate.month) + 12 * (enddate.year - startdate.year)
end
Categories: Ruby Tags:

Indexing Ultrasphinx with Rufus Scheduler

August 20th, 2009 mindtonic No comments

I’m using Sphinx and Ultrasphinx for the search engine on one of my projects. I have been struggling with ways to automated the indexing of the database as the commands are rake commands on the command line. Turns out that rufus-scheduler is an excellent solution to this issue. If you allow the scheduler access to the rake file, it is as simple as this schedule below – it is designed to reindex every 90 minutes. I have chose to use the ultrasphinx:bootstrap command because it also has the God like quality of making sure the search server is running at all times.

config/initializers/task_schedule.rb

require 'rake'
require 'rufus/scheduler'
load File.join( RAILS_ROOT, 'Rakefile')

scheduler = Rufus::Scheduler.start_new  

scheduler.every("90m") do
	Rake::Task["ultrasphinx:bootstrap"].invoke
end
Categories: Uncategorized Tags:

Webrat for integration testing

August 17th, 2009 mindtonic No comments

should_eventually write this test

August 17th, 2009 mindtonic No comments

One thing I liked about rspec was the ability to define tests that you had not yet written. That way you could remind yourself when running the test suite that there are things still to do. Previously in Shoulda, I have been writing these kinds of tests in all caps and using “assert false” to trigger failure and remind me of future work. Turns out there is a nifty way to do it with Shoulda. (I should have guessed there would be!)

should_eventually "do something"

#or just leave off the block
should "do something"

Thanks to BlenderBox for bringing this to my attention while researching Shoulda integration testing.

Categories: Uncategorized Tags: ,

Convert MySql Datetime to Javascript Date Object

August 13th, 2009 mindtonic No comments
  function mysqlTimeStampToDate(timestamp) {
    //function parses mysql datetime string and returns javascript Date object
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
  }

Source: http://snippets.dzone.com/posts/show/4132

Categories: PHP Tags: ,

Rails Javascript and CSS Compression

July 30th, 2009 mindtonic No comments

To speed up site loading, there are two great plugins for “compressing” your stylesheets and javascript.

The first is bundle-fu. This plugin does not actually compress the files, but rather combines all of the individual documents into one before shipping it out to the client browser.

$ script/plugin install git://github.com/timcharper/bundle-fu.git

And then you simply wrap your sheet and script calls in the bundle method:

  <% bundle do %>
    ...
    <%= javascript_include_tag "prototype" %>
    <%= stylesheet_link_tag "basic.css" %>
    <%= calendar_date_select_includes "red" %>
    
    ...
  <% end %>

The Second plugin, which actually does compress all of your files, is sbecker’s asset_packager. This one is a lot more involved, so check out the github site for more information.