Change a title of a view block programmatically!

Just in case you are like me and find yourself wanting to change the title of a view programmatically, and can't figure out how, the (somewhat unintuitive) way is to hit the build_info, so you do this in your module:

<?php
function hook_views_pre_render(&$view) {
 
// Some code to make sure you are changing the right title, say an if statement perhaps!
 
$view->build_info['title'] = t("Your Brand New Title!");
}
?>

Soon this will not be necessary, as there will be a much easier method for accomplishing this included in Views sometime in the near future.

<?php
function hook_views_pre_render(&$view) {
 
// Some code to make sure you are changing the right title, say an if statement perhaps!
 
$view->set_title($fancy_new_title);
}
?>

Hope this helps!

Code editing on the Google Chrome Notebook (cr-48)

Thanks to the help of a fellow cr-48 hacker's instructions, I have successfully gotten the nice editor, a decent POSIX based text editor running on the bash shell on my cr-48 Chrome Notebook.

To get the same going on yours, you need to do the following:

Getting images or other files onto and off of your Google Chrome cr-48 Notebook

I have read quite a few things about the Google Chrome OS notebook, the cr-48, from people decrying that you can't get to files, etc. That's not entirely true.

Two ways that I know of are to enable developer mode by peeling back the sticker by the battery connection in the battery compartment, and switching that little switch toward the connector, then turning on the notebook, at the funky notebook-face graphic you hit CTRL-d and wait 5 minutes. Then after you have logged back in and re-synced, you can access a shell.

To do that, all you need to do is press CTRL-ALT-t. Then you are in the chrosh shell, which I can't find much use for, so I just type "shell" to get to a regular bash shell. At this point you are in a light-weight Linux.

Now, using regular 'ix commands, we can create a directory where we can use it, copy your files into it, and do what you will from there.

Air Quality Android App released

I have had an itch since getting my G1 some time ago, and that was to have a better way to view air quality information on my phone. There just wasn't a way to do it. So, I scratched my own itch, and created Air Quality, an Android app that will show you current particulate and ozone levels, and by clicking on the city you have chosen, will show you AirNow.gov's forecast for that city.

I am going to charge for this app so that I can get enough dollars from it to cover the Apple developer license, at which point I will release it for iOS devices.

You can find this app in the Android Market under "Applications -> Health" or by searching the market for "Air Quality" - it's the one published by my company, 33rd Prime.

Air Quality splash

Getting Appcelerator Titanium to Work on My Mac

After climbing a few rungs of the Java+Android SDK ladder trying to make my own apps, and partially succeeding, I begin to look around to see if there was a better/easier to grok way to make Android apps. I found the Appcelerator Titanium project, and had a big-ole wootfest!

Sadly however, I was soon to have the unfortunate experience of trying to get this pretty flakey thing to work.

Starting from an environment where I had already produced working code and gotten it from my computer onto both my phone and an emulator using the Eclipse IDE, I thought I would be 10 steps ahead. Nope. I met with many many errors such as the very much not helpful:

“Project creation error: Error creating project. Please try again.”

and the marvelously not helpful:

“[ERROR] Failed installing com.example.hello: pkg: /data/local/tmp/app.apk”

or the entirely show-stopping “Loading” + “Loading” display on SDK: and Screen:

Going back to Vim

Well, I have been all over the place on IDE’s and editors, and I am coming back full circle to Vim. It’s been around forever but seems to keep getting the love. After spending a good part of the morning ramping up my Vim setup after reading http://nvie.com/posts/how-i-boosted-my-vim/ I am all kinds of excited to try some of the new plugins I have installed.

Also, though I have had a good time working with Komodo Edit, and NetBeans I find I am still a lot more comfortable, and faster, in Vim. Also, used in conjunction with code snippet software, and some other speed up tips found in http://net.tutsplus.com/articles/general/9-ways-to-instantly-code-faster/ I am virtually flying when I actually do get to the point where I am coding.

The Story of Postfix and the Non-Local Domain Email Host

So I have been scratching my head for a little while over how to get Postfix to deliver mail from my www.example.com site off to an external mail host, when the email address has the same domain, @example.com.

What I discovered is that I needed to do 3 things:

  1. Set my machine hostname to be distinct, ie www.example.com (vim up your /etc/hostname and then hostname -F /etc/hostname)
  2. Set mydomain and myhostname to both be the same as the machine hostname, www.example.com (this is in /etc/postfix/main.cf)
  3. Restarted postfix

The key here for me was to ensure that the hostname (and Postfixes mydomain setting) needed to be different from the actual domain of the email addresses I was trying to get mail delivered to. At that point, I didn't need to deal with local host files, or luser settings, etc. The Postfix program just sees it as an external mail address and pushes it out like any other mail. Yay!

There are a bunch of other things you should probably set as well if you are just setting up your Postfix, run /etc/postfix/post-install first-install-reminder for a fun reminder of what you need to do. http://postfix.org is also a good resource for getting things setup.

Anybody that knows a better way, please comment!

How to hide a form field and keep the value

Just a quickie. Every so often in Drupal you will come across the need to hide a form field, but can't get rid of it, because it holds a value, or you need to show it to one roll but not another, etc. In cases such as this, it is good to remember '#type' = 'value'

Thanks to Eugen Mayer for refreshing me on that.

An example would be

<?php
/**
* Implementation of hook_form_alter()
*
*/
function cool_module_form_alter(&$form, $form_state, $form_id) {
  switch (
$form_id) {
    case
'wicked_cool_form':
      if (
$form_state['pigs'] == 'fly') {
       
$form['pigs']['field_pigs_can_fly']['#type'] = 'value';
      }
    break;
  }
}
?>

My Vim

Screenshot-views.module (-etc-acquia-drupal-6-sites-all-modules-views-DRUPAL-6--3) - GVIM
This is just an image of my vim setup looking at a Drupal module, bookmarks, and file tree (NERDTree) all visible, with Monaco as the font, and ir_black as the colorscheme. This is on Ubuntu, however MacVim looks pretty identical.

Pretty soon here I will make a blog post about how use Vim, and how I got this setup, along with my .vimrc file and .vim directory.

Adding permissions to a role programatically

I wrote this little bit of code after asking around to find out if there was a way to add permissions by role and came up empty. Ends up there is a nice module for doing this for install profiles and could be used for update functions as well I am sure. I haven't looked at it, but you can check out the Install Profile API.

This apparently has some nifty items that aid in your install profile construction (thanks Boris!), however all I need is to add some checks to some checkboxes on the Permissions page via code, so I am using this:

<?php

/**
* _add_permissions() is a helper function to add permissions by role to the db
*/
function _add_permissions($rid, $permissions) {
  if (!
is_array($permissions)) {
   
$permissions = explode(', ', $permissions);
  }
 
$current_perms = explode(', ', db_result(db_query("SELECT perm FROM {permission} WHERE rid=%d", $rid)));
  foreach(
$permissions as $permission) {
    if (!
in_array($permission, $current_perms)) {
       
$current_perms[] = $permission;
      }
    }
 
$current_perms = implode(', ', $current_perms); 
 
$return = db_query("UPDATE {permission} SET perm= '%s' WHERE rid=%d", $current_perms, $rid);
  return
$return;
}
?>

Powered by Drupal, an open source content management system