February 26, 2008 at 8:37 pm
· Filed under ruby
What else?
(Note: Charles Oliver Nutter is helping when he tells us that Thread#raise, Thread#kill, and timeout.rb are broken.)
Permalink
February 21, 2008 at 9:36 am
· Filed under pyre, ruby
I’ve released version 0.3.0 of Pyre, an alternative ruby library for interacting with Campfire from 37signals. Pyre now supports uploading files to a room! Observe:
require ‘rubygems‘
require ‘pyre‘
Pyre::Campfire.new(’pyre‘) do |campfire|
campfire.login(’bot@seriouslyreal.com‘, ‘12345‘)
campfire.room(’Hot Chat‘) do |room|
room.upload(’/path/to/animated.gif‘)
room.speak(’What a cat!‘)
end
end
Also, now there’s a contrib directory which will hold examples of things to do with Pyre. Currently, the only thing in there is a Subversion repository post-commit hook for putting really nice messages about commits into a Campfire room. It’s really nice. Out of the box they look like this:
cms commited revision 104
*************************
Fixed all spelling mistaeks in the README
*************************
U pyre/trunk/README
I’m hoping to expand that contrib dir. I’m hoping people will help too.
Anyway, get it and use it.
sudo gem install pyre
Permalink
February 17, 2008 at 7:21 pm
· Filed under pyre, ruby
I’ve recently had reason to use 37signals’ Campfire, and thus a need for a Campfire bot. Tinder does a fine job, but I was running into issues (minor annoyances), so of course I decided to write my own library for interacting with Campfire.
And Pyre was born.
As of right now, you can log in, log out, join and leave rooms, speak and paste to rooms, and that’s it. But for something like a svn post-commit hook, that’s all you need. Pyre uses Mechanize (as opposed to Tinder’s ActiveSupport, Hpricot, and regular expressions combo) to deal with Campfire, so it was pretty easy to throw together.
Sample code? Here’s what the end of an svn post-commit hook might look like (after the message has been built):
Pyre::Campfire.new(’subdomain‘, :ssl => true) do |campfire|
campfire.login(’bot@email‘, ‘botpassword‘)
campfire.room(’Development‘) do |room|
room.paste(message)
end
end
Pretty straightforward.
For the most part I tried to stay close to Tinder’s interface so that porting to Pyre would be easy, but this block style is new (and, I think, nice).
I’ll be implementing listening in a room soon enough I wager.
So go ahead and get it!
sudo gem install pyre
Permalink
February 11, 2008 at 10:02 pm
· Filed under ruby
I finally ponied up the meager $100 for my spot at MountainWest RubyConf. Last year was good, and it looks like this year will be better. Pat Eyler says, “One of the sponsors has let me know that they’re planning something really special for attendees.” I’m looking forward to receiving this “special” mousepad. (It’s going to be a mousepad, right?)
If you need to harass me in person about how GuessMethod and CSSes aren’t suited for production, I’ll be wearing two hooded sweatshirts and a Baltimore Orioles cap. See you there.
Permalink
January 3, 2008 at 11:28 am
· Filed under csses, rails, ruby
Update: CSSes is now a gem! No need to install the plugin for each app.
I’ve updated CSSes to handle a bunch more Rails HTML helpers, so your forms and images and links should all get the proper treatment and their own nicely alphabetized entries in the generated application.css file.
See it in action!
Say you have this view (though let it be known that CSSes scours your helpers, too):
<h1 id="pomp">The Grand Demonstration</h1>
<p class="wing">Super Mario Bros. 3 reference</p>
<%= image_tag('joy.png', :class => 'happy') %>
<%= link_to('Read', {:action => :read, :id => 4}, {:id => 'four'}) %>
<!-- and it works for form tags too -->
Do this:
script/generate csses
And look at that sweet generated application.css:
a {}
a:visited {}
a:hover {}
a:active {}
a#four {}
a#four:visited {}
a#four:hover {}
a#four:active {}
h1 {}
h1#pomp {}
img {}
img.happy {}
p {}
p.wing {}
Get it for yourself:
sudo gem install csses
Permalink
December 31, 2007 at 12:40 am
· Filed under csses, rails, ruby
I try to follow some good guidelines when developing a website. I separate content from style with CSS, for example, by judiciously using class and id attributes for html elements. Of course, I also usually leave the styling until the content has been mostly completed. The problem with that, though, is I end up with many views and many helpers that reference class and id attributes for elements I haven’t styled yet.
So I made CSSes. It searches helpers and views (you’re not putting style information in your controllers or models are you?) for references to html entities, and creates a bare-bones CSS file.
It has a few shortcomings. It doesn’t yet handle link_to* or image_tag or any of the form building methods, just raw referenced html. It’s only Rails 2.0.x friendly so far. It makes just one file, public/stylesheets/application.css, and you can’t control the name. If you use the < character in html attribute values, it will probably make a little noise. It doesn’t have any unit tests.
But! It was sure nice to run after working on a site for a while and finding this waiting for me:
body {}
div {}
div#author_bio {}
div#author_url {}
div#chapbook_exceprt {}
...
div.chapbook_links {}
div.poem_content {}
div.poem_links {}
...
h1 {}
h1#author_name {}
h1#chapbooks_header {}
...
Get it:
sudo gem install csses
Run it:
script/generate css
Any help at all would be greatly appreciated; it’s pretty raw. But I plan on making it more robust and more fun.
Update!: We’ve got tests, automatic anchor tag pseudo-classes, and basic link_to* and image_tag support (figuring out how to handle class and id attributes in rails helpers is a little trickier than I guessed at first). AND: it’s a gem now.
Permalink
December 24, 2007 at 2:06 pm
· Filed under ruby
According to Matz, Ruby 1.9.0 will be released today (relatively). The expected time is 3pm JST on 12/25, which is 1am EST on 12/25. I’ll be staying up until 11pm MST today (12/24) (where I am), hoping it gets released on time. All incompatibilities with 1.8.6 will be finalized, but it’s not as stable as hoped. Nonetheless, I’m jazzed. I’ve been playing with the 1.9.0 trunk, enjoying the changes and YARV’s speed.
Here’s the bash script I’ve been using to update my 1.9 install (taken mostly from one I saw somewhere, but can’t find now). I’ll probably be using it to keep tracking trunk.
#!/bin/bash
set -e
RUBY19_DIR=~/dev/ruby19
cd ${RUBY19_DIR}
svn up
VERSION=`grep 'RUBY_VERSION ' version.h | awk '{print $3}' | sed -e's/"//g'`
SUFFIX=`grep RUBY_RELEASE_CODE version.h | awk '{print $3}'`
echo "Building ${VERSION}-${SUFFIX}"
./configure --prefix=/usr/local --program-suffix=19 --with-readline-dir=/usr/local
make
sudo make install
exit 0
Permalink
December 13, 2007 at 1:04 am
· Filed under rails, GuessMethod, irb, ruby
I was looking at the code for Giles Bowkett’s utility_belt gem, and came across something I wish I had known about ages ago. There’s a way to execute some code in an .irbrc after everything else when the irb session starts (technically, when the context changes). The problem with GuessMethod and Rails was that GuessMethod can’t load first. Problem solved.
So now my .irbrc has this line to include GuessMethod in a way that works with script/console:
IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }
Of course, if you’re using that IRB.conf[:IRB_RC] for something else (like using utility_belt), something’s going to overwrite something.
Anyway, I’ve finally just given up and wrapped my entire .irbrc in a big unless:
unless $0 == 'script/server'
I’m confused as to why script/server loads .irbrc for every request, but at least this mitigates that issue a bit. (As an aside, can someone tell me why it does that?)
Permalink
December 7, 2007 at 12:41 pm
· Filed under ruby
For those, like me, who missed RubyConf this year, Confreaks have (finally) put up (most) of the videos.
The Reject Conf videos have been up for weeks.
Permalink
December 6, 2007 at 4:39 pm
· Filed under GuessMethod, ruby
I was talking yesterday to Corey (of mini-magick fame) and he suggested something for GuessMethod. I implemented it and sent him an instant message demonstrating such. He said, “Oh yeah! I totally want this. This will enrage so many people! I love it.”
What is it? GuessMethod for Rake.
mvb:~/hot-rails-app cms$ grake db:migrat
(in /Users/cms/hot-rails-app)
attention: invoking task db:migrate instead of db:migrat
…
You can use your new grake command, or add require 'guessmethod/rake' to your rakefiles for this functionality. This is probably ten times more dangerous than plain old GuessMethod. Please, oh please, don’t use this in production.
Otherwise, things are pretty much the same:
001:0> Strin.tos
attention: replacing non-existant constant Strin with String for Object
attention: sending to_s instead of tos to String:Class
“String”
Get it:
sudo gem install guessmethod
Permalink