include

Drupal block/view tip - How to insert a block or view into your content area ($content)

Drupal block/view FAQ: How do I insert a Drupal block or Drupal view into my HTML content area ($content)?

There are several different approaches to this problem, depending on what you really want to achieve.

Insert a Drupal view into your HTML content

If you really want to include a Drupal view into your Drupal content, you can use the Insert View filter, as described on this Inserting Views page on drupal.org.

PHP cannot redeclare function error message

PHP function FAQ: Help, I'm getting a PHP cannot redeclare function error message, how do I fix it?

Assuming you don't really have two PHP functions defined with the same name, this "cannot redeclare" function error message is usually caused by using the require or include functions to include the same common file (and therefore its functions) more than once.

A JRuby jar include tip

Ever need to include a Java jar file in a JRuby script? As I work to convert my Mac speech recognition server to JRuby, the first task I need to tackle is to include the Sphinx-4 jar files in my JRuby path. You can include one Java jar file in your JRuby script path very easily, like this:

require 'lib/sphinx4.jar'

where the jar file 'sphinx4.jar' is in a local subdirectory named lib, which is cool. But if you need to include many Java jar files into your JRuby script at one time, here's a very cool way to do that:

PHP include syntax examples

PHP FAQ: Can you show an example of how to use the PHP include syntax? Also, can you show an example of how to include HTTP content into a PHP script?

PHP include syntax to include a file

Sure, I just used the PHP include statement in developing a Drupal theme, and a simple form of the PHP include syntax to include a file looks like this:

<? include 'google-analytics.inc' ?>

This includes the contents of the file named "google-analytics.inc" into my PHP page output.

My Drupal Google Analytics installation

Drupal FAQ: How do I install Google Analytics on a Drupal website?

There are two ways to do this, and I think they're both pretty easy. In the first approach you can just add the Google Analytics code to your Drupal template files, which is basically a copy and paste operation. However, if you don't want to do that, you can also use a Drupal "Google Analytics" module, and I share the link to that module below.

Perl modules FAQ - What to do when Perl modules aren't in their normal locations

Perl modules FAQ: I need to use a Perl module, but it isn't installed in the standard/default location, what can I do?

When you have root access to a Unix server, it's pretty easy to install Perl modules in their proper locations, and forget about them. But if you don't have root access and you need to install your Perl modules in non-standard directories, how will you get your programs to find your modules?

Java - Build an executable jar file by referencing your dependencies

Summary: How to build an executable jar file that has dependencies on other jar files.

If you ever need to create an executable jar file that has dependencies on other jar files, this tutorial is for you. I'll show you ever thing you need to do -- including the use of an Ant build script -- so your users can just type something like this at the command line:

java -jar my-application.jar

to run your Java application.

A Ruby substring example

Ruby substring FAQ: I can't find a Ruby substring method, how can I tell if one Ruby string contains another string?

Solution: I expected the Ruby String class to include a method named substring, but it doesn't. My personal disappointment aside, it does have a method named include? that works the way I expected it to. Here's a simple example, using the irbenvironment to perform a few tests.

Ruby NameError: uninitialized constant error message

Problem: When working with some Ruby code in an irb session, I just got the following error message:

NameError: uninitialized constant Tempfile

Here's a snippet of my irb session where this error occurred:

>> tmp = Tempfile.new
NameError: uninitialized constant Tempfile
	from (irb):1

Solution

This "NameError: uninitialized constant" looks intimidating, but it's actually not a big deal: I just forgot to require the tempfile package.

Put Perl test data in the same file as your source code

Perl test data FAQ: How can I store some sample/test data with my source code in Perl?

Answer: With Perl it's very easy to store some sample data in the same file as your Perl source code. Assuming you're creating a "main" Perl program (not a Perl module) you can use the special __END__ operator, and then include your data after that operator, as shown in my sample code below. You can then access that data using the main::DATA operator inside of a while loop.

Here's a quick sample program:

Syndicate content