Posted by hank,
Mon Mar 19 15:35:00 UTC 2007
I wanted to be able to click a link in my email to see the comment it talked about. So, I modified Luke Redpath’s Comment Notification Plugin to give that to me. First, I had to do some script/console action:
>> s = Site.find_first
=> #<Site:0xb747e014 @attributes={"current_theme_path"=>"wibbish-mephisto",#...
#...
>> s.host='www.ralree.info'
=> "www.ralree.info"
>> s.save
=> true
>> quit
Next, I did a small model modification:
# app/models/article.rb, in the public section
def full_external_link
["http://", site.host, full_permalink].join("")
end
And a slight test:
Loading production environment.
>> Article.find_first.full_external_link
=> "http://www.ralree.info/2006/5/21/first-post-what-to-say"
Perfect!
Then, I just modified the view for the email a bit:
# vendor/plugins/mephisto_comment_notification/lib/views/
# comment_notifier/comment_notification.rhtml
A new comment has been posted on your blog for the article '<%= @comment.article.title %>' by <%= @comment.author %> (<%= @comment.author_email %>):
<%= @comment.article.full_external_link %>
The commenter IP address is <%= @comment.author_ip %>.
Here is the comment that was posted:
"<%= @comment.body %>"
This notification was sent using the Mephisto Comment notification plugin by Luke Redpath.
http://opensource.agileevolved.com/svn/root/rails_plugins/mephisto_comment_notification/trunk
Modified awesomely by Erik Gregg (http://www.ralree.info)
And it’s magic! It totally works!
Tags: mephisto plugins rails ruby
Posted by hank,
Tue Feb 27 14:56:00 UTC 2007
My solution to this problem:
(1..100).each do |i|
puts i%3==0 && i%5==0 ? "FizzBuzz" : i%5==0 ? "Buzz" : i%3==0 ? "Fizz" : i
end
This should be trivial for just about any programmer. Took me 40 seconds or so.
Tags: money resume ruby ternary work
Posted by hank,
Sun Feb 25 19:29:00 UTC 2007
So, I figured I might as well provide a quick tutorial on how to make Mephisto Plugins currently. Many of the old plugins are broken, so there needs to be a resurgence of plugin development. Here’s the basic structure of the Tag Cloud plugin:
mephisto_tag_cloud
- init.rb README
- lib
- mephisto_plugins
- tag_cloud.rb
As you can see, the structure is very simple. Here’s my code for init.rb
Liquid::Template.register_filter(MephistoPlugins::TagCloud)
That’s it! No require or anything! Next, I edited lib/mephisto_plugins/tag_cloud.rb:
module MephistoPlugins
module TagCloud
def size_tag(tag, largest = 2)
size = (Tag.find_by_name(tag).taggings(true).length + 18).to_f / 18
size = largest if size > largest
"<span style='font-size: #{size}em'><a href='/tags/#{tag}'>#{tag}</a></span>"
end
end
end
Holy crap that barely any code at all! So, the moral of the story is that it’s very easy to make the plugins once you figure out what to do.
Tags: howto mephisto plugins rails ruby tutorial
Posted by hank,
Sun Feb 25 06:15:00 UTC 2007
Because the French one disappeared off the face of the earth, I took it upon myself to make a tag cloud Liquid plugin. Here’s the scoop. I downloaded Rick’s MeasureMap Plugin and went to town converting it.
Add this to your sidebar in your liquid template of choice:
{% for tag in site.tags %}
{{ tag | size_tag }}
{% endfor %}
And you should have some awesome tag_cloud action. You can specify an upper limit as well:
{{ tag | size_tag: 3 }}
That code allows for up to 4em font size. I don’t recommend this because it’s ludicrous. The default upper limit is 2em, which makes the font size range between 1em and 2em. Suggestions are welcome.
Get it here:
svn co https://modzer0.cs.uaf.edu/repos/hank/code/rails/mephisto/mephisto_tag_cloud
Or install it like this:
./script/plugin install https://modzer0.cs.uaf.edu/repos/hank/code/rails/mephisto/mephisto_tag_cloud
Works for me - let me know if you have any difficulties.
Update: French one re-appears!
Well, he’s back. It was down a while back. You can see his version here. I like mine better. :P
Update: Better SELECT Statement
Thanks to Todd for pointing out that the tags were applying to not only published articles, but drafts as well, which produced false tag counts. He also pointed out that they were applying to revisions, which was unacceptable. I think I fixed the problems using some straight up SQL:
def size_tag(tag, largest = 2, smallest = 0.5)
number = ActiveRecord::Base.count_by_sql(
["SELECT COUNT(*) FROM taggings,
tags, contents WHERE
tags.name = ? AND taggings.tag_id = tags.id
AND contents.id = taggings.taggable_id
AND contents.published_at IS NOT NULL;", tag])
size = sprintf("%0.2f", number.to_f / 5)
size = size.to_f > largest ? largest : size.to_f < smallest ? smallest : size
This is simple - I’m just adding some conditions that filter unpublished articles and revisions (which I don’t think actually appear in the contents table anyway). In a test, the linux tag returned 35 results the old way, 34 without the checking of published_id, and 33 as it is above. I think it’s filtering, but Todd will have to confirm this.
Tags: liquid mephisto plugins rails ruby
Posted by hank,
Sat Feb 24 08:07:00 UTC 2007
So, a problem with MySQL (in my opinion) is that it is not case sensitive by default for VARCHAR fields. That makes getting rid of crappy entries like ’ITALY’ a bother. I mean, sure, I could just post-process it with ruby (see titleize), but what’s the fun in that.
select distinct BINARY(lead_country) from countries;
Ah, finally recognizes that ITALY is not Italy. One is definitely uglier than the other one. Now for the change.
update countries set lead_country = 'Italy' where lead_country = "ITALY";
Much better.
Tags: mysql rails ruby sql
Posted by hardwarehank,
Mon Feb 19 23:37:34 UTC 2007
Now, you can see all the cheesy goodness at Cheesetoast.org. Have fun!
Tags: food rails ruby tasty toast
Posted by hardwarehank,
Fri Feb 16 00:32:55 UTC 2007
URI::InvalidURIError (bad URI(is not URI?):
'http://www.ipnlighting.com/images/wasted.jpg'):
/usr/local//lib/ruby/1.8/uri/common.rb:432:in `split'
/usr/local//lib/ruby/1.8/uri/common.rb:481:in `parse'
#...
I couldn’t get it to work!
Wait…
Parameters:
{"photo"=>{"url"=>"'http://www.ipnlighting.com/images/wasted.jpg'"},
"action"=>"new", "controller"=>"photos"}
Of Course!
curl -i -X POST -d \
"photo[url]=http://www.ipnlighting.com/images/wasted.jpg" \
http://localhost:3000/photos/new
All better!
Tags: curl rails rest ruby
Posted by hardwarehank,
Wed Feb 07 20:30:50 UTC 2007
Flash!! Zoom!!
!!!
%html
%head
%link{ :rel => "shortcut icon", :href => "/favicon.ico", :type => "image/x-icon"}/
%title= "Wallpaper Love Factory :: "+controller.controller_name.capitalize
= stylesheet_link_tag 'wallpaper'
%body
.header#header
= render :partial => 'layouts/header'
.menu#menu= render :partial => 'layouts/menu'
.content#content= yield
It’s so easy! Anyone can do it. HAML is sweeping the rails world like a wildfire of chicken, and everyone wants the biggest piece. I decided to try it last night on my new wallpaper site, and found that it’s extremely awesome to work with. As you can see above, I used it for my application.haml layout. Here’s a breakdown of wtf is going on up there:
- !!!: That pesky DOCTYPE crap line that everyone hates and googles all the time.
- %tag: You use % to denote a new tag, and close it with indentation, like Python.
- %link{:rel => “shortcut icon”}: All the tag attributes are just a ruby hash!
- = stylesheet_link_tag ‘wallpaper’: Use the = to evaluate Ruby and display it.
- .header: Makes a div with a class of ‘header’.
- .header#homie: Makes a div with a class of ‘header’ and an id of ‘homie’.
- .menu#menu= render :partial => ‘layouts/menu’: Should be obvious by now. Renders a partial within a div with class ‘menu’ and id ‘menu’.
I found that it’s ridiculously easy to write views now. But what about loops?
- @wallpapers.each do |w|
.image[w]
= w.name
# Makes:
<div class='wallpaper image' id='wallpaper_4'>
Manatee
</div>
Holy dog crap! You don’t even have to use end anymore! It’s all Python style!
Now, if you want to have even more fun, you can make self closing tags like img!:
%img{:src => 'your_face.jpg'}/
# Produces
<img src='your_face.jpg'/>
This is probably a bad example because the HAML is actually longer than the result, but who cares!!!
For more tricks and stuff, check out the HAML reference and tutorial.
Tags: haml programming rails ruby
Posted by hardwarehank,
Sat Jan 27 20:09:25 UTC 2007
I made a sweet sidebar today that I’ve been wanting to make for a long time. I usually forget to head over to XKCD, so I wanted a way to have the newest images staring me in the face all the time. Now, thanks to the magic of RSS, they’re right in front of me. They are lightboxed, so I have the newest comics and their captions available to me without even leaving my own site. How homey. To get the sidebar (works in Typo svn rev. 1246, which is my crusty old checkout), do this wherever your plugins are kept:
svn co http://modzer0.cs.uaf.edu/repos/hank/code/ruby/typo/xkcd_sidebar/
Horray! A sidebar is born.
Tags: plugins rails ruby sidebar typo
Posted by hardwarehank,
Fri Jan 26 11:30:17 UTC 2007
I’ve been using Graticule for geocoding in a Rails project at work, and I decided I needed to make some changes. So, I turned the Graticule gem into a plugin. It’s available here:
./script/plugin install -x https://modzer0.cs.uaf.edu/repos/hank/code/ruby/graticule_plugin
It’s as simple as that. Then just jam this into your environment and change it accordingly:
GEOCODERS = [
Graticule.service(:google).new('google_key'),
Graticule.service(:yahoo).new('yahoo_key'),
Graticule::GeocoderUsGeocoder.new,
Graticule::MetaCartaGeocoder.new
]
Then you can just perform looping on GEOCODERS to do your queries on every site.
There’s also some other changes you can do to catch Graticule::AddressError, but I won’t go into those here.
Tags: gis plugins rails ruby
Posted by hardwarehank,
Sun Jan 21 13:59:09 UTC 2007
So, I am currently hosting this blog on Site5’s $5 Deal. I paid $120 for 2 years of hosting with 55GB HD Space and 5TB/month transfer allowance. So far, I am very happy with it, and I’m going to share some gory details with you.
The deal on the site looked to good to be true, and I thought it might be. So far, I haven’t noticed any deviances or misconceptions at all though.
Here’s what it looks like when you log into the Backstage application. This lets you manage your billing, domains, and contact info, and acts as a gateway into your site management systems. Very Nice!
Then, you can go to each site just by clicking its name. Each site has its own SiteAdmin interface which gives you pretty amazing abilities.
You can manage MySQL databases with phpMyAdmin, see all the Ruby and Perl libraries they have installed, mess around with FTP junk, automatically create about 30 applications, manage files, and lots lots more.
Also, there’s a little tool called FlashBack that I get to beta test for them. It auto-saves the state of your directory so if you delete files or whatnot you can restore them easily. Pretty awesome.
Shell access is enabled by default, so you don’t have to mess around with support on that one. I transferred my domain name to them, and they have a flat rate of $8.88/year for domain name registration. That’s fine with me. Also, if you need SSL, even if you can generate your own certificate like I can (CACert), it still costs $15 to install it on the server. Personally, I don’t want to pay for it, so I’m SSL-less right now. Oh well, I don’t need it anyway.
All in all, these guys blow away Dreamhost, which I had for the past year. Dreamhost cost me twice as much, and their server had very slow network performance for me. The fastest I ever saw was 100K/sec, and usually it was around 40K/sec. Unacceptable. Also, as far as I can tell with ps, this shared host is not as overloaded with people as Dreamhost’s. Dreamhost’s MySQL setup is lame (you have to create a ton of subdomains for no apparent reason), whereas Site5 you always use localhost, speeding installations along. I managed to transfer my entire old SVN checkout of Typo over here, and the only trouble I had was trying to remember to cross my T’s and dot my I’s on the FastCGI/Apache environment. It’s too bad I can’t just run mongrel instances and do Apache forwarding like I used to, but as long as it runs, whatever.
Score: 9/10
Site5 has done a wonderful job so far, and I don’t see it going downhill soon. They make a wonderful Rails host, and I’m proud to be a customer.
Tags: hosting perl rails ruby typo
Posted by hardwarehank,
Sat Jan 20 01:35:51 UTC 2007
Well, I made the transition to Site5 Hosting today. They have an amazing deal - $5/month for 2 years gets you 5 TB/month transfer and 55 GB HD Space. It’s a very Rails-Friendly environment, too! I got Typo up and running today which was transfered from the college webserver it’s been on for a year. They give you shell access, unlimited databases…it’s insane. And I also transferred my domain there - $8.88/year is a little expensive, but that’s OK. They have tons of support for Ruby including tons of popular gems, and their admin interface is very slick.
Anyway, so this is my first post on Site5. I wanted to show off my Google Adsense sidebar, which I made to generate revenue to pay the server bills.
You can get it from my usual subversion repository:
svn co https://modzer0.cs.uaf.edu/repos/hank/code/google_ads_sidebar
It’s very simple to use (at least in my very old checkout of Typo). First, dump it in the typo/vendor/plugins directory. Then, go find it. Then jam in your key from the code they gave you. It should look something like this: pub-1275878260955547. Finally, save, and go stare in awe at the results. You might have to restart Typo’s webserver or clear its cache first.
Tags: hosting life money rails ruby typo
Posted by hardwarehank,
Sat Sep 09 19:31:38 UTC 2006
For some reason, my sessions kept expiring over at my StockMaster app. So, I googled and found this.
Tags: rails
Posted by hardwarehank,
Tue Aug 29 12:07:54 UTC 2006
sudo apt-get install libgnomeprintui2.2-dev libpanelappletmm-2.6-dev \
libgstreamer0.8-dev libgda2-dev libgtkglext1-dev libgnomeui-dev \
libgnomevfs2-dev libpoppler-dev libglade-dev libpoppler-glib-dev \
libgtksourceview-dev libgnomeprint2.2-dev
Target libraries: glib, gdkpixbuf, pango, atk, gtk, vte, libart, gtkglext, libgda,
gnome, libglade, gstreamer, gtkhtml2, gnomevfs, panel-applet, gnomeprintui,
gnomecanvas, gtksourceview, gnomeprint, gconf, rsvg
Ignored libraries: gtkmozembed, poppler
Tags: linux ruby ubuntu
Posted by hardwarehank,
Tue Aug 29 06:33:15 UTC 2006
Well, turns out that you won’t be seeing .score in ActiveSupport any time soon. :( I got pwn3d. So, if anyone wants my blog name to make any sense, they must run this patch. :P
Tags: rails ruby