Displaying articles with tag rails
Posted by hank,
Sat Jan 05 16:49:00 UTC 2008
So, I found this today, and it is awesome. I wanted it in Bluecloth so I could use it in Mephisto. Here’s how.
First, I needed to make it so I could still do normal images, but turn on coolness if I want. Here’s the goal I came up with for the grammar:
[](imageurl.jpg "Scrolly Text at top" "photoslice")
Here’s the first test, with a single image:

And now a set with a namespace:

I did it by simply modifying the regex and image url parsing function in BlueCloth like so:
InlineLinkRegex = %r{
\( # Literal paren
[ ]* # Zero or more spaces
<?(.+?)>? # URI = $1
[ ]* # Zero or more spaces
(?: # title
([\"\']) # Opening quote char = $2
(.*?) # Title = $3
\2 # Matching quote char
)? # Title is optional
[ ]* # Zero or more spaces
(?: # rel
([\"\']) # Opening quote char = $2
(.*?) # rel = $5
\4 # Matching quote char
)? # rel is optional
\)
}x
# and later...
# ...or for an inline style second part
elsif @scanner.scan( InlineLinkRegex )
url = @scanner[1]
title = @scanner[3]
rel = @scanner[5]
@log.debug " Found an inline link to %p" % url
text += %{<a href="%s"} % escape_md( url )
if title
title.gsub!( /"/, """ )
text += %{ title="%s"} % escape_md( title )
end
if rel
rel.gsub!( /"/, """ )
text += %{ rel="%s"} % escape_md( rel )
end
I also added the following to my Mephisto theme layout, in the head section:
<!-- Photoslice -->
<link rel="stylesheet" type="text/css" href="/javascripts/photoslice/style.css" />
{{ "photoslice/functions.js" | javascript }}
Once again, Ruby is awesome. And so is Markdown.
Tags: rails
Posted by hank,
Sat Oct 20 00:05:00 UTC 2007
You can still get 13% off a new Site5 7.5TB/750GB/$7.50 Plan until November! These guys are a great rails host. Get this deal while it’s hot!
Code: HALLOWEEN2007

Tags: rails
Posted by hank,
Sun Sep 02 01:02:00 UTC 2007

OK - I’m usually pretty critical in general, but this is the best hosting I’ve ever found, and it’s 3 times better than when I bought it, and it’s still the same price! So, you should click the image above and go sign up. These guys give you great support - I’ve contacted them numerous times and always had my problem solved within just a few minutes. I’ve noticed my site down once, and as soon as I emailed them, it was back up again. This blog is running Mephisto, a Ruby on Rails application, and it’s FAST! I barely ever see the kind of quick response from websites like I see from mine.
Features
- Full Ruby on Rails support. They have updated gems for you to use, but also allow you to keep your own gem repository in your home directory.
- Ready-to-go web applications with one-click installs
- Awesome tech support
- Very extensive wiki and forum where you can find out how to do anything you want with your account
- 165GB of storage!
- 5TB of bandwidth per month - which is great for transferring large files. I’ve never had a problem with the transfer speed, either.
- 165 domain pointers - This allows me to host all my domains with them. They have a great system for buying domains that I’ve used quite a bit too.
- Shell access
- Free setup!
- 60-day money back guarantee - If you don’t like it, you get all your bones back. How cool is that?
Benchmark
I have 16Mbit internet at home, and I decided just now to test the bandwidth of my site. Here are the results:
hank@rofl:/tmp$ wget -O /dev/null http://ralree.info/videos/grad.mp4
--00:50:57-- http://ralree.info/videos/grad.mp4
=> `/dev/null'
Resolving ralree.info... 70.47.124.108
Connecting to ralree.info|70.47.124.108|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 63,744,460 (61M) [audio/mp4]
100%[====================================>] 63,744,460 1.92M/s ETA 00:00
00:51:30 (1.86 MB/s) - `/dev/null' saved [63744460/63744460]
Yes, folks, thats 1.86 MEGABYTES per second.
My Maximum at 16Mbit is 2 Megabytes/second, meaning this completely maxed out my connection.
I used to be a Dreamhost customer, and it sucked. It sucked really bad. I’m so glad I switched. Compare the features to any other plan you can find for $5/month. This is as good as it gets.
Sign up now!
Tags: rails
Posted by hank,
Sun Jun 10 13:13:00 UTC 2007
Well, I was over at Debian Package of the Day when I noticed an article on KLone. It’s a little application framework that allows you to do XHTML templating in C! Then, you can compile it and send it off to any Linux machine (with a few dependencies of course) to run it. I got it, and it didn’t work for me at first. Then, for some reason, it started working. Here’s what I think did it:
In Ubuntu, I did this:
sudo apt-get install build-essential libssl-dev quilt klone klone-package
Then, I made a new test project:
make-klone-project create -p myhello
This creates a new project directory. Now, go into it and make it your new home:
cd myhello-0.1/
cd userdata/
mkdir www etc
vim etc/kloned.conf
I’m just going to assume you’re using vim because, well, you should be. Make the config file look something like this:
server_list my_http
allow_root yes
my_http
{
type http
addr.type IPv4
addr.port 8880
dir_root /www
}
Now lets give it something to work with (note we’re still in userdata):
vim www/index.klone
<html>
<head><title>Hello Lady!</title></head>
<body>
<% io_printf(out, "Hey, Lady! You call him Dr. Jones!"); %>
</body>
</html>
Now add your precious files to the sauce:
cd ../../site/
klone -c import ../userdata/
# 2 dirs and 2 files imported
cd ..
Now, compile and run it:
kloned-build -o myapp userdata
./myapp -F # This runs it in non-daemonized mode
If you don’t get any errors, congratulations. That means I did something right.
Now, just hop over to here or wherever you specified it to run, and it will magically appear.
Now you can do this:
<html>
<head><title>Hello World</title></head>
<body>
<%
int i;
for(i=0; i < 10; ++i) {
io_printf(out, "Hello Lady! %d<br />", i);
}
%>
</body>
</html>
Then run this to rebuild and re-run the server:
kloned-build -o myapp userdata && ./myapp -F
Update
So, I ran some tests, and I have to say, the speed increase from C might be really awesome every now and again. Here’s the code:
clock_t curtime = clock();
#define SEED 35791246
int niter=10000000;
double x,y;
int count=0; /* # of points in the 1st quadrant of unit circle */
double z;
double pi;
/* initialize random numbers */
srand(SEED);
count=0;
for ( i=0; i<niter; i++) {
x = (double)rand()/RAND_MAX;
y = (double)rand()/RAND_MAX;
z = x*x+y*y;
if (z<=1) count++;
}
pi=(double)count/niter*4;
io_printf(out, "# of trials= %d , estimate of pi is %g \n",niter,pi);
io_printf(out, "%f", (double)(clock() - curtime)/(double)CLOCKS_PER_SEC);
All this is is a Monte Carlo method of calculating pi that I stole from here. It takes 0.56 seconds of CPU time on my Core 2 Duo @ 3.3Ghz. Now for the Ruby on Rails test:
# Controller
@start = Time.now
srand(35791246)
iter = 10000000
count = 0
0.upto(iter) do |i|
x = rand().to_f
y = rand().to_f
z = x*x+y*y
count += 1 if z <= 1
end
@pi = count.to_f / iter * 4
@end = Time.now
This finishes in 20.75 seconds (about 40x slower). C is great for things like this. I hope to use KLone in the future for these kinds of tasks.
Tags: rails
Posted by hank,
Wed May 16 01:44:00 UTC 2007
I noticed today that Site5 has doubled their $5 deal! Now you get the following for only $5/month:
110 GB Storage
5 TB of bandwidth allowance per month
110 Domain Pointers
Free Setup
Ruby on Rails Friendly
I am currently using this plan for this blog, and am extremely happy with it after coming over from Dreamhost.
Tags: rails
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: rails
Posted by hank,
Fri Mar 02 12:56:00 UTC 2007
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 self.uninstall
end
end
end
end
end
That’s all I changed. This is my first post since the change, so I’ll see if it works. If not, at least Mephisto doesn’t blow up on startup.
Results
Well,
unable to send xmlrpc weblog ping -> http://www.ralree.info
unable to send xmlrpc weblog ping -> http://www.ralree.info
unable to send xmlrpc weblog ping -> http://www.ralree.info
unable to send xmlrpc weblog ping -> http://www.ralree.info
Seems like a couple might have worked. I’ll keep working on it. But, at least it gets called.

Tags: rails
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: rails