…and a digital brain freeze.

Setting up Ubuntu 10.04 with Apache, memcached, ufw, MySQL, and Django 1.2 on Linode

Filed under: Work — Tags: , , , , , , — Bryan on May 24th, 2010 @ 3:40 am

Call me a sucker, but I love a good server setup as much as the next guy, I just have a little trouble setting it up sometimes. So I thought I’d walk through my process for setting up all this Django goodness on what is basically a LAMP setup (where “P” stands for Python!) with a few extras like memcached and ufw. We’ll get to a level of general security, but not prefect security.

Also, we’ll keep this well within the 360 megabytes allotted for the cheapest Linode. Before we get underway, just create a new Linode with Ubuntu 10.04 (32-bit), set your password. Alright, let’s get going!

Initial Setup
First thing to do is log in via the standard SSH on your Linode’s IP, port 22, and with root as your username. We’ll change the login user away from root, but for now, this will do (plus we can skip all that sudo stuff). First, let’s update and upgrade the system.

apt-get update && apt-get upgrade

Awesome, you should be 100% up-to-date. Now its time to get to the fun part, let’s install some of the software we’ll be using! Below are the commands to install Apache, MySQL, mod_wsgi and the python MySQL bindings, as well as memcached and ufw. If you have any prompts for passwords, you know what to do! Just remember what you set them as.

apt-get install build-essentials
apt-get install apache2 apache2.2-common apache2-mpm-worker apache2-threaded-dev libapache2-mod-wsgi python-dev
apt-get install mysql-server python-mysqldb
apt-get install memcached libmemcache-dev
apt-get install ufw

Really quickly, let’s get python-memcached installed (alternatively, if you need some raw speed, look up cmemcached or python-libmemcached). This will take a few steps…

# create and enter a temp dir in /home
cd /home && mkdir downloads && cd downloads
# get django 1.2 tar and untar it
wget -O pymem.tar.gz ftp://ftp.tummy.com/pub/python-memcached/python-memcached-1.45.tar.gz && tar -zxvf pymem.tar.gz
# enter the directory and install
cd python-memcached-1.45 && python setup.py install

Now its time for Django! Django 1.1.1 is a lot easier to install than Django 1.2:

# install django 1.1.1
apt-get install python-django

But let’s say we need Django 1.2: its gonna take a few more commands to make this happen. Watch out for that last command, anytime you use rm -r you can run into real trouble if you mistype (but we’re not production yet so no worries, right?).

# enter the downloads directory in /home
cd /home/downloads
# get django 1.2 tar and untar it
wget -O django12.tar.gz http://www.djangoproject.com/download/1.2/tarball/ && tar -zxvf django12.tar.gz
# enter the directory and install django 1.2
cd Django-1.2 && python setup.py install
# strictly optional delete of downloads directory, be careful with rm -r
cd /home && rm -r downloads

Actual Configuration
Let’s work backwards, we’ll start with the easy stuff and work our way to the more complicated things. Let’s get ufw and the SSH port out of the way first. Go ahead and pick a number between 1024-8000ish for the port we will eventually; I chose 5555 but you can should use something else.

# turn on ufw
ufw enable
# log all activity (you'll be glad you have this later)
ufw logging on
# allow port 80 for tcp (web stuff)
ufw allow 80/tcp
# allow our ssh port
ufw allow 5555
# deny everything else
ufw default deny
# open the ssh config file and edit the port number from 22 to 5555, ctrl-x to exit
nano /etc/ssh/sshd_config
# restart ssh (don't forget to ssh with port 5555, not 22 from now on)
/etc/init.d/ssh reload

Now that you have ufw and SSH locked down, its time to move onto setting up memcached (which is super easy). We’ll just run it as root and be done with it (you will need to repeat this command on each boot):

# replace 24 with however many megabytes of cache is appropriate
memcached -u root -d -m 24 -l 127.0.0.1 -p 11211

Alright, with that out of the way, let’s get MySQL nice and tight. The standard install of MySQL can suck up a lot of memory, so we’ll suggest a few ways to lighten the load:

# open mysql conf and set these settings:
#    key_buffer = 16k
#    max_allowed_packet = 1M
#    thread_stack = 64K
nano /etc/mysql/my.cnf
# restart mysql
/etc/init.d/mysql restart

Now let’s get a new user setup and leave behind this root nonsense for safety’s sake. Your username is going to be bobby for this example. Replace bobby everywhere if you want something different.

# create bobby, you'll be asked to set the password and such
adduser bobby
# edit the ssh file and add the line: AllowUsers bobby
# ctrl-x to exit and save
nano /etc/ssh/sshd_config
# restart ssh
/etc/init.d/ssh reload
# log out and login as bobby from now on!

It’s time for the nitty gritty stuff: setting up Apache and mod_wsgi with Django for the domain you own called examplesite.com (creative, I know). We need to make a public_html folder in bobby’s home folder and place a folder called examplesite.com (as well as a few more). We’ll do that first.

cd /home/bobby/
mkdir public_html
mkdir public_html/examplesite.com
mkdir public_html/examplesite.com/logs
mkdir public_html/examplesite.com/private

Right now you should place your Django project into the public_html/examplesite.com folder. For example, if the project is housed in demoproject (eg: demoproject/manage.py, demoproject/urls.py, etc.) you’ll want it placed ALA public_html/examplesite.com/demoproject. Time to get the Apache config files up and running. Here we go!

cd /home/bobby/public_html/examplesite.com/demoproject/
mkdir apache
nano apache/demoproject.wsgi

First, in the demoproject.wsgi file you should paste and save:

import os, sys
 
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
 
sys.path.append('/usr/lib/python2.5/site-packages/django/')
sys.path.append('/home/bobby/public_html/examplesite.com/demoproject')
 
os.environ['DJANGO_SETTINGS_MODULE'] = 'demoproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

We’re so close, let’s get the other Apache files setup. Oh, and don’t worry about that www-data thing just yet, we’ll get to that in a second.

# give the www-data user/group permission on public_html
sudo chown -R www-data:www-data /home/bobby/public_html
sudo nano /etc/apache2/sites-available/examplesite.com

Place the text below in the examplesite.com config file (remember the www-data part from the last command?). You can modify the threads and processes numbers to suit your moods and load.

<VirtualHost *:80>
    #Basic setup
    ServerAdmin your@email.com
    ServerName www.examplesite.com
    ServerAlias examplesite.com
 
    <Directory /home/bobby/public_html/examplesite.com/demoproject/apache/>
        Order deny,allow
        Allow from all
    </Directory>
 
    LogLevel warn
    ErrorLog  /home/bobby/public_html/examplesite.com/logs/apache_error.log
    CustomLog /home/bobby/public_html/examplesite.com/logs/apache_access.log combined
 
    WSGIDaemonProcess examplesite.com user=www-data group=www-data threads=20 processes=2
    WSGIProcessGroup examplesite.com
 
    WSGIScriptAlias / /home/bobby/public_html/examplesite.com/demoproject/apache/demoproject.wsgi
</VirtualHost>

A few more final things:

sudo a2ensite examplesite.com
sudo /etc/init.d/apache2 restart

Time to admire your handiwork.

Congrats! You’re all set up and ready to roll! Nothing can stop you now! Here’s a neat command to measure your memory usage as mine rarely gets over 160mb. This gives lots of room for growth as you can always increase the memcached size, MySQL settings, and Apache/mod_wsgi instances/threads.

# measure your memory usage in kb
ps aux | awk '{print $3"\t"$6"\t"$11;sum+=$6;cpu+=$3} END {print "Total RSS", sum, "\nTotal CPU", cpu}'

Also, under Ubuntu 10.04 (Lucid), Python’s site-packages is now called dist-packages. Just a FYI.

Python Crossword Puzzle Generator

Filed under: Boring Stuff,Work — Tags: , — Bryan on Apr 10th, 2010 @ 4:18 pm

As my next miniature project will be a site for teachers that will make random generation of crossword puzzles and word search puzzles, I thought I’d share the code I developed to create these puzzles on the fly. While I was working on it, I ran across many different scripts to accomplish this, but none of them were in my most favorite of languages: Python. Besides, I’d like the code to fit snugly in my web framework of choice: Django; the popular PHP version just wouldn’t cut it. Anyways, scroll down to see the code, or read on for a little primer about the process behind it.

Puzzles like these:

p u m p e r n i c k e l -    p u m p e r n i c k e l v
a - - - - - - - a - - e -    a w j m p c a y a w r e s
l - s n i c k e r - - a -    l f s n i c k e r b z a x
a - a - - - - - a - - v -    a f a z k e u i a b f v k
d - f - c - - - m - - e -    d x f v c j f d m c n e x
i - f j o r d - e - - n -    i d f j o r d z e j g n z
n - r - d - - - l i p - -    n r r x d j a o l i p d j
- c o r a l - - - - i - -    i c o r a l u s t o i x w
- - n - - i - - - - s - -    m r n u e i i h o t s y w
- - - - - m i s t - t - -    m w e x s m i s t r t u j
p l a g u e - - - - o - -    p l a g u e b n h k o m s
- - - - - - - d a w n - -    f m n v j f p d a w n c q
- - - - - - - - - - - - -    m h j a e d p p r g t p j

Behind the Scenes

This program is actually very simple and creates completely random crosswords on the fly. Naturally, the more words you have, the better it will be at placing the most possible on a board. However, increasing the number of words will increase computation time. Additionally, increasing the board size will severely increase computation time. To counteract the fact that sometimes it will randomly generate a sub-par board, we will generate many different boards in an allotted time and only keep the “best” board (in this case, the board with the most words placed). So, as the board and word list gets bigger, the number of prospective boards created decreases within a fixed time.

The code first randomizes the word list and then sorts by word length. The idea here is that longer words are more difficult to place, so get them placed when the board is the most open. Next, we place the longest word on the 1, 1 coordinate of the grid as the seed. In tests, the placement of the first word at 1, 1 yielded by far the best results on average. Then we go to the next longest word and loop over its letters and each cell in the grid. When we find a match, we back it up and suggest a coordinate placement for that word. Once we’ve checked every letter against every cell, we chose the best (the word best is used very loosely here) coordinate and apply the word to the grid. Now we move on the next word and so forth. Once we’ve made it through once, we can loop over the unplaced words and looks for any lucky chances for a second placement.

This suggested coordinate system allows for a much faster fit than some methods I’ve seen that will randomly place a word to see if it works. Additionally, it requires the word cross other words which is the point of well, a crossword puzzle.

Operation

Be mindful when you create a word list to exclude words like “an” or “or” because these have a tendency to be placed inside other already placed words. This can be confusing. Simply run the code below.

You can feed the Crossword class a list of Word classes, or a list of tuples or lists with the word and clue. Either way works.

When you call the compute_crossword(seconds) method, it does all the work of computing the best crossword in however many seconds you passed. 1 second is probably enough for crossword grids of less that 20×20 and 2 seconds is fine for 25×25 and 3 seconds is good for 30×30. Additionally, if you have a massive word list, you may want to double the time alloyed. Finally, if you can’t run psycho, quadruple these times for similar quality.

The Code:

import random, re, time, string
from copy import copy as duplicate
 
# optional, speeds up by a factor of 4
import psyco
psyco.full()
 
class Crossword(object):
    def __init__(self, cols, rows, empty = '-', maxloops = 2000, available_words=[]):
        self.cols = cols
        self.rows = rows
        self.empty = empty
        self.maxloops = maxloops
        self.available_words = available_words
        self.randomize_word_list()
        self.current_word_list = []
        self.debug = 0
        self.clear_grid()
 
    def clear_grid(self): # initialize grid and fill with empty character
        self.grid = []
        for i in range(self.rows):
            ea_row = []
            for j in range(self.cols):
                ea_row.append(self.empty)
            self.grid.append(ea_row)
 
    def randomize_word_list(self): # also resets words and sorts by length
        temp_list = []
        for word in self.available_words:
            if isinstance(word, Word):
                temp_list.append(Word(word.word, word.clue))
            else:
                temp_list.append(Word(word[0], word[1]))
        random.shuffle(temp_list) # randomize word list
        temp_list.sort(key=lambda i: len(i.word), reverse=True) # sort by length
        self.available_words = temp_list
 
    def compute_crossword(self, time_permitted = 1.00, spins=2):
        time_permitted = float(time_permitted)
 
        count = 0
        copy = Crossword(self.cols, self.rows, self.empty, self.maxloops, self.available_words)
 
        start_full = float(time.time())
        while (float(time.time()) - start_full) < time_permitted or count == 0: # only run for x seconds
            self.debug += 1
            copy.current_word_list = []
            copy.clear_grid()
            copy.randomize_word_list()
            x = 0
            while x < spins: # spins; 2 seems to be plenty
                for word in copy.available_words:
                    if word not in copy.current_word_list:
                        copy.fit_and_add(word)
                x += 1
            #print copy.solution()
            #print len(copy.current_word_list), len(self.current_word_list), self.debug
            # buffer the best crossword by comparing placed words
            if len(copy.current_word_list) > len(self.current_word_list):
                self.current_word_list = copy.current_word_list
                self.grid = copy.grid
            count += 1
        return
 
    def suggest_coord(self, word):
        count = 0
        coordlist = []
        glc = -1
        for given_letter in word.word: # cycle through letters in word
            glc += 1
            rowc = 0
            for row in self.grid: # cycle through rows
                rowc += 1
                colc = 0
                for cell in row: # cycle through  letters in rows
                    colc += 1
                    if given_letter == cell: # check match letter in word to letters in row
                        try: # suggest vertical placement 
                            if rowc - glc > 0: # make sure we're not suggesting a starting point off the grid
                                if ((rowc - glc) + word.length) <= self.rows: # make sure word doesn't go off of grid
                                    coordlist.append([colc, rowc - glc, 1, colc + (rowc - glc), 0])
                        except: pass
                        try: # suggest horizontal placement 
                            if colc - glc > 0: # make sure we're not suggesting a starting point off the grid
                                if ((colc - glc) + word.length) <= self.cols: # make sure word doesn't go off of grid
                                    coordlist.append([colc - glc, rowc, 0, rowc + (colc - glc), 0])
                        except: pass
        # example: coordlist[0] = [col, row, vertical, col + row, score]
        #print word.word
        #print coordlist
        new_coordlist = self.sort_coordlist(coordlist, word)
        #print new_coordlist
        return new_coordlist
 
    def sort_coordlist(self, coordlist, word): # give each coordinate a score, then sort
        new_coordlist = []
        for coord in coordlist:
            col, row, vertical = coord[0], coord[1], coord[2]
            coord[4] = self.check_fit_score(col, row, vertical, word) # checking scores
            if coord[4]: # 0 scores are filtered
                new_coordlist.append(coord)
        random.shuffle(new_coordlist) # randomize coord list; why not?
        new_coordlist.sort(key=lambda i: i[4], reverse=True) # put the best scores first
        return new_coordlist
 
    def fit_and_add(self, word): # doesn't really check fit except for the first word; otherwise just adds if score is good
        fit = False
        count = 0
        coordlist = self.suggest_coord(word)
 
        while not fit and count < self.maxloops:
 
            if len(self.current_word_list) == 0: # this is the first word: the seed
                # top left seed of longest word yields best results (maybe override)
                vertical, col, row = random.randrange(0, 2), 1, 1
                ''' 
                # optional center seed method, slower and less keyword placement
                if vertical:
                    col = int(round((self.cols + 1)/2, 0))
                    row = int(round((self.rows + 1)/2, 0)) - int(round((word.length + 1)/2, 0))
                else:
                    col = int(round((self.cols + 1)/2, 0)) - int(round((word.length + 1)/2, 0))
                    row = int(round((self.rows + 1)/2, 0))
                # completely random seed method
                col = random.randrange(1, self.cols + 1)
                row = random.randrange(1, self.rows + 1)
                '''
 
                if self.check_fit_score(col, row, vertical, word): 
                    fit = True
                    self.set_word(col, row, vertical, word, force=True)
            else: # a subsquent words have scores calculated
                try: 
                    col, row, vertical = coordlist[count][0], coordlist[count][1], coordlist[count][2]
                except IndexError: return # no more cordinates, stop trying to fit
 
                if coordlist[count][4]: # already filtered these out, but double check
                    fit = True 
                    self.set_word(col, row, vertical, word, force=True)
 
            count += 1
        return
 
    def check_fit_score(self, col, row, vertical, word):
        '''
        And return score (0 signifies no fit). 1 means a fit, 2+ means a cross.
 
        The more crosses the better.
        '''
        if col < 1 or row < 1:
            return 0
 
        count, score = 1, 1 # give score a standard value of 1, will override with 0 if collisions detected
        for letter in word.word:            
            try:
                active_cell = self.get_cell(col, row)
            except IndexError:
                return 0
 
            if active_cell == self.empty or active_cell == letter:
                pass
            else:
                return 0
 
            if active_cell == letter:
                score += 1
 
            if vertical:
                # check surroundings
                if active_cell != letter: # don't check surroundings if cross point
                    if not self.check_if_cell_clear(col+1, row): # check right cell
                        return 0
 
                    if not self.check_if_cell_clear(col-1, row): # check left cell
                        return 0
 
                if count == 1: # check top cell only on first letter
                    if not self.check_if_cell_clear(col, row-1):
                        return 0
 
                if count == len(word.word): # check bottom cell only on last letter
                    if not self.check_if_cell_clear(col, row+1): 
                        return 0
            else: # else horizontal
                # check surroundings
                if active_cell != letter: # don't check surroundings if cross point
                    if not self.check_if_cell_clear(col, row-1): # check top cell
                        return 0
 
                    if not self.check_if_cell_clear(col, row+1): # check bottom cell
                        return 0
 
                if count == 1: # check left cell only on first letter
                    if not self.check_if_cell_clear(col-1, row):
                        return 0
 
                if count == len(word.word): # check right cell only on last letter
                    if not self.check_if_cell_clear(col+1, row):
                        return 0
 
 
            if vertical: # progress to next letter and position
                row += 1
            else: # else horizontal
                col += 1
 
            count += 1
 
        return score
 
    def set_word(self, col, row, vertical, word, force=False): # also adds word to word list
        if force:
            word.col = col
            word.row = row
            word.vertical = vertical
            self.current_word_list.append(word)
 
            for letter in word.word:
                self.set_cell(col, row, letter)
                if vertical:
                    row += 1
                else:
                    col += 1
        return
 
    def set_cell(self, col, row, value):
        self.grid[row-1][col-1] = value
 
    def get_cell(self, col, row):
        return self.grid[row-1][col-1]
 
    def check_if_cell_clear(self, col, row):
        try:
            cell = self.get_cell(col, row)
            if cell == self.empty: 
                return True
        except IndexError:
            pass
        return False
 
    def solution(self): # return solution grid
        outStr = ""
        for r in range(self.rows):
            for c in self.grid[r]:
                outStr += '%s ' % c
            outStr += '\n'
        return outStr
 
    def word_find(self): # return solution grid
        outStr = ""
        for r in range(self.rows):
            for c in self.grid[r]:
                if c == self.empty:
                    outStr += '%s ' % string.lowercase[random.randint(0,len(string.lowercase)-1)]
                else:
                    outStr += '%s ' % c
            outStr += '\n'
        return outStr
 
    def order_number_words(self): # orders words and applies numbering system to them
        self.current_word_list.sort(key=lambda i: (i.col + i.row))
        count, icount = 1, 1
        for word in self.current_word_list:
            word.number = count
            if icount < len(self.current_word_list):
                if word.col == self.current_word_list[icount].col and word.row == self.current_word_list[icount].row:
                    pass
                else:
                    count += 1
            icount += 1
 
    def display(self, order=True): # return (and order/number wordlist) the grid minus the words adding the numbers
        outStr = ""
        if order:
            self.order_number_words()
 
        copy = self
 
        for word in self.current_word_list:
            copy.set_cell(word.col, word.row, word.number)
 
        for r in range(copy.rows):
            for c in copy.grid[r]:
                outStr += '%s ' % c
            outStr += '\n'
 
        outStr = re.sub(r'[a-z]', ' ', outStr)
        return outStr
 
    def word_bank(self): 
        outStr = ''
        temp_list = duplicate(self.current_word_list)
        random.shuffle(temp_list) # randomize word list
        for word in temp_list:
            outStr += '%s\n' % word.word
        return outStr
 
    def legend(self): # must order first
        outStr = ''
        for word in self.current_word_list:
            outStr += '%d. (%d,%d) %s: %s\n' % (word.number, word.col, word.row, word.down_across(), word.clue )
        return outStr
 
class Word(object):
    def __init__(self, word=None, clue=None):
        self.word = re.sub(r'\s', '', word.lower())
        self.clue = clue
        self.length = len(self.word)
        # the below are set when placed on board
        self.row = None
        self.col = None
        self.vertical = None
        self.number = None
 
    def down_across(self): # return down or across
        if self.vertical: 
            return 'down'
        else: 
            return 'across'
 
    def __repr__(self):
        return self.word
 
### end class, start execution
 
#start_full = float(time.time())
 
word_list = ['saffron', 'The dried, orange yellow plant used to as dye and as a cooking spice.'], \
    ['pumpernickel', 'Dark, sour bread made from coarse ground rye.'], \
    ['leaven', 'An agent, such as yeast, that cause batter or dough to rise..'], \
    ['coda', 'Musical conclusion of a movement or composition.'], \
    ['paladin', 'A heroic champion or paragon of chivalry.'], \
    ['syncopation', 'Shifting the emphasis of a beat to the normally weak beat.'], \
    ['albatross', 'A large bird of the ocean having a hooked beek and long, narrow wings.'], \
    ['harp', 'Musical instrument with 46 or more open strings played by plucking.'], \
    ['piston', 'A solid cylinder or disk that fits snugly in a larger cylinder and moves under pressure as in an engine.'], \
    ['caramel', 'A smooth chery candy made from suger, butter, cream or milk with flavoring.'], \
    ['coral', 'A rock-like deposit of organism skeletons that make up reefs.'], \
    ['dawn', 'The time of each morning at which daylight begins.'], \
    ['pitch', 'A resin derived from the sap of various pine trees.'], \
    ['fjord', 'A long, narrow, deep inlet of the sea between steep slopes.'], \
    ['lip', 'Either of two fleshy folds surrounding the mouth.'], \
    ['lime', 'The egg-shaped citrus fruit having a green coloring and acidic juice.'], \
    ['mist', 'A mass of fine water droplets in the air near or in contact with the ground.'], \
    ['plague', 'A widespread affliction or calamity.'], \
    ['yarn', 'A strand of twisted threads or a long elaborate narrative.'], \
    ['snicker', 'A snide, slightly stifled laugh.']
 
a = Crossword(13, 13, '-', 5000, word_list)
a.compute_crossword(2)
print a.word_bank()
print a.solution()
print a.word_find()
print a.display()
print a.legend()
print len(a.current_word_list), 'out of', len(word_list)
print a.debug
#end_full = float(time.time())
#print end_full - start_full

Sample output:

You should be able to see the associated methods lining up with the output. A side note: you must run the display() method before the legend() method can be ran.

mist
lime
snicker
paladin
caramel
leaven
pumpernickel
coral
fjord
plague
piston
lip
dawn
saffron
coda

p u m p e r n i c k e l -
a - - - - - - - a - - e -
l - s n i c k e r - - a -
a - a - - - - - a - - v -
d - f - c - - - m - - e -
i - f j o r d - e - - n -
n - r - d - - - l i p - -
- c o r a l - - - - i - -
- - n - - i - - - - s - -
- - - - - m i s t - t - -
p l a g u e - - - - o - -
- - - - - - - d a w n - -
- - - - - - - - - - - - -

p u m p e r n i c k e l v
a w j m p c a y a w r e s
l f s n i c k e r b z a x
a f a z k e u i a b f v k
d x f v c j f d m c n e x
i d f j o r d z e j g n z
n r r x d j a o l i p d j
i c o r a l u s t o i x w
m r n u e i i h o t s y w
m w e x s m i s t r t u j
p l a g u e b n h k o m s
f m n v j f p d a w n c q
m h j a e d p p r g t p j

1               4     8 -
  - - - - - - -   - -   -
  - 2             - -   -
  -   - - - - -   - -   -
  -   - 6 - - -   - -   -
  - 3         -   - -   -
  -   -   - - - 10   12 - -
- 5       9 - - - -   - -
- -   - -   - - - -   - -
- - - - - 11       -   - -
7           - - - -   - -
- - - - - - - 13       - -
- - - - - - - - - - - - -

1. (1,1) across: Dark, sour bread made from coarse ground rye.
1. (1,1) down: A heroic champion or paragon of chivalry.
2. (3,3) across: A snide, slightly stifled laugh.
2. (3,3) down: The dried, orange yellow plant used to as dye and as a cooking spice.
3. (3,6) across: A long, narrow, deep inlet of the sea between steep slopes.
4. (9,1) down: A smooth chery candy made from suger, butter, cream or milk with flavoring.
5. (2,8) across: A rock-like deposit of organism skeletons that make up reefs.
6. (5,5) down: Musical conclusion of a movement or composition.
7. (1,11) across: A widespread affliction or calamity.
8. (12,1) down: An agent, such as yeast, that cause batter or dough to rise..
9. (6,8) down: The egg-shaped citrus fruit having a green coloring and acidic juice.
10. (9,7) across: Either of two fleshy folds surrounding the mouth.
11. (6,10) across: A mass of fine water droplets in the air near or in contact with the ground.
12. (11,7) down: A solid cylinder or disk that fits snugly in a larger cylinder and moves under pressure as in an engine.
13. (8,12) across: The time of each morning at which daylight begins.

15 out of 20
811

My Favorite Way To Sell Files Online

Filed under: Work — Bryan on Feb 15th, 2010 @ 5:48 pm

There are quite a few services out there that provide a mechanism for digital downloads, most of them are cart based or even store based (their store on their site). This puts you at the mercy of their approval process and can shut down your income in a flash if they don’t like what your are selling. Wouldn’t it be awesome if you could just sell some digital file on your site, receive the money directly in your PayPal account and automate the file delivery?

Try BitBuffet.com if you want to sell files online. I promise you’ll be impressed (because I built it myself to be a simple and effective solution for delivering digital files).

I’ve been using BitBuffet.com to sell my WordPress themes at GazelleThemes.com and haven’t hit any snags at all. I just upload the zip file containing my theme and copy the button code onto my website. I even get email notifications when I receive a sale and nice flash charts showing my past sales (including a massive database for searching past sales).

I can set how long the download links are active and how many times they can download. After the time is up, the link no longer works. I can send freebie to friends and resend lost download links. Each download link is unique and expires according to your settings.

Sell Albums or MP3′s On Your MySpace/Band Website

Since my band Glass Cannon is getting ready to release our debut album, I can also use BitBuffet.com to host and sell an album. Again, all I’ll need to do is make a zip of the file, upload it to BitBuffet.com and copy the button to my bands site (or MySpace). All they have to do is click, pay through PayPal and check their email!

Sell Photos From Your Online Portfolio/Flickr

Although I’m not a photographer (I just play one on TV), I can see photographers selling their high resolution files to interested buyers. Since the files are securely hosted, you don’t have to worry about people stealing your work by sharing a download link (each is unique and expires according to your settings).

Sell Any Digital File From Your Site

It doesn’t matter what it is! Software, images, designs, HTML/CSS themes, WordPress Themes, Joomla! Themes, Woopra Themes, MP3′s, Albums, eBooks, vector images… you name it! If it is digital, BitBuffet.com offers the easiest way to deliver the file with after PayPal payments!

Some of the Features:

  • Unlimited Bandwidth
  • Unlimited Sales
  • Keep Your Profits
  • Pay Flat-Fee Month-to-Month or Yearly
  • Payment Directly Into Seller’s Personal PayPal Account

Check out BitBuffet.com today and let me know in the comments what you think!

Notorious B.I.G’s Crack Commandments In Business

Filed under: Interesting — Bryan on Feb 5th, 2010 @ 5:22 pm

In case you need a refresher, check out the tune here. While some are a stretch, a few are really quite relevant.

1. Never let no one know how much dough you hold.

Keep your finances (good or bad) to yourself.

Don’t make the mistake of bragging about how well or mentioning how badly you’re doing unless you have a very good reason for it. What you think of as idle talk amongst friends can get around very quickly and can affect future deals or relationships. When it comes to finances, its just better to keep your mouth shut.

2. Never let ‘em know your next move.

Keep your core strategies/opportunities under wraps.

I know its tempting to talk about your plans or techniques, but just like #1, sometimes it’s just best to shut up. Biggie elaborates on this with “don’t you know Bad Boys move in silence or violence” which is just another way of letting you know that the big dogs don’t over-plan and discuss, and they act.

3. Never trust nobody.

Words are words. Get a contract.

Trust is a funny and terribly fragile thing. While your business partners or clients may not want to ruin you from the outset, who knows what the future will bring? You need to protect yourself. Hire a lawyer, get a contract. Live by this motto: “Everybody signs something.”

4. Never get high, on your own supply.

Discover the customers’ needs; don’t substitute your own.

While you may think you have it under control, your customer should come first. They are the ones controlling your paycheck. Don’t forget that. If you think you have all the answers, be prepared to fail. Badly.

5. Never sell no crack where you rest at.

Don’t mix business with personal life.

It’s easy to bring your personal life into business, and some people have no problems maintaining the difference. But when you become a friend to all, you may have trouble making necessary decisions in the face of emotion. Just know that if you do mix the two, you may need to break the connection to make the right decision.

6. That God damn credit, dead it.

Get cash upfront unless you don’t care about being paid.

This goes back to #3, don’t trust anyone. Get a contract and get the cash upfront. While Biggie was dealing with unreliable crackheads, you’ll still run across unreliable or dishonest businessmen. When in doubt, get it in cash.

7. Keep your family and business completely separated.

Don’t work with family for family’s sake.

This is an elaboration on #5, but don’t hire friends or family just because they are who they are. Do they have a strong skill-set? Can they contribute to your bottom line? If you can’t be honest here, you won’t make it far.

8. Never keep no weight on you.

Learn to delegate effectively.

Biggie clarifies this with the line: “them cats that squeeze your guns can hold jumps too.” In Biggie’s case, he doesn’t want to get nailed with possession. In your case, hire someone to do your dirty work for you. Learn to delegate and get on with more important things.

9. If you ain’t gettin bags stay the fuck from police.

Watch who you are perceived as working with.

There are probably a lot of people who in hindsight would have taken a different route when dealing with unsavory people. Biggie had the right idea, your colleagues will form their own assumption, some of them negative.

10. A strong word called consignment; if you ain’t got the clientele say hell no.

Don’t take credit without a means to repay.

This is the flip-side of #6, don’t take obligations you can’t repay. This is one very quick way of run yourself into the ground. If you already have revenue and need to grow, then by all means.

What do you think? Did I interpret one wrong?

Automated Rank (and Link) Tracking Done Easy

Filed under: Work — Bryan on Dec 17th, 2009 @ 3:55 am
A sample email. Simple easy.

A sample email. Simple easy.

Finally, after months of tweaking and building, I’ve launched Rankiac.com, a super charged automatic Google rank checker. It’s a dandy little SEO tool that doesn’t do a whole heck of a lot, but what it does, it does well. At the moment, it (1) tracks rankings in Google, (2) watches your important links and (3) keeps track of backlinks (and lets you know when it finds a new one!). Oh, and it emails you an update every morning! That last feature was key for me.

So, what’s it do?

Well, it does just what I mentioned before! Tracks keyword rankings in Google (hundreds of them!), hyperlinks between sites (we watch out for pesky no-follows), and backlinks (from Yahoo’s Site Explorer). But my favorite feature is by far and away daily emails.

Daily Emails!

How I love rolling out of bed in the morning (or lately is been afternoon…) and checking all my ranks from my iPhone’s email app. Anywhere you want, its easy access to a simple method that keeps you in the loop. I tend to forget to look at my other keywords, but Rankiac never forgets. Its handy.

Charting

I also love charts. Rankiac has ‘em. See how each of your keywords is doing over time and plan accordingly. Link building making your domains slowly increase in rankings? Double check with one click. Oh, also, you can download all the data in CSV format as well, in case you wanna play with the data yourself.

If you’re interested, here’s a coupon: zr6voq1y. Just sign up and enter it in your profile!

It’s good for the first 25 users and gives you 91 days free (in addition to the 14 day free trial!). After that, I think it runs about 11 cents a day, or less that 3 and a half bucks a month when you buy a year!

So what are you waiting for, go sign up at Rankiac!

PS: I’ve also built two little baby sites for those who want a simple Google rank checker or fast reciprocal link checker on the fly!

6 IT Decisions for Non-IT Management

Filed under: Boring Stuff — Bryan on Nov 4th, 2009 @ 6:18 pm
  1. The first consideration is: is the level of spending tied to the overall strategy? Given that there are uncertain returns for IT investments, the spending should be considered like any other business investment and prudence should be exercised just the same. While industry bookmarks can be an exceptional indicator, they should not be the targeted spending.
  2. The second consideration is: is the money focused on essential, benefit producing programs? While it may be tempting to streamline all business processes, it is foolish to equally distribute investments among business processes that will benefit unevenly. However, a careful balance must be struck to avoid any bottlenecks.
  3. The third consideration is: at what scope will the business benefit from IT centralization? Another tempting move may be to provide company-wide IT integration, or centralization, regardless of the cost. This may appear to be an excellent way to provide cost savings (by buying in bulk), but the added benefit of centralization may be entirely mitigated by the added costs.
  4. The fourth consideration is: does the business need a premier, top-of-the-line system to operate efficiently? If left to IT management, the added cost/benefit ratio may be clearly defined in raw technology terms, but the benefit as perceived by IT management may not translate to overall benefits to the business.
  5. The fifth consideration is: at what point does the marginal cost of more hassle cross the marginal benefit of more security?  In other words, by increasing IT security, are you inadvertently creating insurmountable obstacles for non-IT employees? Research suggests that the weakest link of most security chains is the human element, and the human element is best handled through proper training, not extravagant (and costly) firewalls and encryption.
  6. The sixth and final consideration is: place blame on the management of IT implementation, not the IT systems. Most IT systems are built to exact specifications, and many are industry wide solutions adopted elsewhere. When the expected benefits don’t materialize, find the problem in the decision chain that approved inappropriate systems, not in the IT system itself.

Six IT Decisions Your IT People Shouldn’t Make – March 3, 2009 – Jeanne W. Ross and Peter Weill

Django Encryption – An Updated How-To

Filed under: Boring Stuff — Tags: , , , — Bryan on Oct 16th, 2009 @ 12:56 am

I love Django, and I love Django Snippets, but I’ve noticed some snippets are out of date, most notably for me, Django snippet 1095 or Django Encryption. Unfortunately, some folks are hitting a few snags on TypeError: “Non-hexadecimal digit found”.

Luckily, it seems that Django-Fields have solved this problem for us! Here is my (their) technique!

Make a file named encryption.py to go into the same folder as your settings.py containing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import binascii
import random
import string
 
from django import forms
from django.db import models
from django.conf import settings
 
class BaseEncryptedField(models.Field):
    '''This code is based on the djangosnippet #1095
You can find the original at http://www.djangosnippets.org/snippets/1095/'''
 
    def __init__(self, *args, **kwargs):
        cipher = kwargs.pop('cipher', 'AES')
        imp = __import__('Crypto.Cipher', globals(), locals(), [cipher], -1)
        self.cipher = getattr(imp, cipher).new(settings.SECRET_KEY[:32])
        self.prefix = '$%s$' % cipher
 
        max_length = kwargs.get('max_length', 40)
        mod = max_length % self.cipher.block_size
        if mod > 0:
            max_length += self.cipher.block_size - mod
        kwargs['max_length'] = max_length * 2 + len(self.prefix)
 
        models.Field.__init__(self, *args, **kwargs)
 
    def _is_encrypted(self, value):
        return isinstance(value, basestring) and value.startswith(self.prefix)
 
    def _get_padding(self, value):
        mod = len(value) % self.cipher.block_size
        if mod > 0:
            return self.cipher.block_size - mod
        return 0
 
 
    def to_python(self, value):
        if self._is_encrypted(value):
            return self.cipher.decrypt(binascii.a2b_hex(value[len(self.prefix):])).split('\0')[0]
        return value
 
    def get_db_prep_value(self, value):
        if value is not None and not self._is_encrypted(value):
            padding = self._get_padding(value)
            if padding > 0:
                value += "\0" + ''.join([random.choice(string.printable) for index in range(padding-1)])
            value = self.prefix + binascii.b2a_hex(self.cipher.encrypt(value))
        return value
 
class EncryptedTextField(BaseEncryptedField):
    __metaclass__ = models.SubfieldBase
 
    def get_internal_type(self):
        return 'TextField'
 
    def formfield(self, **kwargs):
        defaults = {'widget': forms.Textarea}
        defaults.update(kwargs)
        return super(EncryptedTextField, self).formfield(**defaults)
 
class EncryptedCharField(BaseEncryptedField):
    __metaclass__ = models.SubfieldBase
 
    def get_internal_type(self):
        return "CharField"
 
    def formfield(self, **kwargs):
        defaults = {'max_length': self.max_length}
        defaults.update(kwargs)
        return super(EncryptedCharField, self).formfield(**defaults))

And then in your models.py:

1
2
3
4
5
6
7
8
9
10
from encryption import EncryptedCharField
...
class Example(models.Model):
    secret = EncryptedCharField(max_length=255)
 
    class Meta:
        ordering = ('secret',)
 
    def __unicode__(self):
        return self.secret

This should be pretty explanatory! Have fun!

PS: You need PyCrypto! Google much?

Antares AutoTune Review

Filed under: Interesting — Tags: , , — Bryan on Aug 13th, 2009 @ 12:06 am

antares autotune review saxaphone trumpetI never thought I’d cross into the dark side. Using AutoTune? On jazz?! What?!?

Oh, I know how wrong it is. The “Trane” would roll over in his grave. Wes would be shocked. Miles would not approve. But, I don’t think those guys would listen to our records anyways (even if they were still alive). Besides, I think I speak for everyone when I say I am tired of doing 800 takes. We aren’t professionals who spend their lives playing live and in the studio. This is for fun. So here is my two bits about Antares AutoTune on woodwind and brass instruments.

Holy shit, it worked!

That was my first reaction. I snagged a copy (v5), installed it, and was thinking I just wasted time and money. Like we need Cher or T-Payne style AutoTuning on our sax duets. Right…  All I did was throw it on the tracks, leave it on the “Auto” setting. 10 seconds later… Well, holy shit, it worked!

Alright, so you know it worked, but how did it sound? Here’s a little excerpt on a song by Adam Loftin, named “Out Of The West Wood”. It’s a very angular jazz tune, slow and ballad like. You can hear our two sax players (who are quite talented), stray off on this strangely angular melody.

Now, that may not sound that different, but listen closely to the last note. The warble is gone. The harmonic dissonance is still there (this is jazz, remember). This is actually a pretty good example, hopefully you aren’t trying to fix horribly out of tune performances, just slightly out of tune.

Anyways, it was literally as easy as installing the software, attaching it to the track, and selecting the instrument setting. We could probably fix the slightly out of tune note pickups, but seriously, its so much better, we don’t even care.

Have you used it?

Just curious about your experiences with AutoTune and your stories. What genres did you use it on? What’s the strangest track you’ve run through AutoTune?

PS: If you care, the band’s name is Glass Cannon. The album is due out whenever it is done, which, at this rate, might be a while…

Bing, Yahoo!, Google and the Ad Serving Internets

Filed under: Work — Tags: , , , — Bryan on Jul 1st, 2009 @ 4:27 pm

I run a few websites (lets just say over a dozen) so I generally spend a lot of my time optimizing and tweaking these sites. My first site, a free guitar lesson resource, survives solely off of Adsense. I like Adsense, its easy to use, is extremely popular, and there are is no shortage of willing advertisers.

I receive decent traffic from all three of the big search engines, and while the night may still be quite young, I can already see which site I am leaning towards as my favorite search engine…

A comparison of revenue earning power.

Thanks to Google Analytics’s handy Adsense integration, I can see exactly which keywords will give me better eCPM, or “the estimated revenue from AdSense per thousand ad page views”. Out of my largest referrers, the highest eCPM earners are…

  1. Bing with 425% of average eCPM!
  2. Yahoo! with 188% of average eCPM.
  3. Direct (no referral) at 98% of average eCPM.
  4. Google with 71% of average eCPM.

Now these numbers should be taken with a grain of salt, I haven’t controlled for other variables, like landing pages, keywords or traffic numbers. However, a cursory overview tells me that any set of numbers with a extreme deviations from the average warrant further investigation. Discuss this, I will.

What’s going on?

Well, Bing and Yahoo! both rank me much, much higher on my target terms than Google (think top 5 vs. top 50). So right off the bat, I am thinking of this in a couple ways:

  1. Bing and Yahoo! are both sending me much more relevant traffic. Therefore the users are more engaged with the site, and are more willing to explore relevant advertising offers.
  2. Bing and Yahoo! are both sending me much less relevant traffic. Therefore the users are less engaged with the site, and want to click away from the site through advertisements.
  3. Google users are more web savvy, and tend to ignore the branding of the the Google Adsense ads (they do have a distinct look).

Well which is it? Well, let me bring in some more information: bounce rates. Bounce rates are great indicators of whether people stick around on your site or not, the lower the bounce rate, the better. Low bounce rates mean users spend more time on your site, time that is likely to translate to favorable actions (bookmarking, ad clicking, etc.), so there might be a little harmonizing amongst the data… Let us explore:

  1. Yahoo! with a BR of 38.06%.
  2. Bing with a BR of 39.52%.
  3. Direct (no referral) with a BR of 45.37%.
  4. Google with a BR of 50.98%.

Anyway you slice it, this doesn’t look good for Google. Google has the highest bounce rate of the bunch, even higher than the site average. Yahoo! and Bing are both neck and neck. And they make me more money per click-through, Win-win! However, in all fairness, they are sending traffic from different search terms. Yahoo! and Bing just seem to be better at choosing relevant search terms at the moment.

The last theory I put forth was one that suggests that Google users are a little less advertisement prone than their counterparts at Bing and Yahoo!. Perhaps this is true since most folks are learning of Bing through Microsoft’s big ad campaign. Sheeple in, sheeple out. Coincidence!? Probably. Who knows.

Why is it so?

Well, in reality, it may not be so. The data isn’t very normalized. In fact, as of right now, both Bing and Yahoo! combined only send about 1/5 of the traffic Google sends. But this number is growing everyday, so we’ll have to come back in a couple months to see if this changes.

But as for now, I am thinking Bing and Yahoo! are both ranking me better for keywords I know my site is good for. Google just seems to be pickier (and a little less efficient in this case). My suggestion would be to get you some Bing traffic and see for yourself.

Whoever is reading this and has a soft spot for statistics of any sort, perhaps you can put forth some clarifications or suggestions. I’d love it.

Edit: Now with the Yahoo!/Bing deal, let’s hope these numbers hold up and more traffic comes pouring through. :-)

Yukon Ho!: A Retrospective

Filed under: Life of Bryan — Tags: , , — Bryan on Jun 9th, 2009 @ 12:52 am

yukon ho!The times I’ve been caught talking to myself I was saying things like “Bryan, you won’t be doing any of that boring personal life blogging will you?“, to which I would answer: “No, of course not“. Please note, I’ve denounced drinking on more than one occasion/morning, and we all know that wagon skipped town long before I got a chance to hop on (“You’ll get hop-on’s“). So, let me just get the relapse out of the way: I vacationed in Alaska/the Yukon and it was a hoot. Let me tell you about it.

Let’s talk a little about our group (we were in a tour group, just like the original Alaskan explorers!). First off, we had the venerable Scott, the twenty something law student leading the charge. With the single exception of some lovely young ladies from Chattanooga, mostly everyone in the tour was old and boring. No offense to old and/or boring people, of course. Who am I kidding, you don’t use the internet anyways.

Though we did stop at every expansive view, where we would all topple out of the bus, the majority of our time was spent riding a bus. I won’t elaborate.

Because lists are easily digested, let’s just list the things we did by the order of coolness:

  1. Plane ride over glaciers. This was just good ol’ fashioned awesome. You really have no idea what you are dealing with when it comes to the great white north until you see it from the sky. Really. Just look.
  2. Kyle’s first three (legal?) beers. They seem to grow up so fast! Especially when you cross a border where the drinking age is lower…
  3. White water rafting in the Nenana river. This was very cool too. I’m man enough to admit I was the only white water virgin on the raft that day. Good thing the Tennessee family went with my little brother and I, otherwise we’d had been the only two in the raft.
  4. Old junk at the gold dredge. I’m a sucker for rustic like junk artifacts (read: not trash). I just love taking photos of old equipment because it’s so freaking cool. It is also easy to do and makes me feel like a big-boy photographer.
  5. Panning for gold. Though I didn’t find much, my little brother found a little. So did my parents. About $30′s worth combined.

You can check out our entire Helmig Family Flickr photostream for the photos, we’ll be adding them regularly. Not sure if any of the tour members will ever run across this, but if you do, drop a comment and say hi!

Next Page »
All articles are licensed under a Attribution-Noncommercial-Share Alike 3.0 Unported License. All files/themes are released under the GPL License where applicable. © 2010 Bryan Helmig Hosted on Webfaction.