Mephisto Comment Notification Mod

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:

How to make a Mephisto Plugin

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:

Mephisto Tag Cloud Plugin

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:

MySQL Capitalization Issue

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:

How I converted Typo to Mephisto

Posted by hank, Wed Feb 21 23:13:00 UTC 2007

I had some difficulty along the way, and I have some fixes for those of you who are having trouble converting. I found that Mephisto is actually very friendly to the ./script/console hacker. Also, though it took a while to actually get a response, I ended up getting direct help from technoweenie in #mephisto@irc.freenode.net, which was a big help. So, here’s the situation:

My current host is Site5. I have gems set up in my home directory, and I have rails 1.2.2 installed as a gem. I tried using it, but just ended up freezing edge rails because I ran into some trouble. I created a db, subdomain, and .htaccess entry for the site. Then, I actually checked it out:


svn co http://svn.techno-weenie.net/projects/mephisto/trunk mephisto

Then, I created config/database.yml. Here’s a template you can use:


development:
  adapter: mysql
  database: mephisto
  username: meph
  password: <new-pw>
  host: localhost

production: 
  adapter: mysql
  database: mephisto
  username: meph
  password: <new-pw>
  host: localhost

typo:
  adapter: mysql
  database: typo
  username: typo
  password: <typo-pass>
  host: localhost

Next, I installed tzinfo as a gem to my home directory, and froze it in the project root:


gem install tzinfo
cd mephisto
rake gems:freeze GEM=tzinfo

Finally, it’s time to fill the database with stuff:


rake db:bootstrap

Now that that’s done, for CGI and FastCGI to work, we need a .htaccess file in public:


AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

Notice I left it as dispatch.cgi. It’s up to you, but while I was still converting I left it like this since it didn’t want to run with FastCGI.

Let’s make sure log and public can be read and, if need be, written to:


chmod -R 755 public log

And finally, the moment we’ve all be waiting for:


script/runner "Mephisto.convert_from :typo" -e production

This connects to the Typo database and runs a converter script in Mephisto’s vendor/plugins/ directory. It takes all the attributes Typo articles and users and comments had and converts them to Mephisto form. Rockin’.

Old Typo Woes

I did this with Typo trunk v1246 with migration level 55. If you are at a similar Typo state, then you may definitely want to continue reading as the next steps I took will be necessary for you as well.

First of all, I saw that my Markdown with SmartyPants formatting was not being interpreted at all! This was, of course, easy to fix because Mephisto is awesome:


./script/console
# Don't do this unless you ALWAYS used Markdown with SmartyPants
# Refer to vendor/plugins/filtered_column if you use Textile or straight up Markdown
# It's just a different a.filter= line below.
Article.find(:all).each {|a|a.filter='smartypants_filter';a.save};1

What this does is find all the Mephisto articles and set their filter to Markdown with SmartyPants. The 1 on the end just prevents it from spewing every article to the console.

Now here’s where I ran into some trouble. Typo has changed its Tag storage technique at least twice, and the way my tags happened to be stored is as follows:


articles
 - id
articles_tags
 - article_id
 - tag_id
tags
 - id
 - name

Someone else had posted a small loop to cure another type of Typo tagging scheme, where there was just one tag grouping string per article. I ran that. Don’t do that.

I noticed that each one of my articles only had one tag, which made me a sad monkey. To remedy this, I wrote a small loop to find all the tags of a Typo article and set them up for the same article in Mephisto. Now, since the id’s on articles and tags are not kept constant in the conversion scripts, this was a bit tricky. Luckily, I never have duplicate permalinks (I guess that means I’m creative…).

First, you have to enable the Typo converter in the console. I did this by adding these 2 lines to the bottom of vendor/plugins/mephisto_converters/init.rb:


require "converters/base"
require "converters/typo"

Then, it’s simply a case of the following:


./script/console
# Remove All Mephisto Taggings as to not make dupes
Tagging.find(:all).each{|t|t.destroy}
# Loop through every Typo article
#    Find the associated Mephisto article
#    Loop through all the Typo Tags
#      Append each tag to the Mephisto tag array
Typo::Article.find(:all).each do |ta|
  a = Article.find_by_permalink(ta.permalink)
  ta.tags(true).collect{|b|b.name}.each do |tag|
    a.tags(true) << Tag.find_by_name(tag)
  end
end

Don’t forget to remove the requires you put into init.rb above. Once you do that, you should have a nicely running Typo -> Mephisto conversion. Congratulations!

Tags:

Switching SVN Locations

Posted by hardwarehank, Wed Feb 21 01:38:18 UTC 2007

I moved some crap around in my repository the other day, and I felt the pain when I tried to update. Thankfully, the svn people have thought this thru already.


svn sw https://modzer0.cs.uaf.edu/repos/hank/code/rails/stockmaster .

At first this broke, so I had to do a temporary svn cp to resolve some missing crap. After that, it moved right over to the new location and I could update again.

If I had changed servers and not paths, I could have done this:


svn sw --relocate https://modzer0.cs.uaf.edu/repos/hank/code/rails/stockmaster \
https://modher0.cs.uaf.edu/repos/hank/code/rails/stockmaster .

All documented here.

Tags:

CheeseToast.Org is Live!

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:

Everybody hates pumpkins

Posted by hardwarehank, Sun Feb 18 23:19:52 UTC 2007

So, it turns out that when I changed my theme to a ‘harvest gold’ background, I got a lot of flak about it:

20:43:29 <+plaidrules> hardwarehank: wow dude, your blog css is hideous

It led me to embrace the night with this new emoesque theme. I hope you like it. I’m going to have to start looking the part in real life, as well as posting pictures of myself with swoopy to the left-like hair dyed black, and some awesome eyeshadow of doom. Something like this should do:

Oh ya. Thats gonna be me. You just wait.

Oh, and the offending color for all the see:

  

Also, this awesome theme is called Wibbish, and you can get it like this for all I care:


svn co https://modzer0.cs.uaf.edu/repos/hank/code/rails/typo/wibbish

Time to go put on makeup.

Tags:

Thumper: a photo and YouTube aggregator for Rails

Posted by hardwarehank, Sat Feb 17 12:55:35 UTC 2007

I made a project today. It’s called Thumper. All you have to do is post a special string to a url, and it does all the work. Catalog those cool images and videos.

It’s available in https://modzer0.cs.uaf.edu/repos/hank/code/ruby/thumper

It’s very simple to use. You run it anywhere, and make requests like this:


# Makes a new YouTube video
curl -i -X POST -d "video[code]=IsyWlcQAy-Q" http://server/youtube/new
curl -i -X POST -d "photo[url]=http://www.ipnlighting.com/images/wasted.jpg" http://server/pics/new

Voila! Thumper lives!

Tags:

Cheating on ERB with HAML

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:

XKCD Typo Sidebar

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:

Graticule: Geocoding on Rails

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:

Route Resource Magic Pants

Posted by hardwarehank, Thu Jan 25 23:38:44 UTC 2007

Apparently, you can make things like users_path and groups_path work if you do this in routes:


  map.resources :group

Finally. Now I can continue adding groups to Beast.

Tags:

Ultimate Hosting Review: Site5

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:

Google Adsense Typo Sidebar

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: