Barefoot is hiring developers again
Sean Brown | Friday, February 08, 2008
Sean Brown | Friday, February 08, 2008
Bobby | Friday, February 01, 2008
<div id="nav">
<ul>
<li><a href="/" class="selected">Home</a></li>
<li><a href="/about/">About Us</a></li>
<li><a href="/contact/">Contact Us</a></li>
</ul>
</div>
<div id="content">
<p>Hello <b>World</b></p>
</div>
class="selected"
). That will allow great flexibility with the design of the nav in Flash. Using SWFObject, it's as simple as this:so.addVariable("xml_input", escape(document.getElementById("nav").innerHTML));
so.addVariable("html_input", escape(document.getElementById("content").innerHTML));
// Parse the xml content
XML.prototype.ignoreWhite = true;
var myXML:XML = new XML();
myXML.parseXML(_level0.xml_input);
var rootNode:XMLNode = myXML.firstChild;
...
// Set the html content
_root.content_txt.htmlText = _level0.html_input;
Dr. B. | Tuesday, December 04, 2007
Bobby | Tuesday, November 27, 2007
uploaded_data
, attachment_fu will grab that TempFile with a setter of the same name and do its magic. I have followed the same process with a new method. It can go right in the model that has_attachment
:
# Takes input of a remote file via an absolute URL,
# reads it and passes it to attachment_fu for processing
def remote_data=(file_url)
return nil if file_url.nil?
open(file_url) do |data|
# extract the filename and extension from the url
temp_filename = URI.split(file_url)[5][/[^\/]+\Z/]
# pass details to attachment_fu
self.filename = temp_filename
self.temp_data = data.read
self.content_type = data.content_type
end
end
photo = Photo.new
photo.remote_data = "http://www.somewhere.com/an_image.jpg"
photo.save
Dr. B. | Friday, November 09, 2007
/%category%/%year%/%monthnum%/%postname%/
next_posts_link()
was misinterpreted by WordPress because of the permalink. The link was: /blog/2007/9/page/2/
. Unfortunately, the string "page" in this URL was interpreted as a post name, instead of a token for the page index.
<?php
/*
Plugin Name: Fix Paging in Category Listings
Plugin URI: http://www.thinkbarefoot.com
Description: Fixes a bug where next/previous links are broken in category by year/month listings
Version: 0.5
Author: Doug Smith
Author URI: http://www.thinkbarefoot.com
Copyright 2007 Doug Smith (email: dsmith@thinkbarefoot.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/**
* Function to fix problem where next/previous buttons are broken on list
* of posts in a category when the custom permalink string is:
* /%category%/%year%/%monthnum%/%postname%/
* The problem is that with a url like this:
*
* /category/2007/10/page/2
*
* the 'page' looks like a post name, not the keyword "page"
*/
function remove_page_from_query_string($query_string)
{
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so split it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
add_filter('request', 'remove_page_from_query_string');
?>
Dr. B. | Thursday, November 01, 2007
Category.published_article_list(options)
and the details would be irrelevant.
def published_article_list(options = {})
if (food?)
# Special query that returns only the latest article for each 'reviewer' category
sql = "mid_category_id != #{REVIEW_CAT} OR articles.id IN ( "
sql += "SELECT SUBSTRING( MAX( CONCAT( published_on, id ) ), 11 ) AS ra_id "
sql += "FROM articles "
sql += "WHERE mid_category_id = #{REVIEW_CAT} AND "
sql += " #{Article.conditions_published} "
sql += "GROUP BY category_id ) ) "
options[:conditions] = sql
end
self.published_root_articles.find(:all, options)
end
SELECT
clause: SUBSTRING( MAX( CONCAT( published_on, id ) ), 11 ) AS ra_id
. I needed to get the ID of the latest article, grouped by category_id (the individual reviewer). So, this code concatenates the published_on date to the article ID, finds the max of all those values, then uses SUBSTRING
to chop the concatenated date off, leaving only the id of the latest article. So, for a list of articles with IDs and dates like this:
id date category_id
101 2007-10-01 1
102 2007-09-30 1
103 2007-10-02 2
104 2007-10-01 2
2007-10-02103
2007-10-01104
2007-10-01101
2007-09-30102
CONCAT
function requires a full table scan, so indexes won't be used in the subquery. Since this page is cached, it wasn't a problem for this application, but if performance becomes an issue other optimization could be done while still using this strategy.Dr. B. | Friday, October 19, 2007
<%= link_to('« Previous', :page => @article_pages.current.previous) if @article_pages.current.previous %>
<%= link_to('Next »', :page => @article_pages.current.next) if @article_pages.current.next %>
undefined method `paginator' for "2":String
. The top-most offending line of the stack trace was: vendor/plugins/classic_pagination/lib/pagination.rb:307:in `=='
.
<%= link_to('« Previous', :page => @article_pages.current.previous.number) if @article_pages.current.previous %>
<%= link_to('Next »', :page => @article_pages.current.next.number) if @article_pages.current.next %>