Sunday, February 14, 2010

Cheetah Templates Bug

I would never have found this bug report if I hadn't figured out the problem myself, because there's no reference in it to the error message you get. Here's what happens:

  • You use Cheetah templates
  • One of them includes a keyword that is the same as a method of a Python dictionary (e.g. $items, $update, $keys, $values)
  • You get an error ending with "Cheetah.NameMapper.NotFound: cannot find ''"
  • You get angry
Hopefully, then the following will happen:
  • You Google and find this post
  • You change your keyword
  • You smile
You're welcome.

Wednesday, May 27, 2009

Remove Line Breaks in Paragraphs in Emacs

Include the following in your .emacs, or somewhere else:
(defun remove-line-breaks ()
"Remove line endings in a paragraph."
(interactive)
(let ((fill-column 90002000))
(fill-paragraph nil)))

(defun remove-all-line-breaks ()
"Remove all single line-breaks in a document"
(interactive)
(while (not (= (point) (buffer-end 1)))
(remove-line-breaks)
(next-line 1)))

Then position your cursor at the top of a stretch of paragraphs that need to have line breaks removed, and do:
M-x remove-all-line-breaks RET
It will remove all line breaks between there and the end of the buffer.

Friday, January 30, 2009

Using py2exe for PyGTK apps

Here's a simple setup.py file that does most of the work (obviously, you'll have to edit the variables at the start):


from distutils.core import setup
import py2exe

appname = "Application Name"
appdescription = "A description of what the application does"
scriptname = "the-script-name.py" #the python script to compile
iconfile = "the-application-icon.ico" #must be a .ico

setup(
name = appname,
description = appdescription,
version = '1.0',

windows = [
{
'script': scriptname,
'icon_resources': [(1, iconfile)],
}
],

options = {
'py2exe': {
'packages':'encodings',
'includes': 'cairo, pango, pangocairo, atk, gobject'
}
}
)


When you've run it, copy the folders etc, lib, and share from your installation of GTK (not PyGTK) into the dist folder the script created. You can prune their contents judiciously if you know what you're doing, but this will let GTK find the theme and other files it needs.




EDIT: Note that py2exe seems to have problems with Python 2.6. I'd recommend sticking to 2.5 for whatever machine you build Windows executables.

Tuesday, January 27, 2009

LaTeX: Continue enumerating after a break

After your \documentclass{}:

\usepackage{enumitem}

Then, begin and end a list as usual, type the stuff that interrupts it, and continue the list with:

\begin{enumerate}[resume]

Your list will resume at the next number.

Sunday, November 9, 2008

Inserting the output of a shell command into the current buffer in Emacs

Simple:

do: C-u M-!
then enter the shell command in the mini-buffer.

e.g.: C-u M-! date inserts the current date and time if you're on Linux. If you're using Windows, it inserts a lot of crap because that's the command to set the date.

Monday, November 3, 2008

Creating PET Packages for Puppy Linux

It's pretty simple, just the usual configure, make, make install process, but with a couple twists, you can make the package work on older processors and still perform well on new ones:

  • Untar the source
  • cd into the extracted directory
  • do ./configure --host=i486-pc-linux-gnu
  • do make CFLAGS="-march=i486 -mtune=i686"
  • do new2dir make install; follow directions
  • exit and cd up one directory; clean up the directory as needed
  • do dir2pet; follow directions
That's all it should take.