December 22, 2014

Using Virtualenv with Fish Shell

I am a huge fan of the fish shell, and I wanted to use Python virtual environments conveniently while in the shell.

Of course, if I was using cranky-old-bash-shell, I’d just use the excellent “virtualenvwrapper“, but I’m not.

It turned out to be not that difficult to make a workalike to virtualenvwrapper using Fish, including help and tab completion of environments.
[Read more...]

Technorati Tags: , ,

How to send HTML Mail to a Mailing List

Many stores use GNU Mailman to maintain a mailing list for store sales and newsletters. Satchmo has this as a built-in option, for example. It isn’t too bad an option, after all. You can easily set options so that it is “push only” and therefore only the mailing list owner can send mail.

(Yes, it really isn’t a great idea. I heartily recommend a service such as Aweber to manage your list, which will lead to much better legal compliance and more professional results. But bear with me, not all store owners want to pay for additional services.)

However, what if you want to send nicely formatted HMTL newsletters? How do you get your mail client to send those so that they’ll look nice for your customers? Answer, you don’t. You send it manually from the commandline.

Here’s how…

[Read more...]

Technorati Tags: , , , ,

Setting up SSL for Lighttpd/Django

My latest client Farinaz Taghavi is finally in beta on her site, and one of the last steps to push her live was to set up SSL for her.

Luckily, I’ve done this a number of times, so it was quick and easy to do, but still I had to refer to various reference sites and remember exactly what I do differently than some.

First off, I use the Lighttpd configuration I describe in "Django and Lighttpd Configuration for smooth SSL", I don’t have any need to vary it much from what I did for my other site, but since I am using Satchmo for my ecommerce engine on this one, I can’t have a separate domain name for my secure and non-secure domains. In other words, I want both http://farinaz.com and https://farinaz.com to work.

The changes are simple, but since it is slightly different, you can download it and modify for your own use: lighttpd_ssl.zip

In that file are the two very important lines:

ssl.pemfile = "/etc/lighttpd/ssl/farinaz.com/farinaz.com.pem"
ssl.ca-file = "/etc/lighttpd/ssl/farinaz.com/farinaz.com.crt"

The rest of this article will discuss how to acquire those files.

Creating the Certificate

1. Create a working directory. I always put them in “/etc/lighttpd/ssl/servername

mkdir -p /etc/lighttpd/ssl/yourserver.com
cd /etc/lighttpd/ssl/yourserver.com

2. Create your server key, and then (optionally) remove the password from it. The only critical question is “common name”, which must be the domain name you want to secure. In our example, “yourserver.com”

openssl genrsa -des3 -out yourserver.com.key 1024
openssl rsa -in yourserver.com.key -out yourserver.com.nopass.key

3. Create the CSR (Certificate Signing Request) that you’ll be using at the certifying authority to get your cert.

openssl req -new -key yourserver.com.nopass.key -out yourserver.com.csr
cat yourserver.com.csr

4. Copy the text to your clipboard. It will look something like this:


-----BEGIN CERTIFICATE REQUEST-----
MIIBrzCCARgCAQAwbzELMAkGA1UEBhMCVVMxDzANBgNVBAgTBk9yZWdvbjERMA8G
A1UEBxMIUG9ydGxhbmQxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0
[... and so on ...]
2JwW20fix2pFjK22E+jUvNh25cTRWpUKeTt5OEoE3hgkPZCjZPuzvXt7dw5N1CBv
1a9vX8LRMPRd+TtlOEBHhNZ2DLSkzAvTg4RI+1uPLN3KBpRp9FCTaPEmeuLfMBwl
Y7Se
-----END CERTIFICATE REQUEST-----

5. Go to a good cheap certificate source. I like to use Name Cheap since they are in fact cheap, their control panel is very usable, and they are not underhanded in business dealings unlike the infamous GoDaddy. (I currently have 49 domains with them!) Namecheap has SSL certs for as low as $12.88 per year.

A short aside. There is no reason I can see for 99% of all site operators to get anything more than the cheapest possible cert from RapidSSL. Ignore all the sales hype. The simple fact is that no one except extreme geeks even know or care about levels of certification, the vetting process, or any of that. It is simply not a factor in purchasing decisions from anything I’ve ever seen, and I used to work for a company that sold expensive certs!

6. After you purchase your cert, the site will ask you what type of system you have. I’ve never seen Lighttpd listed as an option, so you should select “Apache + OpenSSL”

7. Next it will ask for your CSR. Paste in the text you copied in step 4.

8. Make sure you can receive email at the address where the certificate authority will send the confirmation! Wait for it, and click the confirmation link.

9. Wait a few minutes to get your cert.

10. Copy the text of the cert to a file on the server. I just use emacs and paste in the contents of the cert I copied from the email. Save it as “yourserver.crt”.

11. Finally, create your pem file.

cat yourserver.com.nopass.key yourserver.com.crt > yourserver.com.pemchmod 0600 yourserver.com.pem

12. Verify that lighttpd has SSL.

/usr/local/sbin/lighttpd -v

It should say something like “lighttpd-1.4.11 (ssl).” If it doesn’t then you need to recompile it. Use the instructions on cyberciti.biz for that if you need it.

13. restart the server.

/etc/init.d/lighttpd restart

Done. This takes me about 15 minutes, most of that waiting on emails.

[tags]ssl,lighttpd,satchmo,django[/tags]

Setting up Satchmo on a Debian Server

At the request of people on the satchmo-users mailing list, here’s my step-by-step guide to installing Satchmo on a Debian server.

Debian is a wonderful base for Satchmo, much easier to set up and maintain than RedHat in my opinion. The magic is in the “apt” packaging system, it simply eliminates most of the ugly tracking-down of the right versions of software and their dependencies.

This is a step-by-step, not a full discussion. To read more about “why”, please see the excellent article Creating my Dream Server for Django, which I heavily borrowed from.

[Read more...]

Django and Lighttpd init script and config for SSL.

I’ve gotten a lot of interest from my article about my SSL configuration for Django/Lighttpd. To make things even simpler for you, I’m posting a zip file with my raw config files and init script.

The init script is intended for use on a Redhat-style system, since that is what most VPS solutions are going to give you. It actually works, and I’ve never seen any other examples of working Django init scripts. Drop it in, edit the config files, run “chkconfig –add yourapp” and you should have a django setup which autostarts, and a Lighty config which is ready to serve it.

Enjoy, and please let me know if you see a way to improve the scripts.

tribe.zip version 1

Converting WMA to MP3 on OSX or Linux

headphones Converting WMA to MP3 on OSX or LinuxFinding this technique took more time than I thought it should, so I thought I’d share a quick and simple music transcoding tip.

Converting WMA to MP3

1) Get mplayer and lame installed. I use the accelerated and precompiled mplayer and lame for OSX.

2) Create a simple shell script:

#! /bin/sh
set -e
F=$1
mplayer -ao pcm:file="${F%.wma}.wav" "$F"
lame --preset hifi "${F%.wma}.wav" "${F%.wma}.mp3"
rm -f "${F%.wma}.wav"

Save as “convert_wav.sh”, make executable, and run it on your wma files. An easy way to hit all of them in a directory tree is:


find . -name "*wma" -exec convert_wav.sh {} \;

Thanks to the original version, found and modified from that given on Macosxhints.com.
[tags]mp3, osx[/tags]

Pgrep and Pkill for OSX

happy Pgrep and Pkill for OSXUsually I am satisfied by the commandline tools available in OSX. However, one itch that has been unfulfilled for quite a while since my permanent conversion to the Mac is the lack of “pgrep” and “pkill”, two of my favorite time savers from Linux.

Solution

sourceforge.net/projects/proctools/

Works like a dream.

[tags]osx,utilities[/tags]

WordPress 2 multi-blogging made easy

I upgraded the site to WordPress 2 this morning. This wouldn’t be a bit deal, since the dev team has made it so easy to upgrade. What makes it interesting is that I read a tip on the WordPress forums and came up with a simple method to enable multiple domains using one blog installation on Linux/BSD systems.

1) Get WordPress 2.0 and unpack it to a master directory you’ll be symlinking later.

2) Copy wp-config.php to wp-config-orig.php.
3) edit wp-config.php, replacing the whole thing with:
<?php include($_SERVER['DOCUMENT_ROOT'] . '/config.php'); ?>
4) make the directory for your domain, for example:
mkdir coderseye.com
5) cd into the directory and symlink the contents of your master directory.
cd coderseye.com
ln -s /home/example/wordpress-master/* .

6) copy the original wordpress config file, naming it “config.php” and edit like you usually would for wp-config.
cp /home/example/wordpress-master/wp-config-orig.php config.php
7) Done! You’ve successfully linked another directory as a separate blog with the same base files.

Making it automatic

I’ve made a script which automates all of this, at least on Linux boxes. You just call it like so:
setup_multiblog.sh master slave
If “slave” directory exists, it will be backed up, and upgraded to work with the master as a slave-multi-blog.
If it doesn’t exist, it will be upgraded.
If the master doesn’t have the modifications I describe in step #3, the script will back up wp-config and make the modifications.

setup_multiblog.zip

Enjoy, let me know if it needs tweaks, it has a lot of self-checks built in, so hopefully it won’t trash anything. I’d backup first, just to be double-sure.

Technorati Tags: , , ,