Posted on

Google Cloud SDK – Creating a Guestbook Application

Google left out a lot of steps in their tutorial on using the App Engine to access a Datastore. Not only that, but if you want to run Python 3.x and 2.x on the same machine there are some simple ways to handle it that Google never explains. Here is the run down:

1. download and install python 3.x from the python website. this will include the py.exe python launcher
2. download and install python 2,x because Google doesn’t support 3.x when this was written
3. download and install the google cloud SDK and don’t use their bundled python option
4. when you open the google sdk command prompt, enter this to use the correct python version: SET PY_PYTHON=2

That’s it for the setup portion. Now for the real problem! You cannot execute the dev_appserver.py ./ python script and have it open a http server as expected. It will run and say something like “update#setState idle”
Also, you will get get an error (ERR_CONNECTION_REFUSED) trying to connect to locahost:8080. You need to do the following instead:

1. as mentioned in the install instructions for google cloud python sdk, you must install the missing python components using gcloud commands from a temp directory somewhere on your computer. This usually works:
cd %TEMP%
2. now enter the gcloud command:
gcloud components install app-engine-python
and when that is done get the extras because it didn’t work for me without them:
gcloud components install app-engine-python-extras
3. now you can run the dev_appserver.py but you have to use the py.exe launcher to make sure the correct v2 python exe is used, so change directories to where your project is and enter this command:
py “C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py” ./app.yaml
4. open a web browser and go to http://localhost:8080 to see the results

Posted on

How to compare strings using QString and Qt::MatchFlags for Qt5 and up

The Qt QString class is missing a really great opportunity to use the same Qt::MatchFlags that are used elsewhere in Qt. In the interest of making it super easy to add this functionality to my existing code and yours, just copy the following code into one of your commonly used header files. Make sure to actually include the required headers as shown in the comments. Then you can match your strings using Qt::MatchFlags.


/** determine if the pattern matches the string using Qt::MatchFlags
    \param str the string
    \param pattern the pattern to find
    \param flags any combination of the follow Qt flags
                - Qt::MatchFixedString
                - Qt::MatchContains
                - Qt::MatchStartsWith
                - Qt::MatchEndsWith
                - Qt::MatchRegExp (overrides all flags above)
                - Qt::MatchCaseSensitive
    \returns true if the pattern is found in the string

    requires:
    #include <QString>
    #include <QRegularExpression>
    #include <QRegularExpressionMatch>

    Thank you for visiting sirspot.com
    This code is not guaranteed to work.
    Use at your own risk.
*/
static bool QString_Matches(
    const QString& str,
    const QString& pattern,
    const Qt::MatchFlags& flags = (Qt::MatchCaseSensitive | Qt::MatchFixedString))
{
    if(flags.testFlag(Qt::MatchRegExp) == true)
    {
        QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
        if(flags.testFlag(Qt::MatchCaseSensitive) == false)
        {
            options = QRegularExpression::CaseInsensitiveOption;
        }
        QRegularExpression regex(pattern, options);
        return regex.match(str).hasMatch();
    }
    else
    {
        Qt::CaseSensitivity cs = Qt::CaseSensitive;
        if(flags.testFlag(Qt::MatchCaseSensitive) == false)
        {
            cs = Qt::CaseInsensitive;
        }
        if(flags.testFlag(Qt::MatchContains) == true)
        {
            return str.contains(pattern, cs);
        }
        else
        {
            if(flags.testFlag(Qt::MatchStartsWith) == true)
            {
                if(str.startsWith(pattern, cs) == true)
                {
                    return true;
                }
            }
            if(flags.testFlag(Qt::MatchEndsWith) == true)
            {
                if(str.endsWith(pattern, cs) == true)
                {
                    return true;
                }
            }
            if(flags.testFlag(Qt::MatchFixedString) == true)
            {
                return (str.compare(pattern, cs) == 0);
            }
        }
    }
    return false;
};

Happy String Matching!

Posted on

Is Climate Change and Global Warming Fake News?

It’s really not fake news. The global average temperature is definitely on the rise. What could be considered fake news is how much humans have contributed to the rise in temperature. This is difficult, but not impossible to determine. I think the correlation of the data charted on these two sites is very telling.

https://climate.nasa.gov/climate_resources/24/

https://climate.nasa.gov/vital-signs/global-temperature/

So Yes, global warming is real and humans are responsible.  The next question is, “will it stop or can it be stopped?”  That’s a much harder question to answer!

Posted on

Hour of Code

Last year I went to 3 schools for Hour of Code.  This year I have already been to 3 schools and am schedule to visit 2 more schools before the end of the week.  The students range in age from 6 years old to 13 years old.  I tailor my presentation to each class based on how responsive the students are.  It is a lot of fun!  If you don’t know what Hour of Code is, you can visit the official site here: https://code.org/learn but basically it is just a week out of the year when we try to get students interested in computer programming.  Have a great week and give the Hour of Code a try!