Articles in the programming category

  1. [Python] Empty String?

    Posted on in Programming

    I've mentioned before that empty strings in Python are false. This leads to a common if not string paradigm. Unfortunately, this can be problematic. Check out this snippet:

    >>> string = ""
    >>> if not string:
    ...  print("empty")
    ... 
    empty
    

    That pretty much worked out just as we imagined. The empty string returned False and …

  2. Using Pelican's article.summary

    Posted on in Programming

    I'm using Jinja2 templates with my new Pelican-based articles. If you have Django experience, you'll feel right at home using Jinja2 templates. I decided early on that I wanted to create my own theme from scratch and keep it as basic as possible. (In fact, 'basic' is the name …

  3. Agreeing to the Xcode/iOS license...

    Posted on in Programming

    Sometimes this pops up when you least expect it:

    Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
    

    This morning, I went to refresh one of my git repo's for work, and make spit that out. What the heck happened last night? Anyway, the …

  4. MySQL Multiple-Column Indexes: Order Matters

    Posted on in Programming

    Powered By MySQLThis will just be a short reminder. If you're planning to create multiple-column indexes in MySQL, remember that the order of the columns matters. As the MySQL documentation points out, any "leftmost prefix of the index can be used." This means that the index can be used for any number …

  5. [Python] Convert String Date to Date Object

    Posted on in Programming

    Occasionally, you may run across a date in a format that can't be easily loaded into a Python date object. For example, I recently had a situation where a file I was parsing was full of dates in this format: 7/7/2008.

    The obvious thing to do here is …

  6. Empty Strings in Python Are False

    Posted on in Programming

    Recently I was working on some old code. One of my model methods was originally written such that if one parameter was set to the Python None type, a particular set of actions would occur. For some reason, I checked for None like this:

    if parameter is None:
        do something …
  7. The Beauty of Python File-like Objects

    Posted on in Programming

    As I mentioned the other day, I'm building a RADIUS client in Python for sending disconnect messages to Cisco routers.

    One hang-up with the pyrad package is that it requires a dictionary file in order to map RADIUS attribute names to codes and types. In the case of my client …

  8. [Python] Remove Whitespace From a String

    Posted on in Programming

    >>> print "".join(" hello   world ".split())
    helloworld
    

    The key to the above is that split() separates the string on any amount of whitespace when no separator is specified.

    python

  9. Listing WordPress Database Queries

    Posted on in Programming

    WordPress Horizontal Logo If you need to debug what queries your WordPress site is making, try adding the following PHP to your theme:

    <?php
      foreach ( $wpdb->queries as $query ) {
        echo "$query[0]<br />";
      }
    ?>
    

    For this code to work, you need to add the following line to wp-config.php:

    define('SAVEQUERIES', true);
    

    After that …

Slaptijack's Koding Kraken