Expression Engine

Blank Screen with Expression Engine

I am going to use this post to track the occasions when I get inexplicable blank screens in Expression Engine.

Issue #1 - Relative Date plugin syntax error

Symptoms: After adding the first entry to a weblog I would get a blank screen. If I changed the status of the entry to Closed, the page would be ok. If I opened it again it would be blank. No debug messages would show.

Resolution: My templates rely on the relative_dates plugin. The syntax of the plugin was incorrect. Line one of the file was <? but should have been <?php. This thread on the Expression Engine forum got me jump started on resolving the issue.

Expression Engine Linux

Using /home/* on a mac

I want the path on my Mac dev environment to match the path on my Linux server (I am doing this for ExpressionEngine, where it’s much easier to deploy to different servers if the paths match).

My Linux server path starts with /home/myusername. Unfortunately, in Mac Leopard the /home directory is not editable, so I cannot put my files in the directory I need.

I found a solution buried in an Apple support forum message. The solution is to comment out an entry in the the auto_master file.

Here are the steps:

  1. edit the file: /etc/auto_master
  2. comment out this line: # /home auto_home -nobrowse
  3. save & reboot

After reboot the /home directory acted like I expected and now I have my ExpressionEngine files where I need them.

Expression Engine

Relative time formatting with ExpressionEngine

I started using David Rencher’s handy Relative Date plugin for ExpressionEngine.

Here is an example output:

About 1 week, 2 days, 21 hours, 13 minutes ago

The formatting comes from a php function called Localize::format_timespan. It would be great for doing a count down timer to some event, but it is not so great for displaying the age of a blog post.

I was looking for a formatting method in PHP that behaves like the time_ago_in_words method in Rails. I found it here: http://snippets.dzone.com/posts/show/5658. Sweet.

So, I modified the original relative_date plugin to use the new method.

Here is the new output:

About 10 days ago

You can download the new file here: pi.relative_date_.php_.zip.

Linux

git: ‘index-pack’ is not a git-command. See ‘git --help’. fatal: index-pack failed

I am using capistrano to deploy to a dedicated server. It has been working fine for days, then last night it stopped working.

I investigated the trace and saw this error:

1
2
git: 'index-pack' is not a git-command. See 'git --help'. 
fatal: index-pack failed

So, I signed in to the server and tried to run a few variations of fetching and cloning my repository and other public repositories and got the same error.

Then I decided to sign in as root and another normal user. Those users were able to do git commands with no problems.

After a bunch of work trying to find the difference I discovered that my failing user had:

1
2
echo $SHELL
/usr/local/cpanel/bin/jailshell

whereas my other users had:

1
2
echo $SHELL
/bin/bash

So, I signed in as root and changed my user’s shell to bash and now everything works just fine:

1
2
ssh root@xxx.xx.xx.xx
chsh -s /bin/bash username

RubyCocoa TwitterGrowl

Twitter and Growl

I started with code from visnup for pushing friends’ tweets to Growl called TwitterGrowl.

Then I added a few features using RubyCocoa and Growl Notifier:

  • track custom search terms
  • click on notifications, go to Twitter
  • customize the look of friend versus search tweets from the growl preferences panel
  • run TweetGrowl as a startup item

The code is available at github.

MySQL

Create a MySQL User

I often forget how to create a user in MySQL..  Here it is:

1
2
3
4
grant all privileges on *.* to 'landlessnesss'@'localhost' \
 identified by 'abc123def' with grant option;
 
flush privileges;

Ruby on Rails

strftime without leading zeros (0s)

In Rails I wanted to display times like 2:30 am without having a leading zero like 02:30 am.

The view code that gave leading zeros looked like this:

1
<%= foo.updated_at.strftime("%I:%M %p") %>

The code that will trim leading zeros looks like this:

1
<%= foo.updated_at.to_datetime.strftime("%-1I:%M %p") %>

The trick is to convert the time object from ActiveSupport::TimeWithZone to DateTime, which supports prefix modifiers like ‘-1’ in the format expression.

History of Computing

Arthur W. Burks, 92, Dies

Arthur W. Burks, a member of the team that designed the Eniac computer, a frequent collaborator of John von Neumann and a pioneer in computing education, died Wednesday [May 14th, 2008] at a nursing home in Ann Arbor, Mich. He was 92.

-The New York Times

I had the opportunity to work for Professor Burks for a number of years.  I worked for him at his home.  His wife, Alice, an author, used to make me sandwiches each time I visited.  He was a genuinely nice man, who taught me much about the history of computing.

Rest in peace, Professor Burks.

Foreign Domain Routing

Just Published Foreign Domain Routing

I just published Foreign Domain Routing plugin at github:

http://github.com/brianmulloy/foreign-domain-routing

Ruby on Rails

Validate One ActiveRecord Attribute

I am using restful_authentication and want to extend it with functionality to invite a person using only his email.  So, I wanted the ability to validate just one attribute of a model.  Expressia::Blog described the same problem here and had built the plugin I wanted. Only all the links to the plugin pointed back to the original post.  I eventually found the plugin install and usage documentation here at RailsLodge.

1
ruby script/plugin install svn://vinsol.com/plugins/sur/validate_attributes

Now, my relevant code looks like this:

1
@person.validate_attributes(:only => ['email'])

Ruby on Rails

Installing restful_authentication and acts_as_state_machine (aasm) as plugins

Here are the steps I took to install restful_authentication with acts_as_state_machine (using the new aasm gem) as plugins.

Started in the rails home directory of the app. 

Installed aasm gem as a plugin:

1
script/plugin install git://github.com/rubyist/aasm.git

(thanks to Erik on Rails for the above)

Installed restful authentication:

1
2
3
git submodule add \
  git://github.com/technoweenie/restful-authentication.git \
  vendor/plugins/restful_authentication

I use capistrano so I also added the following to my config/deploy.rb file

1
set :git_enable_submodules, 1

Created a lib directory in the app home directory:

1
mkdir lib

Called the restful authentication generator.  Fyi, instead of user, I use person as the name of my model for people:

1
./script/generate authenticated person sessions --include-activation --aasm

Then I did the post-generate steps, following some of the instructions at github.  Some of the steps enumerated in the docs seem to be taken care of as part of the generate call now.

In config/routes.rb, I did a find/replace on peoples (incorrect plural) replacing all with people (correct plural) and added the activate route.  In the end my routes.rb looked like this:

1
2
3
4
5
6
7
8
9
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/register', :controller => 'people', :action => 'create'
map.signup '/signup', :controller => 'people', :action => 'new'
map.activate '/activate/:activation_code', :controller => 'people',
                    :action => 'activate', :activation_code => nil
map.resources :people, :member => { :suspend   => :put,
                                   :unsuspend => :put,
                                   :purge     => :delete }

In config/environment.rb, I added:

1
config.active_record.observers = :person_observer

So I can use before filters in my controllers, I modified app/controllers/application.rb to include AuthenticatedSystem:

1
2
3
4
class ApplicationController < ActionController::Base
  helper :all
  include AuthenticatedSystem
end

I adjusted the language in app/models/person_mailer.rb, especially replacing the YOURSITE references to be the URL of my site:

1
2
@body[:url]  = 
    "http://www.landlessness.net/activate/#{person.activation_code}"

Linux

Adding fonts on Linux without sudo

I am using a hosting service, which doesn’t allow me sudo access.  Yet I want to install additional fonts.

I don’t recall all the steps I did, but I got it working.  First, I installed fontconfig in under my home directory, such that:

1
2
$ which fc-list
~/bin/fc-list

then when I want to install new fonts I copy the ttf file to the ~/.fonts directory like:

1
2
$ scp Georgia.ttf user@myurl.com:~/.fonts/g.ttf
Georgia.ttf     100%  146KB  73.1KB/s   00:02

then in order to reset the font cache I run

1
2
3
$ fc-cache -v ~/.fonts
fc-cache: "/home/me/.fonts": skipping, 6 fonts, 0 dirs
fc-cache: succeeded

then when I run fc-list, I’ll see my new font in the list

1
2
$ fc-list
Georgia:style=Regular

Ruby on Rails

Passing optional local variables to a partial

In verbose_index.html.erb i want to pass some additional parameters to the _thing.html.erb partial:

1
2
3
4
<% @things.each do |thing| %>
<%= render :partial => thing,
  :locals => {:some_extra_stuff => some_extra_stuff} %>
<% end %>

in index.html.erb i do not want to pass any additional parameters to the _thing.html.erb partial:

1
<%= render :partial => things %>

when I hit verbose_index everything will work fine.  but when I hit index, I’ll see this error:

1
2
undefined local variable or method 'some_extra_stuff'
  for #<ActionView::Base:0x22e6948>

to fix, in _thing.html.erb I add a check to see if the local variable is assigned:

1
2
3
<% unless local_assigns[:some_extra_stuff].nil?  %>
<%= some_extra_stuff %>
<% end %>

Capistrano

Could not find any SCM named git

I have been wrestling with capistrano and git, when I ran the following I got an error:

1
2
$ cap deploy:check
could not find any SCM named `git'

I ran ‘which git’ by hand on both my local box and remote box.

on the remote box:

1
2
$ which git
/usr/local/bin/git

on the local box:

1
2
$ which git
/usr/local/git/bin//git

not sure what the issue was, but I tried to set the following in my deploy.rb without success:

1
2
set :local_scm_command, "/usr/local/git/bin/git"
set :scm_command, "/usr/local/bin/git"

ultimately, my fix was to uninstall and reinstall git on my local machine.

now on the local box:

1
2
$ which git
/usr/local/bin/git

now

1
2
$ cap deploy:check
You appear to have all necessary dependencies installed

Sonoa

Using cURL for SOAP

How to issue a SOAP request (to Sonoa’s ServiceNet) using cURL from the command line:

shell command:

1
2
3
4
5
curl \
  -H "SOAPAction: urn:getCustomerDetails" \
  -H "Content-Type: text/xml" \
  -d "@getCustomerDetails.xml" \
  http://192.168.96.132:8080/samples/services/CustomerInfoService

where getCustomerDetails.xml is a file in the current directory.

getCustomerDetails.xml:

1
2
3
4
5
6
7
8
9
10
11
12
<soapenv:Envelope 
  xmlns:soapenv=
    "http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:cus=
    "http://www.sonoasystems.com/schemas-samples/2007/1/26/customer"> 
  <soapenv:Header/> 
  <soapenv:Body> 
    <cus:getCustomerDetails> 
      <cus:customerID>12</cus:customerID> 
    </cus:getCustomerDetails> 
  </soapenv:Body> 
</soapenv:Envelope>

shell output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope 
    xmlns:soapenv=
      "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header />
  <soapenv:Body>
    <getCustomerDetailsResponse 
      xmlns=
        "http://www.sonoasystems.com/schemas-samples/2007/1/26/customer">
      <return>
        <customerID>12</customerID>
        <shipToAddress>
          <city>City 12</city>
          <country>USA</country>
          <name>Name 12</name>
          <state>CA</state>
          <street>Street 12</street>
          <zip>Zip 12</zip>
        </shipToAddress>
      </return>
    </getCustomerDetailsResponse>
  </soapenv:Body>
</soapenv:Envelope>

Sonoa

Sonoa

I am checking out Sonoa System’s ServiceNet product.

http://www.sonoasystems.com/

Expression Engine

ExpressionEngine Category for Entry

I wanted to display the category of an entry so that the end result would look like the following, where Ruby on Rails is the category:

RUBY ON RAILS
Scaling ActiveRecord
Thursday September 25, 2008 at 10:26pm

I couldn’t find any examples, but the snippets in TextMate helped me out.  Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{exp:weblog:entries weblog="posts"}
  <div class="post">
    <h3>
      {categories weblog="posts"}
      {category_name}
      {/categories}      
    </h3>
    <h2>
      <a href="{title_permalink="posts/view"}">
        {title}
      </a>
    </h2>
    <div class="post-date">
      {gmt_entry_date format="%l %F %d, %Y at %g:%i%a"}
    </div>
  </div>      
{/exp:weblog:entries}