Tagged "sinatra"
-
-
Keep reading →
Pow! etc.
It seems as if a few colleagues might need to use that little Sinatra-based reclassifier ditty, which is always a nice thing: The first iteration of these things usually seems to come close to breaking even on time saved if I just use it once, but if I can make the same tool available to one or two more people, then it's a lock to earn the development time back and start saving a lot of time.
The problem with sharing stuff like Rails and Sinatra is deployment. Easy for me to set something up on my desktop that never seems to leave dev mode, but less of a pleasure to get it working for others, especially on shared hosting.
Several things will help with that:
First, Pow! from 37 Signals makes it easy to create a local development domain for webapps that use Rack. You just install it, create a
config.rufile for your app in its directory, then symlink the app directory to~/.powand it becomes available athttp://yourappdir.dev. Besides being a great way to work on a number of webapps in parallel, it's a nice way to practice dealing with Rack.Second, it looks like it's not too hard to use those Rack-enabled apps on Dreamhost. This worked for my
config.rufile, and it's the same as the one I use for my desktop machine:Third, it's not too hard to add http authentication to a Sinatra app. That means I can deploy little apps that don't require a robust user model to a subdomain and protect them for as long as they need to be up, which is just a day or two. Here's all I had to add to the top of my app file to get http authentication:
This all makes me think back to 2008, when I wrote about my recent discovery of Rails: The combination of Sinatra, Pow! and Rack does even more to provide me with a comfortable replacement for lightweight databases, and makes it much easier to share my work, which is even better.
#37signals #dreamhost #pow #rack #ruby #sinatra
-
Keep reading →
Sinatra ftw (Updated)
So, I have this task to accomplish:
I've got 1,180 articles that were all placed in a website directory I no longer want to keep. The friendly dbas gave me an Excel spreadsheet showing me each article's title, url, pub date, author and current directory. I'm to go down the list and reassign each article.
I made it through 15 entries before realizing it's hard to tell what an article's about from just the headline. Some things look like tutorials, but they're reviews, some things look like reviews, but they're analysis. I can either guess, or I can copy the URL, flip to my browser and load the article then decide how to classify it. This process sucks:
- Copying and pasting URLs is a drag
- Waiting for articles to load if an element on the page hangs is a drag
- Entering stuff in an Excel spreadsheet is a drag
So I gathered together a few tools:
- Sinatra, which is a Ruby micro-framework for Web apps
- Blueprint CSS, which is a CSS framework for quick/easy pretty (or at least not awful) HTML
- Summarize, a gem that can take a bunch of text and return the relevant parts for a given percentage of the original
Then I set up a sqlite database & fed the Excel spreadsheet into it and sat down with Sinatra.
Here's the finished app (minus the one template page I use):
It's missing some affordances, but the long and short is demonstrated here:
You start with a given article. It shows you the headline, pub date and author. Using the summarizer gem, it pulls in a summary representing 25 percent of the total text. You pick a new category for it from the radio buttons, click "Reclassify," and it takes you to the next record (unless you're done, in which case it just reloads the current record.
The time gain? I dunno. If I worked like a machine, I'd probably be done in four hours. Now it takes less time to update a record and I don't have to do as much to update it: Just click a radio button, click a submit button, move on. Even if it turns out the time I save is offset by the coding time (two hours, with a break for coffee, chatting, answering mail), I guess I figured out a way to spend some time that would be wasted screwing with Excel getting to play with Sinatra. And since I'm going to have to do the same task in a few weeks for another site, I'll have time-saving code ready to go.
Update: Even better with a bit of jQuery: Rather than loading the article summary every time (even though I don't always need it to tell what kind of article I'm dealing with), I wrote an additional route that handles providing just the summary and used jQuery's load function to pull in the summary for review when I click on a "load summary" button. That makes things a lot faster when I can tell what an article is just from the headline.
Update2 : Sinatra uses Mongrel by default, which is fine, except I noticed that every now and then a page load would go from taking an average of a fifth of a third or so to five seconds. Meh. So I
sudo gem install thin'd the thin gem, and got much more consistent, snappy performance. -
-