SQL in easy steps, 3rd Edition errata

I was reading through SQL in easy steps, 3rd Edition and made it to page 152 where it covered Sub-query calculated fields. It’s a fancy way of saying a SELECT statement within a SELECT statement, but isn’t that hard to grasp if you’re familiar with how variable interpolation works with Bash or similar shells.

My problem was understanding how even though a column wasn’t listed as one to be returned by SELECT it was seemingly returned as a byproduct of an ORDER BY statement. I couldn’t find this mentioned in any of the MySQL documentation or another MySQL book I have so I was getting pretty frustrated. I fired my MySQL this morning and opened up subquery-calc.sql and had a good laugh: The mental block I was having was due to an error in the book’s code that wasn’t present in the SQL file.

I fired off an errata report in the hopes that it will be correct in future printings so others won’t be as confused as I was.

Continue reading

Renaming files with Python

I downloaded some PowerPoint slides and wmv programming videos from a college website and the original file names had spaces in them, so my browser’s downloader plugin converted the spaces to _20. I wanted to rename them so they wouldn’t have the _20 in them, and the following is the code I used to do so. Hope someone finds it useful.

import os
import os.path

files = os.listdir(os.getcwd())

for file in files:
    #if '20' and 'wmv' in file:
    if ' ' and 'ppt' in file:
        new_name = file.replace(' ', '_')
        print "%s   %s" % (file, new_name)
        os.rename(file, new_name)

Counting the number of items in a line

This short script was used to count the number of pipes in a line. I wanted to have 9 per line so the Dokuwiki table would be displayed properly, so this script let me know which lines were busted.

# Purpose: 
#     Get number of pipes per line. The first line should be what you 
#     want the others to match

import re
import os
import sys

game_collection_file = sys.path[0] + os.sep \
    + 'game_collection_dokuwiki_list.txt'
game_collection_fh = open(game_collection_file)

rexp = re.compile(r"\|")

count = 0
for line in game_collection_fh:
    count += 1
    match = rexp.findall(line)
    if len(match) != 9:
        #print "Number of pipes on line %s: %s " % (count, len(match))
        print "line %s: %s " % (count, len(match))

Making Firefox maximize on startup

You’d think something like this would be incredibly easy, maybe even be in an options tab or possibly prefs.js in the user’s profile.

Eh, sort of.

The setting is in localstore.rdf within the user’s profile. This value is supposed to be saved automatically when closing out of the browser, as this page mentions.

In my case I want a lab of users to all receive the same “maximize window” setting. Thankfully, the user profile being used is thin and I don’t have to worry about them having a personalized localstore.rdf file.

Here is the file I’ll use:

<?xml version="1.0"?>
    Purpose: Set the Firefox window to maximized. This file would be copied
             over on every login, thereby preventing the window from coming up
             sized smaller. Users are able to size it themselves during their
             browsing session however.
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#sidebar-title"
                   value="" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
                   sizemode="maximized" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul">
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/>

Here is the relevant value:


Hope somebody finds that useful. 🙂

C++ Standard update

Overview: C++ Gets an Overhaul

As I’m new, most of that is right over my head. What I do get out of it is they’re going to be adopting a lot of the Boost libraries. Little surprise there as I read a lot about the Boost libraries.

Here is one part that show how new I am to C++:

C++0x also removes some embarrassments from the language. For example, C++03 has at least three different forms of initialization:

int x=0;
int x(0);
int y[2]={1,2};

C++0x defines a unified initialization notation which can even be used in the declaration of dynamically allocated arrays:

I knew about the syntax for the first two in the list but had not seen the third or had seen it described differently.

int* a = new int[4] {1, 10, 20,95 };
vector<string> vs={"ab","cd","ef"};

class S {
 int arr[3];
  S() : arr{ 1, 2, 3 } {}

This last code block looks a little alien to me. Perhaps that’s just because my exposure to C++ classes is so limited.

Either way, this is definitely a month for change in the C++ world:

The vast number of new features forces the committee to work at an incredible speed. A clear statement of intent was made to complete work on the new standard at the San Francisco meeting of September 2008 in order to achieve publication in 2009.