The Coded One

programming, algorithms, discrete math, open-source

Using Disqus Plugin in Joomla

with 9 comments

Disqus Comment System is a plugin that provides seamless integration between Joomla and the popular commenting system Disqus.

Installing the plugin is pretty straightforward but there are a few gotcha’s.

Troubleshooting

No comments/links are showing up.

  • Check if the plugin is enabled.  (not enabled by default)
  • Open template/html/com_content/article/default.php and make sure that the following lines exist.
  • <?php echo $this->article->event->beforeDisplayContent; ?>
    ...
    <?php echo $this->article->event->afterDisplayContent; ?>
    

There is no Add New Comment section.

  • Verify your plugin setting.  The subdomain value should only be the name and not the entire URL. ie. mysite.disqus.com

Adding an Exclude List

Currently, there’s no setting for enabling/disabling comments per article so I did a few hacks.

plugins/content/jw_disqus.xml – Add this line before the </param> tag

<param name="disqus_excludelist" type="text" default="" label="Exclude list" description="Do no show comments for articles having these ids (comma separated)" />

plugins/content/jw_disqus.php – Create a new function that checks if the id of the article is in the exclude list.

/**
  * Check if the id of the current article is included in the excludelist parameter
  */
function isExcluded($article_id){
	$plugin =& JPluginHelper::getPlugin('content', 'jw_disqus');
	$pluginParams = new JParameter( $plugin->params );	
	$disqus_excludelist = $pluginParams->def('disqus_excludelist','');
	if(in_array($article_id, explode(',', $disqus_excludelist))) {
	    return true;
	}
	return false;
}

Now simply return nothing in the callback functions if the article is in the exclude list.

/** just before content is output, returns output to be displayed */ 
function plgJWDisqus_onBeforeDisplayContent( &$row, &$params, $limitstart ){

    if(isExcluded($row->id)) {
	    return;
	}
...
/** just after content is output, returns output to be displayed */ 
function plgJWDisqus_onAfterDisplayContent( &$row, &$params, $limitstart ){

    if(isExcluded($row->id)) {
	    return;
	}
...

You should be all set after this.

Written by Mark Basmayor

April 27, 2009 at 10:55 pm

Posted in Joomla, PHP

Tagged with , , , ,

TiddlyWiki + TiddlySnip + TiddlySpot as a Google Notebook Alternative

with 2 comments

Last January, Google announced that they will stop supporting Google Notebooks.  FInd out more in their official blog.

Although they promised to keep the existing notes intact, I though that it was a good opportunity for me to look for alternatives.

Come TiddlyWiki.  TiddlyWiki is a single-file, self-contained wiki for managing micro-content, written in JavaScript.  And there are lots of compelling reasons to use it.  Some of which are:

  • It’s a single file – meaning it’s portable, you can easily save it in your USB drive or upload it somewhere
  • It’s self-contained – The single file that is a TiddlyWiki contains not only all of your data, but all the machinery to edit and manipulate it
  • It’s a wiki – it allows collaboration
  • It manages micro-content – so it’s really well fitted for small notes not like other wikis which I think are more page-oriented

tiddlywiki preview

Tiddly Wiki

Read the rest of this entry »

Written by Mark Basmayor

March 16, 2009 at 5:47 am

Enable mod rewrite in Apache2

with 6 comments

  1. tell apache to enable the module
    sudo a2enmod rewrite
  2. edit apache’s configuration file and change allow override from None to All
    sudo vim /etc/apache2/sites-available/default
  3. restart apache
    sudo /etc/init.d/apache2 restart
  4. test by creating an .htaccess file containing the following code
    Options +FollowSymLinks
    Redirect /test.html http://www.ubuntu/com
  5. You should be redirected to the Ubuntu site instead of getting a 404 error.

Written by Mark Basmayor

March 14, 2009 at 6:43 am

Posted in apache, Linux, Ubuntu

Tagged with , ,

Which Programming Language Are You?

with 6 comments

I was really getting swamped with programming a moment ago so I decided to surf a bit and stumbled on an online quiz.

I’m not really a fan of these things but since I just love doing things that require minimal thinking when I’m tired from coding, I decided to go ahead.

Which Programming Language Are You?

You are Java.  You are very strong and sturdy, but this makes you a bit sluggish.

Interesting… I have always considered myself to be “Java Man” or is Java starting to take over my consciousness and body?

I had to admit, I had a bit of fun so I decided to take the other test.

Which OS are You? ( Anything but Windows pls )

You are Windows XP.  Under your bright and cheerful exterior is a strong and stable personality.  You have a tendency to do more than what is asked or even desired.

Mark is at wits end.

I hate online quizzes.

Written by Mark Basmayor

March 2, 2009 at 6:45 pm

Posted in random thoughts

Setting Up Tomcat on Ubuntu

with one comment

Prerequisites

Tomcat 6.0 requires JRE 5.0. Read the RELEASE-NOTES and the RUNNING.txt file in the distribution for more details.

Installation

1. Download binary core from apache site.

wget http://apache.tradebit.com/pub/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

2. Extract the tarball under /usr/local/

Note: Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.

tar xvzf apache-tomcat-6.0.18.tar.gz

3. Tomcat requires that you set the JAVA_HOME variable. If you haven’t done it yet, you can do so by adding the following line in your .bashrc

export JAVA_HOME=/usr/lib/jvm/java-6-sun

4. We can test if Tomcat is running by running the startup script then opening a browser and accessing http://localhost:8080

sudo /usr/local/tomcat/bin/startup.sh

Details on troubleshooting can be found on RUNNING.txt

Read the rest of this entry »

Written by Mark Basmayor

March 2, 2009 at 5:37 pm

Posted in Java, Ubuntu

Tagged with , , , ,

Setting Up MySQL/JDBC Driver on Ubuntu

with 26 comments

Assuming that you already have MySQL installed, the next step is to install the connector driver. You can do this easily on the CLI by using the following command:

sudo apt-get install libmysql-java

The next step is to make sure that the classpath is set. You can have this set automatically by adding this command to you bashrc file.

export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar

If you want to set this for all users, you should modify the /etc/environment instead.

For those using Eclipse, you can also do this by going through the following steps:

  1. Select Project Properties > Java Build Path
  2. Select Libries tab
  3. Click Add External Jars
  4. Choose the jar file, in this case mysql-connector-java.java

Once you’re done, you can test the connection using the following snippet:

import java.sql.Connection;
import java.sql.DriverManager;

class JDBCTest {

	private static final String url = "jdbc:mysql://localhost";

	private static final String user = "username";

	private static final String password = "password";

	public static void main(String args[]) {
		try {
			Connection con = DriverManager.getConnection(url, user, password);
			System.out.println("Success");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Written by Mark Basmayor

March 1, 2009 at 1:32 pm

Posted in Java, Ubuntu

Tagged with , , , ,

Writing Better Conditional Statements

with 17 comments

1. Use 1 == foo instead of foo == 1.  Srsly.

At a glance, you might think that the following statements are the same as dictated by logic and the property of commutativity.

if( foo == 1 ) {
...

and

if( 1 == foo ) {
...

Well logically yes, but in a pragmatic point of view, the second one is better because it makes the compiler barf an error whenever you’re in a zombie programming mode and you write = (which assigns the value to the variable instead of checking for equality) in lieu of ==.
I just can’t imagine how much time I spent debugging before, only to find out that I missed a single character.

2. Proper use of .equals

First of all, when comparing strings, always use .equals. The == operator compares references and not values.
Now, if you’re checking for a “” or a null string, use the following form:

if( "".equals( foo ) ) {
...

This way, you do not get a Null Pointer Exception whenever the variable is null.

Written by Mark Basmayor

February 28, 2009 at 4:49 pm

Introduction to SOAP

with 3 comments

What is SOAP?

By merely looking at what SOAP stands for, we will already have an idea of what it is. So lets try to break it down:

  • Simple – easy, non-complex
  • Object – Let’s use the programming cliche:  “Everything is an object”
  • Access – the right to obtain or make use of
  • Protocol – A set of rules that lets computers agree how to communicate over the net

So what does this tell us? Soap is an easy way of getting or using objects across a network or commonly, the Internet.

Read the rest of this entry »

Written by Mark Basmayor

February 26, 2009 at 5:33 pm

Posted in PHP

Tagged with , ,

Developing with VIM

leave a comment »

VIM or Vi Improved is a text editor that is very popular among programmers especially those working in *nix environments.  It was originally released by Bram Moolenar in 1991 for the Amiga computer.  http://en.wikipedia.org/wiki/Vim

I have to admit that when I first used VIM, I was very skeptical.  I thought that it was “just another text editor” like nano or pico.  But since I’ve been hearing lots of good things about it, I finally decided to give it a shot.

vim screenshot

I wasn’t immediately converted as a vim user.  I’m used to IDEs like Eclipse and NetBeans.  I was missing lots of things like code completion, folding, automatic formatting, etc not to mention the fact that it was completely a different environment (modal).

But eventually I got comfortable and started having fun with it.  And now with VIM 7 I can do everything that I’ve been missing.  It’s got a legitimate syntax highlighting, code completion, auto formatting, etc.  And you can continue to buff it with plugins and a decent vimrc.  Here’s the one that I compiled based on some of the best vimrcs that I saw.

Some of the reasons why I prefer using it over an IDE are:

  1. It’s lightweight.  It’s blazing fast compared to launching Eclipse.  This comes very handy when you only need to write/edit several lines of code.
  2. You can use it over SSH.  If there’s a file that you need to open/modify on the fly on a remote location, this is just the way to go.  I mean who would like to download, modify, re-upload?
  3. The transition is seamless when in a terminal.  There’s just no better tool for editing config files/scripts.  Also, FYI the bash shell uses VIM mode by default.
  4. You can search/replace using regular expressions.  This feature is one of the reasons why I kept going despite the steep learning curve.
  5. Finally I just don’t see any limit to its capabilities since you can always add custom scripts and install plugins.  Btw, there are over 2,000 plugins that you can choose from in the plugins section of vim’s website.

Written by Mark Basmayor

February 26, 2009 at 3:37 pm

Posted in Linux, Ubuntu

Tagged with , ,

Removing Trailing Spaces in VIM

with 2 comments

We all hate trailing spaces when programming, so here’s something that will rid us of that forever.

Before quitting, execute this simple find and replace command in VIM.

:%s/s+$//

What this does is it looks for one or many instances of space (s) just before the end of line ($) and replaces it with a null string.

Even better, you can have this command execute every time you save by binding this to the save command in your .vimrc (vim configuration file).

autocmd BufWritePre * :%s/s+$//e

Written by Mark Basmayor

August 22, 2008 at 2:14 am

Posted in Linux, Ubuntu

Tagged with , ,