Malicious enjoyment derived from observing someone else’s misfortune
 

Tag Archives: ruby

Mephisto Comment Notification Mod

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 [...]

2007 Iditarod Tracking with Google Earth

I’ve created a Google Earth KML Feed of the current Iditarod standings. I’m generating it with Ruby. It’s pretty cool. If you want to try it, do one of the following: Download the Network Feed KML, which contains a link to the following KML and automatically updates every 10 minutes *or* Download the Current KML, which does not update, but is that actual static file the above KML uses. I recommend the feed. Here’s some pictures of the current state:

Fixing Mephisto Post Pinger Plugin

I wanted some places to get pinged when I posted. I used the mephisto_post_ping plugin, I simply changed the directory structure and class definition around: Directory Structure ./lib/article_ping_observer.rb ./lib/mephisto_plugins/post_ping.rb ./lib/config.rb ./README ./init.rb File Changes init.rb # $Id$ require ‘mephisto_plugins/post_ping’ ActiveRecord::Base.observers << :article_ping_observer plugin.rb module Mephisto module Plugins class PostPinger < Mephisto::Plugin author ‘Mark Guzman’ version ‘$Rev: 82 $’.gsub( "Rev: ", "" ) notes "Send Weblogs Pings when articles are published" homepage "http://hasno.info/2006/11/11/mephisto-plugins" class Schema < ActiveRecord::Migration def self.install end def [...]

FizzBuzz: The Ultimate Programmer Weed Out

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.

How to make a Mephisto Plugin

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 [...]

Mephisto Tag Cloud Plugin

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 [...]

ZIP files in Rails

Today, I needed to make a KMZ file from my KML in Rails. This was easy thanks to RubyZIP: gem install rubyzip Now for the Rails action: # In your controller private def zip(data, filename) zipfile = “/tmp/rubyzip-#{rand 32768}” Zip::ZipOutputStream::open(zipfile) do |io| io.put_next_entry(filename) io.write data end zippy = File.open(zipfile).read File.delete(zipfile) zippy end This makes a temp file, adds to it zip-style, reads it to a string, and deletes it. It leaves nothing behind on the file system. Then all you [...]

MySQL Capitalization Issue

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’ [...]

More Madness converting to Mephisto

I changed all my typo:code tags to filter:code today: Article.find(:all).each {|a|a.body.gsub!(‘typo:code’, ‘filter:code’);a.save};

How I converted Typo to Mephisto

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 [...]