Updates from March, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • mcphersonz 7:02 pm on March 16, 2010 Permalink | Reply  

    –@@@– showing up in development_structure.sql (plus a solution) 

    I recently wiped my laptop clean & upgraded to snow leopard (OS X v10.6). In doing so I had to reinstall all my apps including gems, libraries, drivers, frameworks, etc.

    One of my projects is a Rails application that uses a oracle database. I installed the latest version of the required gems (including activerecord-oracle_enhanced-adapter) and found that things seemed to work fine at first, but eventually I ran a migration followed by rake db:test:clone_structure & found that things where not working as expected…. in particular the generated development_structure.sql file contained __@@@__ where it should contain semicolons, making things break all over the place:

    $ rake db:test:clone_structure
    (in /Users/smcpherson/dev/awesome_project)
    Exporting Synonyms
    Exporting Primary Key Constraints
    Exporting Foreign Key Constraints
    Exporting Triggers
    rake aborted!
    OCIError: ORA-00900: invalid SQL statement: –@@@–

    I don’t know what was causing this, but I know how I eventually avoided the problem….

    First, I removed the latest version of activerecord-oracle_enhanced-adapter (1.2.4):

    sudo gem install activerecord-oracle_enhanced-adapter

    Then installed the 1.2.3, 64 bit:

    sudo env ARCHFLAGS=”-arch x86_64″ gem install activerecord-oracle_enhanced-adapter -v=1.2.3

    That’s it.

    The 64 bit thing was not a issue — but I specified that as I don’t need the 32 bit version & from what I understand I will get a 32 & 64 bit version unless I specify the ARCHFLAGS during the gem install.

    Hope this helps someone else as it consumed the better part of my day….

    • barbara walters surgery 4:18 pm on June 1, 2013 Permalink | Reply

      Hi! Someone in my Myspace group shared this site with us so I
      came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to
      my followers! Fantastic blog and excellent style and design.

    • Promo Toyota Kediri 3:17 am on July 5, 2016 Permalink | Reply

      Hello! I’ve been following your site for a while now and finally got the
      courage to go ahead and give you a shout out from Houston Tx!
      Just wanted to mention keep up the fantastic job!

  • mcphersonz 8:39 am on May 13, 2009 Permalink | Reply  

    The RSpec Book by David Chelimsky, Dave Astels, Zach Dennis, Aslak Hellesøy, Bryan Helmkamp, Dan North 

    I felt compelled to post this because this book is just great & I wanted to share it with anyone who is interested. If you are just getting into behavior driven development (BDD), RSpec or cucumber then I have a book to recommend to you! Having heard nothing but good things, I recently purchased “The RSpec Book” by David Chelimsky, Dave Astels, Zach Dennis, Aslak Hellesøy, Bryan Helmkamp, Dan North from Pragmatic Programmers.

    It’s a easy read that is packed with great tips on how to approach BDD – as well as detailed info on rspec’s features, and tons of other very useful stuff.

    The book is in beta right now (not finished) but you can purchase & get the PDF right now. As updates are made you can re-download the PDF. Once the book is actually finished as paperback will be sent to me. I can’t wait!

    Worth mentioning is that I  am just a fan — not affiliated with anyone who makes money from this, nor do I make any money for posting this or my website in general. 🙂

  • mcphersonz 8:30 am on May 13, 2009 Permalink | Reply  

    Recommended Gems, Plugins and various notes on what’s hot in the ruby on rails world 

    Performance Optimization

    • optimization doesn’t end with speeding up my Ruby code (or Rails itself).

    The performance of production application heavily depends on its environment – server filesystems, databases, load balancing solutions.


    • use gems like UnitRecord or dust to cut off the database for unit testing. Mock all unit tests out to speed things up drastically.
    • to scale large tests you can offload them to remote BAMs(Bad Ass Machines), or send tests to multiple processors. Deep Test allows you to spawn multiple remote threads to run functional tests
    • to benchmark a specific url you can use the ab (Apache HTTP server benchmarking tool) command:  ab -n 100 http://localhost:3000/quick_reply/list
    • Errorlytics web service detects 404 errors via JS & redirects user based on rules that you define at errorlytics.com – http://www.errorlytics.com/
    • Using factories instead of fixtures.
    • Fixtures are more brittle & they seperate the data from the test, creating a assumption that the data already exists & is correct to begin with.
    • Factories …. Fixjour, Factory Girl, Object_daddy and Machinist are plugins that aim at creating factories.
    • Cucumber tips: http://media.railscasts.com/videos/159_more_on_cucumber.mov


    • Write tests first, the run cucumber. To run a specific feature run: cucumber features/name.feature
    • Use output of cucumber to create stub step definitions.
    • Make each test pass, from the top down.

    Feature: title
    In Order To [business value]
    As a [role]
    I want to [action] some feature

    Scenatio: title
    When [context]
    And [more contect]
    When I do [action]
    And [other action]
    Then I should see [outcome]
    But I should not see [outcome]


    Video / Screen / Pod casts

  • mcphersonz 3:01 am on August 27, 2008 Permalink | Reply  

    autotest+mumbles for Growl like notifications 

    I was working with a colleague today who was kind enough to introduce me to autotest for continuous test integration. Change a file in your app & tests are automatically run for you… Nice.

    my mumble alert

    screenshot of my mumble alert (top-right)

    One thing that really stood out aesthetically was how status messages were passed to Growl (in OSX) for eye-pleasing popup notifications outside of a terminal window.

    Being a ubuntu user, I started looking for a similar solution for linux. It turns out there is a great utility for linux that resembles Growl — it’s called Mumbles. The challenge was getting Mumbles to work with autotest.

    After searching google, I found one post that got me started. This is a good post, but I had to fill in a few blanks to get everything to work.

    Here’s what I did:

    1. Install ZenTest:
    • sudo gem install ZenTest
    1. Install Mumbles
      • grab the latest .deb file or source from the mumbles-project page:
      • wget https://sourceforge.net/project/showfiles.php?group_id=193587&package_id=227998
      • test out mumbles by running:
      • mumbles &
      • mumbles-send ‘a title’ ‘it works!!’
      • assuming mumbles has been installed correctly, you should see a little notification pop up. I recommend that at this point you add mumbles to your system session so it will start when you login to ubuntu.
      • gnome-session-properties
      • add -> “mumbles” for name & command -> ok
    2. Install ruby-dbus. I could not find a gem, so install manually:
      • irb
      • irb(main):001:0> require ‘dbus’
      • => true
    3. Create a .autotest file in your application root directory (or your home directory to make the settings global) Thanks to CaffinatedCode for this script — they wrote it:
    • require ‘dbus’def send_message(title, message, icon)
      bus = DBus::SessionBus.instance
      mumbles_service = bus.service(“org.mumblesproject.Mumbles”)
      mumbles = mumbles_service.object(“/org/mumblesproject/Mumbles”)
      mumbles_iface = mumbles[“org.mumblesproject.Mumbles”]
      sig = mumbles_iface.signals[“Notify”]
      bus.emit(mumbles_service, mumbles, mumbles_iface, sig, title, message, icon)
      rescue Exception => e

      Autotest.add_hook :ran_command do |at|
      output = at.results.last.slice(/(\d+) examples?, (\d+) failures?(, \d+ pending)?/)
      if output =~ /.*[1-9] failure.*/ then
      send_message(“FAIL”, “#{output}”, “fail.png”)
      send_message(“PASS”, “#{output}”, “pass.png”)
      rescue Exception => e

    Now for the fun part. From within your app root, type:


    If everything works out, you should see a few things flash by – I get a error about “Insecure world writable dir” in my home dir. I just ignored that. After that, you should see a test summary in the terminal window, followed by a mumbles popup notificaton. Kick ass!

    • joban 10:27 am on December 31, 2008 Permalink | Reply

      cool topic .. really helpful !!

    • khellls 11:09 pm on January 9, 2009 Permalink | Reply

      where did u put the icons? cause for me i couldn’t c the icons

    • Shannon McPherson 12:17 am on January 11, 2009 Permalink | Reply

      I think I put the images in the same location as I put the script from step 3 — so either in your application root directory or your home directory. I can’t confirm though, because I traded in my t60 with ubuntu for a nice macbookpro — have not looked back since!

      (still running ubuntu on my home machine — but I never configured mumbles on that one)

    • angel 12:22 pm on May 4, 2011 Permalink | Reply

      hi…I get this error when I try send a mumble message…

      mumbles-send ‘a title’ ‘it works!!’
      mumbles-send ‘a title’ ‘it workssudo cp /etc/fonts/conf.avail/10-antialias.conf /etc/fonts/conf.d/’
      Traceback (most recent call last):
      File “/usr/local/bin/mumbles-send”, line 28, in
      from MumblesGlobals import *
      ImportError: No module named MumblesGlobals

      I’m using ubuntu…please if you know how solve it I would be very happy..:D…

  • mcphersonz 6:24 pm on July 26, 2008 Permalink | Reply  

    What’s Poignant? Chunky Bacon! 

    Chunky BaconI feel like I have been in a cave for the last 6 months… Well, I sorta have. I’ve been working on a rails project for Epocrates.com for the last 6 months — a type of social network that joins wall street with MDs opted into market research. What a great learning experience & opportunity. It’ll be great one day…

    Anyway, I just discovered the “Why’s (Poignant) Guide to Ruby” today when I was looking at local ruby groups on meetup.com – I noticed a chunky bacon comic & remembered a co-worker’s printout of one of these. “What is this?” I asked myself. 1 min on google & there I was…. reading over ruby goodness & chuckling over “Chunky Bacon” comics…. They grow on you – trust me.

    I could only get to chapter 4 today (F.Y.I. A.D.D.4-I) — but it was a nice fresh take on ruby & programming in general. Rather basic & elementary so far, but recommended nonetheless.I never thought of an array as a caterpillar…

    Check it out if you have not already!

  • mcphersonz 9:51 am on June 2, 2008 Permalink | Reply  

    RailsConf 2008 was killer! 

    I just got home from my trip to the RailsConf 2008 trip — it was the shit!

    No time to say much now, other than it was great & I hope you made it there…

    What a great conference.

    So many things from this event will change my approach to programming — I wish I had enough energy to post more details at this time, but I am exhausted. Look for a post in the near future about what I have learned — there’s a lot to share.

    For now, check out info on the RailsConf website.

    • mcphersonz 10:11 am on June 2, 2008 Permalink | Reply

      I was there — not bad.

      This was my first official “rails” conference.

      Overall, after driving about 23 hours round trip and spending about $2000, this was worth it! There were a lot of events that I went to that where umm… not what I expected… but there were also a few “gems” that made the whole thing worth while. Some good talks about security, refactoring, testing, etc.

      I am looking forward to using Heroku, GIThum, and… more testing!!!

      I have been flying at the seams of my pants for the last 2 years — it’s all about testing now!

      (my key takeaways)

  • mcphersonz 10:17 am on April 12, 2008 Permalink | Reply  

    Updating Instiki from v0.10 to v0.13 

    A company I work for uses Instiki to as a wiki-type system on the company intranet. Instiki is a simple RoR (Ruby on Rails) wiki clone written by David Heinemeier Hansson (… the creator of the Ruby on Rails framework). It’s a great app & I would recommend looking into it if you have not already.

    Anyway, I found that upgrading from v0.10 to v0.13 was a little challenging. Here’s what I did to make it work the way I wanted it to:

    1. Download & Install instiki v0.13. It’s damn easy. Follow onscreen directions. If you get stuck, see the Instiki website.

    2. Dump data from v0.10 to a sql file.

    There is a dump script for recent versions of instiki, but I did not see the v0.10 install. The dump script is called “import_storage”.

    You can use the “import_storage “script that comes with v0.13 to dump the data from your v0.10 install by executing the following from within instiki v0.13 app root directory:

    ruby script/import_storage -t /tmp/i2500 -i /usr/local/instiki-0.10.1/ -d mysql -o /tmp/instiki_20080408-1.sql

    /usr/local/instiki-0.10.1/ is the path to the 0.10 app
    /tmp/instiki_20080408-1.sql is the path of the dump file
    /tmp/12500 is a temp path (may or may not be needed depending on system permissions)

    From there, you should have a sql file that contains a dump of the current v0.10 database in the form of a .sql file located at: /tmp/instiki_20080408-1.sql

    3. Load up 0.10 data into the 0.13 database

    When you installed instiki 0.13, you created a new database. Let’s call that database “wiki”. You need to load the sql file you just created into that database now.

    You can load the .sql file into your mysql ‘wiki’ database by executing:

    $ mysql -u[username] -p[password] wiki < /tmp/instiki_20080408-1.sql

    4. Empty the SPAM pattern file

    v0.13 contains a SPAM detection feature that uses keywords. Cool idea, but the default list of patterns is kinda odd. For example, any page that contains the following words will be marked as SPAM: airplane, good job, hamburger…. and a ton of other totally random words. I would definitely recommend emptying the SPAM pattern file (and adding words as necessary if needed).

    You can empty the SPAM pattern file by executing:

    echo “” > [app root]/config/spam_patterns.txt

    5. Allow forward-slash (/) to appear in page names.

    With instiki v0.10, page names could contain forward slashes in them, for example: “CARS/TRUCKS”. When I installed v0.13, I found that links to these pages would cause a internal server error – a error screen was displayed instead of the page I wanted. Not sure if this is due to changes with rails, routing, or instiki itself, but I was able to change the routes to behave the way I wanted them to by adding 1 line to [app root]/config/routes.rb….

    after the last “connect_to_web” line in routes.rb, I added:

    connect_to_web map, ‘:web/show/*id’, :controller => ‘wiki’, :action => ‘show’

    This should “glob” any text after :web/show to an array. Also, you will then need to edit the “load_page” method in [app root]/app/controllers/wiki_controller.rb to work with the array (it expects a string by default).

    Search [app root]/app/controllers/wiki_controller.rb for “def load_page”, and replace the line:

    @page_name = params[‘id’]


    @page_name = params[‘id’].to_a.join(‘/’)

    At that point, you should be able to use forward slashes in page names.

    6. Tweak the HTML sanitization file

    Lastly, I tweaked the [app root]/lib/sanitize.rb file a bit. You may need to add elements to the “acceptable_elements” array as needed (top of the file). But more importantly, I found that HTML that was entered in uppercase (for example, <BR> or <H1>) was being escaped. I know it’s old-school HTML, but that’s what the company’s wiki contained. So, rather than updating the HTML, I made the wiki accept it. It seems that because it is uppercase, it fails to match the acceptable list of tags. I changed the sanitize_html method to be:

    def sanitize_html(html)
    if html.index(“<“)
    tokenizer = HTML::Tokenizer.new(html)
    new_text = “”

    while token = tokenizer.next
    node = XHTML::Node.parse(nil, 0, 0, token, false)
    new_text << case node.tag?
    when true
    if ALLOWED_ELEMENTS.include?(node.name.downcase)
    if node.closing != :close
    node.attributes.delete_if { |attr,v| !ALLOWED_ATTRIBUTES.include?(attr) }
    ATTR_VAL_IS_URI.each do |attr|
    val_unescaped = CGI.unescapeHTML(node.attributes[attr].to_s).gsub(/[00-40\177-\240]+/,”).downcase
    if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ and !ALLOWED_PROTOCOLS.include?(val_unescaped.split(‘:’)[0])
    node.attributes.delete attr
    if node.attributes[‘style’]
    node.attributes[‘style’] = sanitize_css(node.attributes[‘style’])
    node.to_s.gsub(/</, “<“)
    node.to_s.gsub(/</, “<“)

    html = new_text

    … the main difference is the addition of “downcase” methods to the comparison lines.

    That’s it. Works great for me. Please let me know if this was helpful, or if you have a better way to achieve these results!

  • mcphersonz 7:22 pm on March 23, 2008 Permalink | Reply
    Tags: ActiveRecord, API, parse, PubMed,   

    Parse PubMed database using their API + ruby + ActiveRecord 

    In case any of you need to parse the PubMed database, here’s what I came up with as a first try. Run via a ruby script. You will need ruby, ActiveRecord (if you have rails setup, you should be good), and a few libraries — use gem install [x] for the libraries that you don’t have — if you have rails installed, you probably only need to get “xmlsimple”.

    gem install xmlsimple

    I used 3 tables in my mysql database: articles, authors, and a join table articles_authors

    Here’s the schema:

    DROP TABLE IF EXISTS `pubmed`.`articles`;
    CREATE TABLE `pubmed`.`articles` (
    `id` int(11) NOT NULL auto_increment,
    `pubmed_id` int(11) NOT NULL,
    `source` varchar(50) character set latin1 default NULL,
    `title` varchar(255) character set latin1 default NULL,
    `full_journal_name` varchar(255) character set latin1 default NULL,
    `author_list` varchar(255) character set latin1 default NULL,
    `pub_date` date default NULL,
    PRIMARY KEY (`id`)

    DROP TABLE IF EXISTS `pubmed`.`articles_authors`;
    CREATE TABLE `pubmed`.`articles_authors` (
    `article_id` int(11) NOT NULL,
    `author_id` int(11) NOT NULL

    DROP TABLE IF EXISTS `pubmed`.`authors`;
    CREATE TABLE `pubmed`.`authors` (
    `id` int(11) NOT NULL auto_increment,
    `name` varchar(255) default NULL,
    `pubmed_id` int(11) default NULL,
    PRIMARY KEY (`id`)

    Here’s the ruby script:

    # #!/usr/local/bin/ruby -w
    # Require Files & Libs
    require 'net/http'
    require 'rubygems'
    require 'active_record'
    require 'xmlsimple'
    # App Configuration Settings
    empty_tables = true
    # Search Settings
    searchRelDate = 7
    searchLimit = 100000
    batch_size = 100
    searchUrlBase = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmax=#{searchLimit}&"
    summaryUrlBase = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=xml&id="
    # Database Settings:
    db_host    = "localhost"
    db_user    = "root"
    db_pass    = "password"
    db_schema  = "pubmed"
    # Header Output:
    puts  "#"
    puts  "# PubMed parsing tool."
    dash = "========================================================================="
    # Connect to DB using Active Record:
    ActiveRecord::Base.establish_connection(:adapter=>"mysql", :database=>db_schema, :username=>db_user, :password=>db_pass, :host=>db_host)
    # Define SearchResults model:
    class Article < ActiveRecord::Base
      set_table_name "articles"
    class Author < ActiveRecord::Base
      set_table_name "authors"
    class ArticleAuthor  0
              property['Item'].each{|author| article[:authors] < "#{article_summary['Id']}",
            :source => article['Source'],
            :title => article['Title'],
            :full_journal_name => article['FullJournalName'],
            :pub_date => article['PubDate'],
            :author_list => article[:authors].join(', ')
          # Add Authors to database:
            # See if the author exists already:
            exists = Author.find_all_by_name("#{author}")    
            if exists.length == 0
              new_author = Author.create(
                :name => author,
                :pubmed_id => "#{article_summary['Id']}"
              new_author = exists[0]
            # Add to join table:
              :author_id =>  new_author.id,
              :article_id =>  new_article.id
      batch_current += 1

    From there, you can run queries like this:

    SELECT author_id, authors.name, count(author_id)
    FROM articles_authors, authors
    WHERE articles_authors.author_id = authors.id
    GROUP BY author_id
    ORDER BY count(author_id) desc

    SELECT articles.pubmed_id, authors.name, articles.title, articles.source, articles.pub_date, articles.id
    FROM articles_authors, authors, articles
    WHERE articles_authors.author_id = authors.id and articles_authors.article_id = articles.id
    and authors.name = “Li Y”
    GROUP BY articles.pubmed_id

    • Anonymous 3:25 pm on November 23, 2011 Permalink | Reply

      How do I get to the VIP section? I would like to talk about the 7 pm news if possible

    • Phoebe 2:49 am on February 25, 2013 Permalink | Reply

      Hi there, i read your blog occasionally and i own a similar one and i was just

      wondering if you get a lot of spam responses? If so how do
      you prevent it, any plugin or anything you can
      recommend? I get so much lately it’s driving me crazy so any assistance is very much appreciated.

    • http://www.fameb.ufba.br 7:40 pm on April 26, 2013 Permalink | Reply

      I’m still learning from you, but I’m trying to reach

      my goals. I certainly liked reading everything

      that is written on your website.Keep the aarticles coming.
      I liked it!

    • isabella 6:29 am on May 6, 2014 Permalink | Reply

      I’m planning to create my own blog, and a question comes up to my mind..

  • mcphersonz 9:10 pm on October 9, 2007 Permalink | Reply  

    Pure ruby CRON jobs on rails. 

    I found a post by “Loren Johnson” that had code that worked well for me:

    rails test
    sudo gem install daemons
    cd test
    ruby script/plugin install http://svn.kylemaxwell.com/rails_plugins/daemon_generator/trunk
    ruby script/generate daemon tester

    First off, check out the (brief) Daemon Generator readme file.

    Open up the file that was generated from the “generate” command above:
    It’s short — take a look. This is where your custom stuff will added. More on that later.

    Open up your /log/xyz.log file (development.log, production.log, etc) — it should have a message like this: This daemon is still runnig at Tue Oct 09 13:43:38 -0700 2007.

    …That was inserted by a function stub created within tester.rb.

    Change tester.rb to do something useful… As a simple example, I changed the line in tester.rb from:
    ActiveRecord::Base.logger << “This daemon is still running at #{Time.now}.\n”
    ActiveRecord::Base.logger << “Disk space free: “+`df -hl | grep /dev/sda2`+”\n”

    ….. you get the idea.

    NOTE that changing the code within the file tester.rb does not take effect until you restart the daemon: ruby script/daemons restart


    • TylerMontgomery 5:06 pm on December 6, 2007 Permalink | Reply

      Thanks for the quick tutorial on this! I got cron like stuff and running in like an hour.

      I commented at Douglas Shearer’s blog too and noticed you posted a comment about not being able to do any time based functions – I got it setup to send me an email every 12 hours detailing my registered users for my site – I can send you my code if you want…


  • mcphersonz 6:09 am on October 9, 2007 Permalink | Reply  

    Ruby LDAP Authentication with net/ldap 

    I’m working on a Rails project that requires LDAP authentication.

    I searched the net for a long time, but finally got something to work for me.

    …  just use your own username, password & hostname.

    Note that the username and password should be contained in SINGLE QUOTES unless you have some reason to use double quotes…. that messed me up for a while.

    require ‘rubygems’
    require ‘net/ldap’

    user = ‘DOMAIN_NAME\my_username’
    pass = ‘my_password’
    ldap = Net::LDAP.new :host => “x.x.x.x”, :port => 389, :auth => {:method => :simple, :username => user, :password => pass}
    p (ldap.bind) ? “Authorization Succeeded!” : “Authorization Failed: #{ldap.get_operation_result.message}”

    • Andy 5:02 pm on September 28, 2010 Permalink | Reply

      Wow… That is strange. Thanks for the help, though!

      • Andy 5:07 pm on September 28, 2010 Permalink | Reply

        Ahh, it’s obvious! In double quotes you’d need to escape your backslash.


    • ashikin 5:20 pm on June 10, 2015 Permalink | Reply

      hi,can i ask you,where you put this code in your app?

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc