Posted 12. June 2008
Based on some notes from this page , I wrote the following in a shell script to determine the absolute path to the script if the script is called from the command line using a relative path:
#! /bin/bash
ScriptLocation="`pwd`"/"`dirname $0`"
`dirname $0` is the relative path to the script from the current working directory. I add `pwd`, the absolute path to the current working directory, to obtain the absolute path to the script.
If the script is called from an absolute path, such as /Users/josh/location_aware.sh, this outputs a nonsense path: /Users/josh//Users/josh. This is because $0 is the name of the file that Bash is invoked with. If Bash is invoked with an absolute path, then `dirname $0` will be an absolute path. I added a few more lines of code to check whether $0 was a relative path and wound up with the following:
#! /bin/bash
if [[ $0 == '/'* ]]; then
ScriptLocation="`dirname $0`"
else
ScriptLocation="`pwd`"/"`dirname $0`"
fi
These snippets output the directory in which the script resides; replace `dirname $0` with $0 to obtain the path to the script file itself.
0 comments
Posted 8. June 2008
To manually load SnippetsEmu’s Django model and template snippets, I run the following command in Vim:
:runtime! ftplugin/django_*_snippets.vim
Following the Using Vim with Django guide, I added the following lines to my python.vim file:
if getline(1) =~ 'from django.db import models'
runtime! ftplugin/django_model_snippets.vim
endif
filetypes.vim detects django templates as the filetype htmldjango, so all that needs to be done to enable the template snippets is to rename django_template_snippets.vim to htmldjango.vim. Creating htmldjango.vim with the one-liner
runtime! ftplugin/django_template_snippets.vim
has the same effect.
0 comments
Posted 4. March 2008
Bad thread titles such as “help with coding,” “looking for a solution,” “can anyone help me?,” and “Help!” are common on many technical forums. A bad thread title can make it difficult to get help because your thread cannot be easily found. I propose a technical solution to prevent threads with these titles from being created and educate users about how to choose better titles.
Many of the worst and least-descriptive thread titles could be easily detected by a simple filter that removes punctuation, whitespace, and certain words from the thread title and checks if any characters remain. If more than 0 characters remain, the original string would be used as the thread title. If 0 characters remain, the user would be prevented from posting their thread and given suggestions for better titles. The aggressiveness of the filter could be controlled by modifying the wordlist.
The words in the string “looking for a solution,” for example, would be checked against a list of words to exclude from the length check. Since all of these words would be in the list, they would be removed, leaving the string with a length of 0. “Looking for a solution for PNG transparency in Internet Explorer” would pass the length check because it contains descriptive words.
A second stage of filtering could be used to catch questions with yes or no answers such as “Does anyone know how to make transparent PNG files?” and rewrite them as “How do I make transparent PNG files?” This could be easily accomplished with regular expressions.
If anyone has ideas for other techniques for filtering thread titles or has suggestions on how to implement these filters in a forum plugin, please leave a comment.
0 comments