Background image

Trey Piepmeier

Posts

Posts

Posts

  • February 28, 01:42 PM

    Installing MySQL on Snow Leopard using Homebrew

    If you already have a /usr/local folder and it’s not owned by your user:

    sudo chown -R `whoami` /usr/local
    

    Install Homebrew:

    cd /usr/local
    git init
    git remote add origin git://github.com/mxcl/homebrew.git
    git pull origin master
    

    This is kind of odd–you install Homebrew right into the base of your /usr/local folder. It nicely ignores other folders that already exists there. Just do it.

    Install MySQL:

    brew install mysql
    

    Yeah, it’s really that easy. This will take a while.

    Now warm it up:

    mysql_install_db
    

    And make sure it automatically starts again on login:

    launchctl load -w /usr/local/Cellar/mysql/5.1.43/com.mysql.mysqld.plist
    
  • February 25, 02:56 PM

    The mate Shell Command for TextMate

    I keep having to look this up.

    To add the mate shell command, select the Help menu from within TextMate and select "Terminal Usage..."

    Source

  • February 22, 05:02 PM

    Using Dropbox to Share Git Repositories

    First, create a Git subfolder inside your Dropbox folder. Then you can share the individual projects inside that folder with whomever you want (or just use it for instant offsite backups).

    From inside a Git project:

    git clone --bare . ~/Dropbox/Git/gitproject.git
    git remote add dropbox ~/Dropbox/Git/gitproject.git
    

    When you’re ready to push:

    git push dropbox master
    

    Your Collaborator’s View

    Your collaborator would work on the project like so (inside the folder where they want their project to live):

    git clone ~/Dropbox/Git/gitproject.git
    

    If they want to have a dropbox remote instead of the default origin:

    git remote add dropbox ~/Dropbox/Git/gitproject.git
    

    They would then push the same way:

    git push dropbox master
    

    To get the other person’s changes, it’s the standard deal:

    git pull dropbox master
    

    Source

  • January 10, 04:46 AM

    Create Your Own Local Copy of the Django Documentation

    sudo easy_install Sphinx
    

    Inside your local SVN checkout of Django:

    cd docs
    make html
    

    Now you’ll have a beautiful local copy of the documentation to browse for those rare moments when you’re away from the internet (perhaps you’re in a fort?). Just point your browser to:

    file:///path/to/your/django/docs/_build/html/index.html
    

    Source

  • January 04, 10:03 PM

    Getting Django + MySQL running again on Snow Leopard

    Previously…

    • Install the latest Xcode Tools from your Snow Leopard installation DVD
    • Re symlink things to /Library/Python/2.6/site-packages (Leopard used 2.5)
      • Django
      • Any other thing you had symlink’d in 2.5

    MySQL + Python

    After all that Sequel Pro is still showing the version of MySQL as 5.1.33, but it seems to be working…

    PIL

    This was by far the biggest headache. I finally found a solution:

    Install like this, but before running sudo python setup.py install, do this:

    LDFLAGS="-arch ppc -arch i386 -arch x86_64" CFLAGS="-arch ppc -arch i386 -arch x86_64" python setup.py build
    

    If you already had PIL installed and had the source files you compiled from before, be sure to delete them and start fresh from a new Imaging-1.1.6.tar.gz.

  • December 10, 06:08 PM

    Using the jQuery Autocomplete Plugin with Django

    Here’s another look into the development of ComicBinder.

    There’s already a good tutorial on how to use an autocomplete plugin with Django, but I wanted to use this much snazzier plugin.

    The Process

    Load both jquery.autocomplete.min.js and jquery.autocomplete.css in your page.

    In your form object, create a CharField to hold your autocomplete. Something like:

    title = forms.CharField(label='', widget=forms.TextInput(attrs={'placeholder': 'The name of a comic'}))
    

    Create a hidden field to hold the primary key of the item you’re selecting (so you don’t have to depend on searching against a ‘name’ field or something else equally brittle):

    title_pk = forms.IntegerField(widget=forms.HiddenInput())
    

    Create a view to populate the autocomplete list:

    def title_lookup(request):
        results = []
        if request.method == "GET":
            if request.GET.has_key(u'q'):
                value = request.GET[u'q']
                # Ignore queries shorter than length 3
                if len(value) > 2:
                    model_results = Title.objects.filter(name__icontains=value)
                    results = [ (x.__unicode__(), x.id) for x in model_results ]
        json = simplejson.dumps(results)
        return HttpResponse(json, mimetype='application/json')
    

    This will, of course, need a URLconf:

    url(r'^title_lookup/$', view=title_lookup, name='title_lookup'),
    

    And to finish it off, a bit of JavaScript in your template to call the plugin:

    <script>
        $(function() {
            $('#id_title').autocomplete('{% url title_lookup %}', {
                dataType: 'json',
                width: 500,
                parse: function(data) {
                    return $.map(data, function(row) {
                        return { data:row, value:row[1], result:row[0] };
                    });
                }
                }).result(
                    function(e, data, value) {
                        $("#id_title_pk").val(value);
                    }
                );
            }
        );
    </script>
    

    Sources

  • December 02, 06:50 PM

    Smart URL Redirects in Django

    While building ComicBinder’s URLs, I wanted a way to differentiate a volume of a title other than one, and a printing of an issue other than one. So, for example, a URL to the second printing of the second volume of Amazing Spider-Man #1 would look like:

    /marvel/amazing-spider-man_2/1_2/
    

    That’s easy enough with some URLconf wrangling. What I’m talking about today is automatically redirecting a request for _1 in any of those places to the same URL without the _1. While technically correct, I want the lack of underscore + number to mean one, and for there to be only one URL for a resource (someone send me a link to a clever article that talks about this).

    django.views.generic.simple.redirect_to to the rescue. Try something like this:

    (r'^(?P<publisher>[-\w]+)/(?P<title>[-\w]+)_1/(?P<number>\d+)_1/$', 'django.views.generic.simple.redirect_to', {'url': '/%(publisher)s/%(title)s/%(number)s/'}),
    

    I made a few of these to account for situations where it was the first volume, but nothing specified for printing, and vise versa.

    Not too bulky, and since I have that sitting near the normal rule, it shouldn’t put me out too much to update it if I make any changes.

    Source

  • November 09, 05:55 PM

    How to Log Something

    With The Django Debug Toolbar

    Somewhere in your Python code (not a template):

    import logging
    logging.debug(something_you_want_to_log)
    

    With Firebug

    Somewhere in your JavaScript or the Firebug Console:

    console.log(something_you_want_to_log);
    

    That was easy.

    Sources

  • October 29, 06:13 PM

    Display the Number of Comments on a Blog Post in EE and WP

    ExpressionEngine:

    <a href="{comment_url_title_auto_path}#comments">{comment_total} {if comment_total == 1}Comment{if:else}Comments{/if}</a>
    

    WordPress:

    <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?>
    
  • September 15, 03:05 PM

    Remove a Git Submodule

    1. Delete the relevant line from the .gitmodules file.
    2. Delete the relevant section from .git/config.
    3. Run git rm --cached path/to/submodule (no trailing slash).
    4. Commit and delete the now untracked submodule files.

    Source

    • Chat conversation with JTJ.

Posts

Upgrade Flash to view this site properly