blog.humaneguitarist.org

discoveries in digital audio, music notation, and information encoding

Archive for the ‘blogging’ tag

a switch to Syntax Highlighter Compress, a WordPress plugin

leave a comment

Just a note to self here.

Tonight I noticed some problems with Syntax Highlighter Evolved, the plugin I was using for code and XML snippets, etc.

I was trying to load a page with an XML snippet and my browser was reporting that it couldn't find the XML brush. Reinstalling the plugin probably would have fixed it but, all the same, I switched to Syntax Highlighter Compress which, true to its claims, does seem to work faster than other syntax highlighters I've tried.

--------------

Related Content:

Written by nitin

September 29th, 2011 at 10:30 pm

Posted in news

Tagged with , ,

a change of theme and missing WordPress comments

leave a comment

Last night, I discovered that some old comments from about a year ago were no longer showing up on this blog with the Journalist 1.9 theme.

So, I've spent far too much time playing around with themes tonight. I hate most WordPress themes because a lot of them, at least the free ones, don't seem to place a high value on readability. Too much razzle-dazzle.

For now I've switched to something else and, using the Journalist CSS file, I replaced some values in the current CSS to make the text look better to my eyes.

I guess at some point I should document the changes I made, huh?

Update, September 20, 2011: Aha! It seems that turning off the WordPress feature that automatically disables comments on old posts was the problem for the Journalist theme. In other words, Journalist – as well as many other themes it seems – won't show comments even if they exist if commenting is turned off for a given post. This includes commenting that's turned off manually or because WordPress was automatically disabling the ability to add new comments to posts that were over a year or so old.

I don't like that so I might tweak the Journalist behavior at some point. I think it's valid to turn off commenting for really old posts or because there are too many spammy comments appearing on a given post. But I don't think that means current users shouldn't be able to view older comments – those are often more valuable than the post itself!

--------------

Related Content:

Written by nitin

September 19th, 2011 at 9:24 pm

Posted in news

Tagged with , ,

tweaking Simple Download Manager, a WordPress plugin

leave a comment

I wanted a way to track downloads available through my blog without having to do a lot of work and without having to check server access logs.

So I installed Simple Download Manager (v. 0.21). It's great.

I did do one thing a little differently than the instructions in regard to editing my .htaccess file.

Here are the instructions:

The last step involves editing the '.htaccess' file. The default '.htaccess' skips default WordPress processing for existing files, which means that direct-linked files would get downloaded directly, without Simple Download Monitor ever learning about it. You need to modify the '.htaccess' file so that downloads are passed through Simple Download Monitor. This is easy enough to do: Open your '.htaccess' file and locate line RewriteCond %{REQUEST_FILENAME} !-f Add this line directly above it: RewriteRule ^(files/.*) /index.php?sdmon=$1 [L] (replace 'files/' with your download directory).

Other than changing the "files" folder to "uploads", I altered the line to read like this:

RewriteRule ^(uploads/.*\..*) /index.php?sdmon=$1 [L]

The reason for this is that using the default line would have prevented users from directly browsing directories through their browser. And that would have been a problem since with some projects I provide a link to a directory so people can download past versions of software.

For example:

Click here to download the latest Windows self-installer.

Click here to download the latest ZIP file.

Older versions can be accessed here.

Simple Download Manager will still track downloads for the types of files I've asked it to track whether the user downloads the file via clicking a link in a blog post or by downloading the file from the directory. That's exactly what I wanted.

I'm pretty lousy with regular expressions, so for my own notes here goes …

There are three parts, as I see it, to this regex:

.*\..*

Those parts are:

  1. .*
  2. \.
  3. .*

The first matches anything, the second makes sure the match ends with a dot, and the third means the match can have anything after the dot.

This matches filenames a la "filename.ext" but excludes directories.

By the way, this means I cannot name directories with a dot in the directory name, otherwise the RewriteRule will kick in on the directory – which won't work and the user won't be able to traverse that directory.

I guess I should learn the regex to allow me to create directories with dots in the directory name …

:/

Update, June 12, 2011: Actually, I've since reconsidered. I only want to track ZIP and EXE downloads. Doing otherwise would force users to have to download other file types like text and XML files. That's not a user-friendly approach. So, the addition to the .htaccess file now reads:

RewriteRule ^(uploads/.*\.zip) /index.php?sdmon=$1 [L]
RewriteRule ^(uploads/.*\.exe) /index.php?sdmon=$1 [L]

The two lines ensure that only ZIP and EXE files are processed by Simple Download Manager … and I can now make directory names with dots in them.

Update, November 26, 2011: I need to mention that this addition to the .htaccess file should not go in the WordPress block otherwise it will get periodically overwritten, preventing the download manager from working. It maybe better to just see an example …

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

#Notes: don't put anything in the WordPress block per: http://www.webpronews.com/keep-wordpress-from-overwriting-custom-htaccess-rules-2007-06

#Simple Download Manager
RewriteRule ^(uploads/.*\.zip) /index.php?sdmon=$1 [L]
RewriteRule ^(uploads/.*\.exe) /index.php?sdmon=$1 [L]
--------------

Related Content:

Written by nitin

June 12th, 2011 at 10:25 am

Posted in news,technophilia

Tagged with , ,

syntax highlighting with WordPress: that's not that!

leave a comment

A few months ago I posted on how I used the Syntax Highlighter Evolved plugin for WordPress to make code snippets more readable.

Anyway, at the time I was really excited to be able to put some nice looking code/markup into my posts. Never mind that the code itself wasn't so nice!

:P

Over time, of course, I've wanted to make things easier. As I mentioned in the earlier post I was pasting in my code using Deans' FCKEditor, using the Styles drop-down to mark up my code as <code> and then in turn editing the source HTML to change the <code> tag to a <pre> tag with the appropriate attribute to denote that my code was either Python or XML, etc.

Well, as I remarked to a friend of mine today over lunch, I'm sick of doing that.

So I dug around in all the files that are part of Dean's FCKEditor. I learned that by editing the "ckeditor/plugins/stylescombo/styles/default.js" file that I could add options to the Styles drop-down menu. Now, when I paste in Python, XML, or Javascript I just need to highlight the code and pick the right option from the Styles list. It's SO much easier.

Here's an image of the Styles list with the added options mentioned:

If you are curious to see the .js file with the minor additions, I've pasted it below – and even highlighted it using the new Code: Javascript option.

/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.addStylesSet('default',[{name:'Blue Title',element:'h3',styles:{color:'Blue'}},
{name:'Red Title',element:'h3',styles:{color:'Red'}},
{name:'Marker: Yellow',element:'span',styles:{'background-color':'Yellow'}},
{name:'Marker: Green',element:'span',styles:{'background-color':'Lime'}},
{name:'Big',element:'big'},
{name:'Small',element:'small'},
{name:'Typewriter',element:'tt'},
{name:'Computer Code',element:'code'},
{name:'Keyboard Phrase',element:'kbd'},
{name:'Sample Text',element:'samp'},
{name:'Variable',element:'var'},
{name:'Deleted Text',element:'del'},
{name:'Inserted Text',element:'ins'},
{name:'Cited Work',element:'cite'},
{name:'Inline Quotation',element:'q'},
{name:'Language: RTL',element:'span',attributes:{dir:'rtl'}},
{name:'Language: LTR',element:'span',attributes:{dir:'ltr'}},
{name:'Image on Left',element:'img',attributes:{style:'padding: 5px; margin-right: 5px',border:'2',align:'left'}},
{name:'Image on Right',element:'img',attributes:{style:'padding: 5px; margin-left: 5px',border:'2',align:'right'}},
/* start of added options */
{name:'Code: Python',element:'pre',attributes:{class:'brush:python'}},
{name:'Code: XML',element:'pre',attributes:{class:'brush:xml'}},
{name:'Code: Javascript',element:'pre',attributes:{class:'brush:javascript'}}
/* end of added options */
]);
--------------

Related Content:

Written by nitin

March 13th, 2011 at 10:48 pm

tweaking Efficient Related Posts, a WordPress plugin

2 comments

There are so many plugins for WordPress that it's easy to get carried away and install more than necessary. I hope I've avoided that. I try to limit myself to plugins that can really improve the reader's experience.

The other day, I installed Efficient Related Posts (0.3.6). It's a great tool to generate a list of hopefully related posts on my blog. There should even be some listed below this post.

;)

Under the settings, you can alter what the header says and even have it auto-generate related posts for every blog post. For example, I changed the header "Related Posts" to "Related Content".

But one thing I didn't see the settings offer is a way to hide that header in cases where no related content was generated.

In other words, when no related content was generated it was displaying something like "Related Content: no related posts found." I don't want people to see that so I tweaked the code in the main plugin script using WordPress' plugin editor.

Here's the code below. It's only a minor change for the "if" block that starts at around line 307.

if ( !empty($settings['title']) && !empty($relatedPosts)) {
	$output = "--------------<h4 class='related_post_title'>{$settings['title']}</h4>{$output}";
	/* Nitin Arora modified the code above on 20101219 to display differently.
	By adding the "&& !empty($relatedPosts)" condition, only posts/pages with related content
	will show the related content header.
	A few "-"s were added to offset the related content header for readability.
	Also, the <h4> tag was originally an <h3>. */
}
--------------

Related Content:

Written by nitin

December 20th, 2010 at 12:12 am

syntax highlighting with WordPress

leave a comment

Thankfully, pretty much nobody reads this blog.

If they did, they'd have seen a lot of weird changes going on in real-time concerning some XML code in a recent post.

Basically, I've been playing around with various WordPress plugins that support syntax highlighting, which is a fancy way of color-coding code examples with color-coding specific to various scripting and markup languages like PHP, Python, XML, etc.

Anyway, after playing around with several, I was running into the same issue with the indent stripping as talked about here. The use of indentation is paramount to making one's code readable and in some languages, like Python, indentation is required.

In other words, this is valid Python code:

if a == a:

print "The 'a' variable is equal to itself!"

But this is invalid:

if a == a:

print "The 'a' variable is equal to itself!"

because the print statement is dependent on a condition.

Anyway, what was happening was that I'd put code into WordPress, the indentation and highlighting would look good, but if I wanted to edit my post later all the indentation would be lost when I'd reopened the post in the editor (btw: I use Dean's FCKEditor).

So here's what appears to fix it:

  • I installed my preferred WordPress syntax highlighter: Syntax Highlighter Compress Syntax Highlighter Evolved.
  • I wrote my post and pasted my code directly into the Visual Editor.
  • I then highlighted only the code and from the Visual Editor's "styles" drop-down menu I chose "Computer Code".
  • I then edited the post in Source mode.
  • I replaced the <code> tags with <pre> tags.
    • The opening <pre> tag needs a "class" attribute to specify the type of code (i.e. Python, XML, etc.)
    • For example, I'd use this for Python:
      • <pre class="brush:python">
    • and this for XML:
      • <pre class="brush:xml">

From then on, everything seems to be OK. That is to say, I can edit my post at a later time with the Source or Visual Editor and all my indentations are intact.

Here's the earlier Python code using the technique just described:

if a == a:
	    print "The 'a' variable is equal to itself!"

And that's that … I hope.

:P

--------------

Related Content:

Written by nitin

September 6th, 2010 at 2:39 pm

blog.humaneguitarist.org launches

leave a comment

I gave into Facebook, now I'm giving into blogging.

I figure it's a good way to add some level of organization to the research I do. Plus, I think blogging is increasingly looked upon as a yet-unwritten necessity for library job applicants, it's a way to provide future fodder for potential articles, and it'll keep my writing chops alive.

--------------

Related Content:

Written by nitin

August 2nd, 2009 at 4:00 pm

Posted in news

Tagged with ,

Switch to our mobile site