Archive for the 'Ruby on Rails' Category

Rojo – A Ruby on Rails CMS

Sunday, 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

Tuesday, 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.

Why the open source community needs to rethink migrating to Github

Tuesday, 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

Wednesday, November 18th, 2009

I’ve just finished adding AOL support to the Rails 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:

[source language=":ruby"]
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 <input name="usrd" value="2726212" type="hidden"/> 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 <input name="user" value="8QzMPIAKs2" type="hidden"/>
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
[/source]

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

UPDATE: My changes have been merged into the trunk.

Google is better than Bing for programming related searches

Friday, 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.

The World’s Oyster screencast

Saturday, September 5th, 2009

Here is Micah Friedline with another screencast. This time it’s about The World’s Oyster, a self-updating address book. Stay in touch with friends, business contacts, and more with the easy to use address book that keeps itself updated as you move.

Webster’s Classroom screencast

Saturday, September 5th, 2009

Here is a screencast our account manager, Micah Friedlin, made introducing you to Webster’s Classroom. Webster’s Classroom enables teachers to create free classroom webpages. We just recently upgraded the site to include some new features including password protection, classroom archiving, file dropbox, and more. There were numerous bug fixes and security enhancements made as well.

The World’s Oyster

Thursday, August 20th, 2009

Its been a long year and I’ve had very little time to keep things updated around this site but here’s a preview of something we’ve been working on with a client. Its a self updating address book so you never lose track of your contacts when their information changes. Signup, try it out, and let us know if you have any ideas for improving it.

The World’s Oyster

Hiring full time Rails developers

Thursday, February 19th, 2009

My company Onomojo, http://onomojo.com , is searching for a few quality Rails developers to bring onto our team. You need to have some experience under your belt and have urls to show for yourself. You must develop on a Mac or Linux. Windows users need not apply. This is a telecommute position but ideally you’d be located either in Hawaii or North Carolina. If you’re interested, please send your desired salary, date you can start, and your resume to hr at onomojo dot com

Rojo – An open source Ruby on Rails CMS

Saturday, February 7th, 2009

I’ve been planning out a content management system in Ruby on Rails for a while now and will be releasing a beta version in the next few weeks. I’m calling the project Rojo. There are quite a few CMSs out there for PHP already and they’re quite mature at this point but the ones I’ve seen for Rails are pretty pathetic to say the least. They’re all really limited in functionality and lack modularity so they’re not always the easiest to extend.

My company, Onomojo, does a decent amount of Ruby on Rails development and have been working on building a solid CMS that’s modular, easily extended, and easily customized. The project itself is coming along nicely. I’ve taken concepts that I like from different content management systems that I’ve used over the past decade and combined them in a way that helps minimize the effort involved in developing Rails sites for our clients. I’m pretty excited about it and I’ll be releasing the core code and the plugin code to the public after we get a few pieces developed so stay tuned for more on Rojo.