Get a Drupal node using a node id

If you would like to access node data but only have the node id ($nid in this case) all you need to do is:

$node = node_load($nid);


This lacks some "content". To generate that we can take this one step further:

$node = node_build_content(node_load($nid));

Armenian Prime Minister Visits SLAC



The Armenian Prime Minister made a low profile visit to SLAC yesterday (photo above by Brad Plummer - see SLAC Today article). He even took a tour of NLCTA and must have seen my handy work :-) In fact I was busy trying to get a picture to help plan future work when I got kicked out of the accelerator upon his arrival. I still got the pic though:


Setup Blogspot statistics (hit counter)

Need a counter for your Blogspot page? I found a solution that works for Blogspot as well as any other website you might want to track the statistics of.

Check out Google Analytics. I'm sure there are many other services offering the same package, but Google worked for me.

It's pretty straight forward to set up Google Analyitics, so I won't give a detailed account of how to do it. Here's the gist: (1) Sign up here, it's free!, (2) Once you've set up the account Google will give you a script to add to your website. Paste the script on pages you want to track. (3) For Blogspot just paste it right before the </body> tag at the end of your html "layout" page.

Make HTML, C++, PHP, etc code colored on web pages

Ever wished you could color the source code of your programs on your html/web pages? Google makes it easy. All you need are two files and a little work: prettify.cs and prettify.js. These can be downloaded from Google and placed on your server or you can just reference them.

Step 1: Place the following source code between you're <head> and </head> tags:

<link href="http://google-code-prettify.googlecode.com/svn
/trunk/src/prettify/prettify.css" rel="stylesheet" type="text/css"/>
<script src="http://google-code-prettify.googlecode.com/svn
/trunk/src/prettify.js" type="text/javascript" />


If you downloaded the two files to your server, change the URLs above to point to the files you downloaded.

Step 2: Add onload="prettyPrint()" to your body tag (located just after the closing head tag usually) as follows:

<body onload="prettyPrint()">


Step 3: Google pretty print should now be working. If you want to "color" some code you just need to wrap it in <pre> tags as follows:

<pre class="prettyprint">"Test Code String"</pre>


and you should get:

"Test Code String"


Perhaps we should try something more exciting? How about a C++ snippet?

/* Test C++ comment and code snippet */
for ( int i = 0; i < 10; i++ ) {
cout << "Hello, World, ten times!" << endl;
}


Beyond step 3: Now what? Well, pretty print will automatically figure out what language you are trying to format. However, if you wish to specify a language specifically, you can change your <pre> tag slightly. Let's say we want to do html. Then we would use: <pre class="prettyprint lang-html"> instead of just <pre class="prettyprint">. So what languages can we do? Hmmm... I'm not sure, but I know we can at least do: "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml", "xsl" and probably more? Not to shaby!

Also, if you want to do html. Make sure you use "&lt;" and "&gt;" to represent "<" and ">" or your tags may not appear.

More? Yes, if you wish to edit what colors are used. Try editing prettify.css.

"Pro Black" Blogger-Blogspot Template in Blue

I absolutely love the "Pro Black" theme by TemplateLite.com. But in orange?

So here's my attempt at making it blue. It's not perfect but it's a lot better than orange. If you want to see it live, it's the theme I'm using for the blog you're presently reading. If I make improvements to the css/xml in the future, I'll be sure to update the link to the attached template/theme/layout/whatever below:

Download "Pro Black" in blue now...



Link to any "node" using Drupal

I need to get better at posting on a more regular basis. Maybe if I start making a habit of it even if it's something simple. Today let's take a look at how to link to a node in Drupal that all users will have access to (even without admin. privledges)...

l(strip_tags($node->title),"node/".$node->nid);


l() is Drupal's way of making links. $node->title will be what the user sees. "node/".$node->nid is the URL for the node. That's all there is to it.

Soccer @ SLAC

A coworker of mine made a poster to promote soccer here at the lab :-)
It looks like most of the regulars made an appearance!