Blogs

Getting Rid of Drupal's Blog module "username's blog"

roland's picture

Edit your page.tpl.php and and modify the title section with the following code to remove the person's blog

<?php if(strpos($title, "'s blog") === false) { if ($title): print '<h2 class="title'. ($tabs ? ' with-tabs' : '') .'">'. $title .'</h2>'; endif; }?>

PHP and html_entity_decode (&rsqo; &trade; &hellip; etc)

roland's picture

I was having a hard time with getting some xml data pumped into flash because the encoded characters were not being decoded properly. In my case ’

Luckily someone had already found the solution http://bugs.php.net/bug.php?id=42023

I changed my code from:

$desc = html_entity_decode($row['description']);

to

$desc = html_entity_decode($row['description'], 0, 'UTF-8');

and it all seems to work well.

Customizing Primary Links in Drupal 6

roland's picture

Working with Drupal can be a headache when you are learning the ropes, but it's one of the best CMS out there. I wanted to add ids to the primary links so I can style them with CSS. Here's how I did it:

1. Create or edit your template.php in the your current theme folder (i.e. themes/your_theme/template.php)

2. Edit the function or create the following function in template.php

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  $current_language = $vars['language']->language ;
  foreach ( array('primary_links', 'secondary_links') as $menu_name ) {
    if (! empty($vars[$menu_name])) {
      foreach ( $vars[$menu_name] as $menu_key => $menu_item ) {
        if ( $menu_item['langcode'] != $current_language && ! empty($menu_item['langcode']) ) {
          unset($vars[$menu_name][$menu_key]) ;
        } else {
			$vars[$menu_name][$menu_key]['attributes'] = array('id' => strtolower(str_replace(" ", "_", $vars[$menu_name][$menu_key]['title'])));
		}
      }
    }
  }
}

3. Disable and re-enable your current theme. I disabled it and enabled Garland. You will need to do this only once. After this, any changes, to this function will be made available to you immediately.

This technique works in customizing secondary links too.

4. Now in your page.tpl.php add the following code:

<?php if (isset($primary_links)) :
  print theme('links', $primary_links, array('class' => 'links primary-links'));
endif; ?>

You may have to disable the primary links from the blocks admin page.

The economics of Farm Town, a game on Facebook

roland's picture

I quite like the Farm Town game on Facebook. It's mainly written in ActionScript and you can analyze the way it works by decompiling the swf file using a product such as Sothink SWF Decompiler . For a geeky look at how messaging is managed you can use a tool such as Charles Proxy. Your farm data is stored on some database backend with counters and timers calculating the progress of your farm. Probably, scheduled tasks mark when your crops are ready for harvest.

The idea in the game is that you plow, plant, and harvest seeds: such as Grapes, Tomato, Rice, Corn, Potato, Strawberry, etc. Your seeds cost coins, and you get to harvest them in a given number of days. Then you sell your harvest for profit. In addition to the profit you pay 20 coins each patch on the farm. You also gain experience by farming and various things get unlocked so you can purchase them such as houses, flowers, etc.

Below is a screenshot of what the seeds cost.

Seed Table

Someone made a comment that Tomatoes were more profitable, other swear by Coffee and so on. So, I decided to run analyze the profits of a 12 day farming experience for a single patch of land.

 

 

WildCare Inc Rocks!

roland's picture

Last Saturday my neighbor brought a baby bird which had many feathers missing, and a slight wound on his back. He claimed that his dogs had probably caused the damage to the bird.

Trish and I feed the birds out side; we regularly buy a lot of seed for this. This is what gave my neighbor the idea that we were most likely able to help this bird. At first we were confused, but we took the bird in and placed it in the bathroom which was quite warm. Trish created a small nest with a towel and placed the bird inside. We gave the baby bird some seeds too, but I don't think he was used to eat by himself.

A quick search on the internet brought WildCare Inc. They were open 7 days a week 8am-8pm. We left a voice mail and hopped they would return our call on Sunday, since it was quite late. We grew a bit impatient so we started doing some research.

It turns out there's quite a number of people out there that do wild life rescue. Many specialize in mamals, others in birds, and some are very specific such as humming birds. Here's a list of some wild life rescue people and organizations http://www.tc.umn.edu/~devo0028/contactA.htm. The phone numbers of most people on that list are not currently active, so try as many as you can.

On Sunday we took the baby bird at WildCare Inc., and they were very friendly. We liked the place so much that we donated some money. If you can please consider donating to WildCare Inc. They are mostly volunteer based and all your money will go towards providing care for Deer fawns, wild birds and a lot of different kinds of critters. We also signed up to volunteer there.

Why flash sites are a headache to maintain

roland's picture

From the view point of a system administrator flash based sites are quite difficult to maintain, mainly because of rigid coding. The problem of concern arises when flash sites load external resources, or post data to external resources and specify the statically define the host where the resource resides.

Let us assume, you created a flash form that will post the data to some PHP file to do some server operations. If you were to say that the sites is on subdomain.domain.com, changing the subdomain at a later date is difficult, because cross site requests are not allowed by Flash (justly so).

The solution: crossdomain.xml

Add a CNAME record to your DNS server: new_subdomain.domain.com is CNAME for subdomain.domain.com

At the root directory of your site create a crossdomain.xml file with content as described by adobe at: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14213.

Modify allow-access-from domain="www.company.com" to be allow-access-from domain="*.domain.com", where of course domain.com is your domain of concern.

If someone needs to change the domain, change the CNAME record and you're done. Of course you can always ask the developers to recompile their flash code, but that cannot always be an option with people leaving the company.

PHP's var_dump equivalent in Ruby on Rails

roland's picture

The PHP function var_dump is a very important tool for web developers as it allows one to inspect the variables of an object, or show the elements in arrays. In Coldfusion, the equivalent of var_dump is the cfdump tag.

Rails inherits has Ruby's inspect function for all variables, but sometimes it is rather useless if you are looking at big arrays. Here's an alternative:

<%= content_tag("pre", YAML::dump(var_name)) %>

Streaming Video to G1 (Android)

roland's picture

Last time I wrote about how you could convert flv files to mp4. The powers of ffmpeg are rather cool!

I own a G1 phone and I want to be able to stream the MP4 videos directly to my phone. Straight MP4 format doesn't work because the android player has no idea how long the movie is so it may buffer the stream properly.

A popular protocol RTSP can be used, but also straight HTTP works.

In Ubuntu install the gpac package:
sudo apt-get install gpac

The add hints to an MP4 file using:
MP4Box -hint filename.mp4

Now you can stream the video directly from your video player. Skipping forth and back is quite responsive.

How about using a proper protocol to stream your videos? To the rescue comes Apple's Darwin Streaming Server. The Install script is quite crappy for Ubuntu, but Lincoln Stoll has come up with a deb package, which you can also download here: DarwinStreamingSrvr6.0.3-Linux.deb (22MB)

sudo dpkg -i DarwinStreamingSrvr6.0.3-Linux.deb

Next reset the password for admin using:

sudo qtpasswd admin

Finally go to your site: http://yoursite.com:1220/ , and follow the configuration settings. When asked whether to stream from port 80, don't allow that if you are using an HTTP server on that machine. More details are found here.

Syndicate content