Entries by mark

Apache Enable Directory Browsing (Indexes) in Arch Linux

We had a VirtualHost defined for a simple website; we wanted to enable directory browsing for this (password protected) site. Simple, right? Despite all of my Google searching, adding "Options Indexes", "Options +Indexes", "Allow Overrides" and adding .htaccess files, we were unable to get directory browsing working. A quick look at the http error_log revealed this error:

Directory index forbidden by Options directive: /path/to/files

Our VirtualHost config, looked like this (below); it was all good, so that error turned out to be very misleading.

<Directory /path/to/files>
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from ...

Python/Django Tips n' Tricks Cheatsheet

Converting a unicode string to a list of strings
http://stackoverflow.com/questions/5001385/unicode-to-python-object-conversion
n = [e.encode('utf-8') for e in s.strip('[]').split(',')]

Converting a list of longs to a list of intsnew_list = [int(e) for e in queryset]


Template Tag Variables

If you've ever needed to save a variable spot in a Django template to be rendered later, there's special tags that allow you to do this:

{% templatetag openvariable %}somevariable{% templatetag closevariable %}

When this code is rendered by Django, you'll be left with a nice:

{{somevariable}}

in your rendered template.


Coldfusion - java.io.IOException: No space left on device

If you run into a "java.io.IOException: No space left on device" error when running ColdFusion, check your hard disk space.  If you've inspected your hard disk space, and still have open space on your drive, check your /tmp directory.  We're running ColdFusion 8 on Archlinux and this error wasn't too easy to diagnose.  A df -h lead us to believe that we had plenty of disk space available, but a df -T revealed that our /tmp directory had filled up. It was so full that Arch wasn't able to empty it on reboot, like ...


Linux Auditd Service and SSH Login

We have a CentOS 5.x box that strangely stopped allowing us to ssh in.  It would allow you to enter a username, prompt you for a password, and then just hang there, eventually timing out.  We tracked the problem down to a service, auditd, that acts as a central system logger, rather than /var/log/messages.  We found errors stating "kernel: audit: backlog limit exceeded" in our messages log.

The auditd service allows you to run some interesting little summary reports on access/processing that occurred on your machine within a given timeframe. Some examples:

aureport --start today
aureport ...

Apache setup on Mac OS X Lion

I always feel the need to write some silly commentary to explain why I'm documenting procedure in a public way to help anyone else who shares similar circumstances. Enough for today.

Enable System Preferences->Sharing->Web Sharing. After this web pages in DocumentRoot specified in httpd.conf, will be served by Apache.  And even though Apache is started at this point, you don't really have control over the service.  Running:

sudo apachectl stop

won't produce any errors, but it won't restart httpd either. System Preferences has some strange control over the apache service at this point ...


The _imaging C module is not installed

While trying to use PIL on a Arch linux box (python 2.6.7) I kept getting the dreaded "The _imaging C module is not installed" error message.  I tried installing libjpeg using pacman and from source. I tried installing freetype2 using pacman and from source. After each of these attempts, I reinstalled PIL with the --update option and went through the...

python
>> import Image
>> import _imaging

to test. None of this helped.  My libjpeg.so file was in /usr/local/lib, so I added that to sys.path; still didn't work.  I finally resolved the problem with ldconfig ...


Creating and Updating MySQL Accounts / hosts.allow

Here's a quick script for creating or updating MySQL accounts via the command line so that you're able to login from any host. It's really easy to replace the '%' with your actual hostname or ip to make this more secure, so if at all possible, you should.

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

To update:

use mysql;
update user set password=PASSWORD("password") where User='username';

Also remember, if you're on a linux box and you ...


Finding First or Last Item in a Python List

I had a small piece of code I was using to parse a search string in Python for Sphinx.  When you pass "verizon | mobile | at&t" to Sphinx (in boolean mode) it happily returns results.  However, if you pass "verizon | mobile | at&t | " it throws an "unexpected $end near ''" error.  So I needed to not add the extra pipe/or for the last element in my search string.  Using split() to turn the string into a list and then using the [-1] index, you're able to determine if you're on the last element and not add the extraneous ...


Sphinx Mode in Python / SphinxSearch Class

In order to get Sphinx to work in boolean mode in Python/Django, you need to pass the "mode" argument as it's plain text value to the SphinxSearch class.

    search = SphinxSearch(
                index = 'my_index another_index',
                mode = 'SPH_MATCH_BOOLEAN',
                maxmatches = '1000000'
    )

If you specify mode as it's numeric equivalent (mode = 3, for boolean) Sphinx will throw a "getattr(): attribute name must be string" error (hint, hint).  If you specify "mode = '3'", Sphinx defaults to "SPH_MATCH_ALL," without throwing an error; not too helpful.


Page 1 of 8 1 2 3 4 5 6 7 8 »