Rojo: An easy to install Ruby on Rails CMS

February 8th, 2010

Rojo is Onomojo’s Ruby on Rails Content Management System. You can find it here:

http://github.com/onomojo/rojo

Today we made some changes to make the initial setup of a Rojo instance easier. The steps to setup a new Rojo instance are clearly detailed in the README. This should help eliminate most of the problems new users were encountering when trying to setup Rojo from scratch. Please let us know if you have any comments or suggestions for improving the setup process.

In the next few weeks, we will be releasing the plugins that we’ve developed for Rojo including a blog, video gallery, photo gallery, and more so stay tuned.

GitHub down yet again

February 2nd, 2010

I am experimenting with a new Engine Yard account today and their Setup basically requires you to have your projects in git. Since the site was from a private svn repos I decided I’d go ahead and signup for a paid Github account so I can host my projects there privately instead of having to setup my own git server. I should have trusted my gut because not more than a few hours later here I am trying to access my Github account and the site is broken again.

Rojo – A Ruby on Rails CMS

January 31st, 2010

Rojo logo

We’ve been working on this part time for a while now and I finally decided to just go ahead and release it. Its far from perfect and isn’t what I originally envisioned but it does work and we do use it on a number of sites. Its fairly stable and we have a handful of plugins that I’ll be releasing in the next week or two.

The 2 main motivations for Rojo came from the lacking diversity in Ruby on Rails content management systems. There are a few and some work well but I wasn’t happy with the learning curve with the ones I explored when we initially started this project. It seemed to me that every time I embraced a CMS the CMS ended up determining how I had to write my application. Its simply impossible to craft a CMS that enforces a strict data and programming interface that works for every situation. I didn’t want a content management system that forced me to write my tables one way or another or forced me to communicate with the CMS in certain ways. In short, I really just wanted a simple core that I could easily extend in any way I needed without having to conform to any standard imposed by the CMS.

You can check out the Rojo code here: http://github.com/onomojo/rojo

Rails threading with Spawn plugin

December 8th, 2009

My previous post was about using Thread in Rails which simply doesn’t work properly when you’re doing anything with ActiveRecord despite what anyone else is claiming.

This post will focus on my second attempt at a solution to intra-request threading in Rails. Basically, I have a Rails app where I want to run multiple computations at the same time. Since I had problems with Ruby’s native Thread method previously, I had no intention of going down that route again. I decided to try out the Spawn plugin.

Spawn was able to successfully segregate my multiple threads, or forks in my case. This got around the MySQL errors I reported in my previous post but it created a whole new set of problems all its own.

The first problem I had was that the spawn forks I was creating weren’t able to communicate their changes back to the main Rails request. I was creating forks and they were running fine and even saving data via ActiveRecord. I could confirm this via the console. The problem was that I need to know what data was being written by the spawn forks inside of the main Rails request. It was as if the main Rails request didn’t even know that something new was written to the database. I was able to get around this by forcing a reload from the database on the object I was trying to get association data from.

No big deal and it seems to make sense to do that anyway. That’s not where the real problem occurs though. After I got past that I realized that since each fork was essentially using a ‘copy’ of the database and not actually live connections that the data validations randomly failed. Basically if two forks are writing data to the database at the same time when there is a validates_uniqueness on the data. They both write to the database and both actually pass validation. The result is a database full of incorrect data which should have never passed the validation. I’m still not sure if that’s a problem with Spawn or an inherent problem with ActiveRecord’s connection pool.

Fun with Rails ActiveRecord and Ruby’s Thread

December 8th, 2009

I’ve been working on threading a Rails application lately and after reading headlines like ‘Rails is thread safe’ I figured how hard could it be. My first discovery was that when people talk about Rails and threads there are two different types of threading in Rails.

      Multiple request threading – This is where Rails itself threads among different requests to your web server and allows ActiveRecord to behave properly without having to keep a copy of Rails in memory for each request.
      Intra-request threading – This is where you have 1 request to your web server and inside the action you want to create multiple threads that run concurrently.

I’ll be talking about Intra-request threading. In particular, I want my threads to execute some code, read and write to the database, and play nicely with each other. My first attempt was to use the Ruby Thread method. This seemed to work somewhat until I started seeing strange errors coming in from MySQL. The problems seemed to occur randomly and what I determined was that the threads were trying to write to the database at the same time which ended up causing some collisions of sorts resulting in ‘lock wait timeout exceeded’ errors.

After considerable Googling, I found numerous posts about setting:

ActiveRecord::Base.allow_concurrency = true

The problem with that is that this is deprecated in the newest version of Rails in favor of connection pooling.

The short answer: Don’t use the Ruby Thread method within Rails when doing anything with ActiveRecord.

Why the open source community needs to rethink migrating to Github

November 24th, 2009

Here I am yet again at a standstill because the Rails gems have mostly all migrated to Github and the site is down. This is the second or third time this year that Github has messed up and caused me to stop dead in my tracks because I couldn’t access the gems I needed. I can’t even remember the last time my subversion repository went down. This is exactly the reason I thought the Rails community was crazy for mass migrating to Github. Its just not a good idea to have 1 centralized location responsible for all your gems. Especially when they go down all the time. What we need is a company with experience maintaining quality uptime to manage this site in the short term and in the long term we need a more distributed mirror type system to roll-over when Github dies again.

Github down again

Github down again

AOL support for Rails contacts gem

November 18th, 2009

I’ve just finished adding AOL support to the Rails contacts gem. You can check out my code here: http://github.com/onomojo/contacts-gem

Until this is officially added to the contacts gem release, you’ll need to create a RAILS_ROOT/lib/contacts/aol.rb file with the following contents:

class Hash
def to_query_string
u = ERB::Util.method(:u)
map { |k, v|
u.call(k) + “=” + u.call(v)
}.join(“&”)
end
end

class Contacts
require ‘hpricot’
class Aol < Base
URL = "http://www.aol.com/"
LOGIN_URL = "https://my.screenname.aol.com/_cqr/login/login.psp"
LOGIN_REFERER_URL = "http://webmail.aol.com/"
LOGIN_REFERER_PATH = "sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=0&siteState=ver%3a4|rt%3aSTANDARD|ac%3aWS|at%3aSNS|ld%3awebmail.aol.com|uv%3aAOL|lc%3aen-us|mt%3aAOL|snt%3aScreenName&offerId=mail-second-en-us&seamless=novl&xchk=false"
# http://webmail.aol.com/28878/aim-2/en-us/Suite.aspx
CONTACT_LIST_URL = "http://webmail.aol.com/28878/aim-2/en-us/Lite/ContactList.aspx?folder=Inbox&showUserFolders=False"
CONTACT_LIST_CSV_URL = "http://webmail.aol.com/28878/aim-2/en-us/Lite/ABExport.aspx?command=all"
PROTOCOL_ERROR = "AOL has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts"

def real_connect

postdata = {
"loginId" => login,
“password” => password,
“rememberMe” => “on”,
“_sns_fg_color_” => “”,
“_sns_err_color_” => “”,
“_sns_link_color_” => “”,
“_sns_width_” => “”,
“_sns_height_” => “”,
“offerId” => “mail-second-en-us”,
“_sns_bg_color_” => “”,
“sitedomain” => “sns.webmail.aol.com”,
“regPromoCode” => “”,
“mcState” => “initialized”,
“uitype” => “std”,
“siteId” => “”,
“lang” => “en”,
“locale” => “us”,
“authLev” => “0″,
“siteState” => “ver%3A4%7Crt%3ASTANDARD%7Cac%3AWS%7Cat%3ASNS%7Cld%3Awebmail.aol.com%7Cuv%3AAOL%7Clc%3Aen-us%7Cmt%3AAOL%7Csnt%3AScreenName”,
“isSiteStateEncoded” => “true”,
“use_aam” => “0″,
“seamless” => “novl”,
“aolsubmit” => CGI.escape(“Sign In”),
“idType” => “SN”,
“usrd” => “4222992″,
“doSSL” => “”,
“redirType” => “”,
“xchk” => “false”
}

# Get this cookie and stick it in the form to confirm to Aol that your cookies work
data, resp, cookies, forward = get(URL)
postdata["stips"] = cookie_hash_from_string(cookies)["stips"]
postdata["tst"] = cookie_hash_from_string(cookies)["tst"]

data, resp, cookies, forward, old_url = get(LOGIN_REFERER_URL, cookies) + [URL]
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

doc = Hpricot(data)
(doc/:input).each do |input|
postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == “usrd”
end
# parse data for
and add it to the postdata

postdata["SNS_SC"] = cookie_hash_from_string(cookies)["SNS_SC"]
postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"]
postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"]

data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]

until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

if data.index(“Invalid Screen Name or Password.”)
raise AuthenticationError, “Username and password do not match”
elsif data.index(“Required field must not be blank”)
raise AuthenticationError, “Login and password must not be blank”
elsif data.index(“errormsg_0_logincaptcha”)
raise AuthenticationError, “Captcha error”
elsif data.index(“Invalid request”)
raise ConnectionError, PROTOCOL_ERROR
elsif cookies == “”
raise ConnectionError, PROTOCOL_ERROR
end

@cookies = cookies
end

def contacts
postdata = {
“file” => ‘contacts’,
“fileType” => ‘csv’
}

return @contacts if @contacts
if connected?
data, resp, @cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]

until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end

if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end

# parse data and grab
doc = Hpricot(data)
(doc/:input).each do |input|
postdata["user"] = input.attributes["value"] if input.attributes["name"] == “user”
end

data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]

parse data
end
end
private

def parse(data, options={})
data = CSV.parse(data)
col_names = data.shift
@contacts = data.map do |person|
["#{person[0]} #{person[1]}”, person[4]] unless person[4].empty?
end.compact
end
end

TYPES[:aol] = Aol
end

I’ve submitted the source to the authors so it should be added in the next few weeks.

Google is better than Bing for programming related searches

November 13th, 2009

I’ve been writing a lot about how great Bing is and made the switch to use Bing regularly but here I am in day 1 with using Bing full time and have run into problems. I am working on a Rails project doing some http requests and screen scraping. Basically, I’m extending the contacts gem to include AOL support. I wanted to see a quick reference to refresh my memory on the get / post syntax in Rails. I search Bing for “rails get http” and the first result is a link to rubyonrails.org. How useless. I search the entire first page and find absolutely nothing related to what I’m looking for. I’m beginning to second guess my previous whole-hearted support of Bing. Its good for general searches but it seems program related searches are crap with Bing. I do the same search in Google and the first result is what I wanted. Just a quick reference of someone using the Ruby get method. I tried a few other searches like ‘rails contacts gem’ and Bing doesn’t really give me much to work with in the results. I did have to dig down to the 8th result with Google but the Rails contacts gem project page is at least on the first page of the search results. Google wins when it comes to programming related searches in my opinion. Time for me to switch back to Google for the time being.

Bing Firefox add-on

November 12th, 2009

I’ve made the switch to Bing as my default browser in Firefox. It doesn’t come as an option with Firefox but there is an add-on you can easily install to add support for Bing in the Firefox search bar. Finally, some competition in search and finally Microsoft releases a quality web application. You can get the add-on here: https://addons.mozilla.org/en-US/firefox/addon/10434

Bing is beating Google

November 11th, 2009

I’ve long been anti-Microsoft migrating first to Linux and then to Mac OSX. I’ve been using OpenOffice since the days it was first released (remember Star Office?). I used Mozilla long before Firefox every came out and even stopped supporting some older versions of IE with Onomojo. Needless to say, Microsoft would have to do something extremely well to catch my eye and even more so to actually get me to use it.

I have a confession to make. I’ve been using Microsoft’s Bing search engine more and more lately. I feel my results are more relevant and less spammy. It seems these days 5 out of the 10 search results on Google are simply screen scrapers reposting content and dumping Google Adwords all over the place. Of course Google is going to rank those higher simply in the name of profits. They of obviously will never admit to that though but think about it. If they generally rank sites with Adwords on them higher, they can make a significant more amount of money per day. Its hard to believe any corporation would ignore that fact. Certainly, a publicly traded company is at the mercy of shareholders who are only interested in the pursuit of more profits. With that being said, Google still has to maintain credibility in its search results so the same game applies but I simply refuse to accept the idea that Google doesn’t inflate rankings of sites that use Adwords onsite. Just do a few random searches and you’ll see what I mean.

I’ve been finding that Microsoft’s Bing search engine is pulling more relevant results and less junk results than Google. I don’t have any data to back that up. Its just my general perception of the results. One thing I really like is Bing’s image search. It does an Ajax call to keep the page scrolling down so you never have to click on the next page. Hover over an image and it magnifies it some with details. All in all, Microsoft is onto something good with their Bing search engine. I think its going to be a major competitor within the next year. I’ve already noticed that I go to Bing first for some types of searches.

People are trendy. They like the latest trends and naturally migrate towards trendy sites. Bing will win more and more search traffic if Google doesn’t up their game. Google long ago stopped actually innovating and instead went into operational mode since there’s no real competition out there. They’ve just been trying to position themselves to maintain that dominance without actually bringing anything new to the table. Bing is coming out swinging. Its only been a few months since it went live and its already making converts out of long time anti-Microsoft people like myself. In my opinion, that says a lot both about the technology behind Bing and the lack of innovation from Google. Take it for what its worth.