The goal of efficiency is more slack.

Sunday, October 13, 2019

Installing GStreamer Development for Visual Studio 2019

Install and create template.
  1. Browse to > Downloads.
  2. Download and install both MinGW 64-bit runtime installer and development installer.
  3. In Visual Studio 2019, open \gstreamer\1.0\x86_64\share\vs\2010\gst-template\gst-template.vcxproj
  4. Project > Export Template.
 Run example.
  1. Download
  2. Expand tutorials folder.
  3. Open tutorials.sln.
  4. Set solution platform to x64.
  5. Solution Explorer > Solution ''tutorials' > basic-tutorial-1 > Properties
    1. Debugging > Working Directory: $(GSTREAMER_1_0_ROOT_X86_64)\bin
      Note: To get the variable name, in cmd.exe, enter: set gstreamer
    2. Linker > Input > Ignore All Default Libraries > No (or delete setting)
    3. For Debug configuration, Ignore Specific Default Libraries: msvcrtd.lib
      Note: The gstreamer libraries were apparently built with /MD and not /MDd.

Friday, October 11, 2019

Fix route to VM after Cisco VPN remove them

Cisco AnyConnect VPN modifies/removes routes to the bridged network adapter on a VirtualBox VM when you log in. To connect to the VM again, you need to log off the VPN, as the Cisco VPN has a watchdog that reverts any route changes while the VPN is active. After logging off, run this reroute script:



# The following 2 deletions are not always needed
# route -n delete ${guestip%.*}.0
# route -n delete $guestip/32

route -n add $guestip/32 -interface vboxnet0
arp -s $guestip $guestmac
netstat -rnf inet | grep 192

Thursday, October 10, 2019

VirtualBox Windows XP Guest File Sharing

How to share files hosted on a Windows XP VirtualBox guest on a Mac OS X host to a real Windows XP computer.
  1. Plug in Thunderbolt Ethernet adapter to host Macbook Air.
  2. Connect Ethernet cable between client computer and host Mac.
  3. Mac Host > Network Preferences > Thunderbolt Ethernet
    1. Configure IPv4: Manually
    2. IP Address:
    3. Subnet Mask:
  4. VM Settings > Network settings > Adapter [n]
    1. Attached to: Bridged Adapter
    2. Name: en3: Thunderbolt Ethernet
  5. Guest VM > Network Connections > Wired network > Properties >
    1. Internet Protocol (TCP/IP)
      1. Check Use the following IP Address or Alternate Configuration
      2. IP Address:
      3. Subnet Mask:
    2. Advanced > Windows Firewall > Settings > Exceptions > Check File and Print Sharing.
  6. Client computer > Network  Connections > Wired network > Properties > Internet Protocol (TCP/IP)
    1. Check Use the following IP Address or Alternate Configuration 
    2. IP Address:
    3.  Subnet Mask:
  7. (Optional test) Ping from each computer to the others.
  8. Guest VM > Share a folder
    1. Make folder C:\share
    2. Right click folder > Properties
    3. Check Share folder on network.
  9. Client computer > My Network Places > share on Guest VM
  10. Done

Tuesday, September 17, 2019

Sites for Django

How to use the Sites package for Django.

Follow instructions in documentation to install the Sites package. Then create a migration in one of your apps.

from __future__ import unicode_literals

from django.db import migrations

def set_site_name(apps, schema_editor):
    Site = apps.get_model('sites', 'site')
        site = Site.objects.get(id=1)
    except Site.DoesNotExist:
        site = Site() = "Astrobiology"
    site.domain = ""

class Migration(migrations.Migration):

    dependencies = [
        ('sites', '0002_alter_domain_unique'),

    operations = [

Enter the latest migration from the "sites" app as a dependency to ensure there is a database table for sites.

On the development computer, run ./manage shell and change the domain of the site object to

Wednesday, September 11, 2019

List links in HTML files

This Python script walks through a directory of HTML files and extracts all the links. It outputs one line per link with each line also containing the pages in which the link appears.

import os
from os.path import join, getsize
from bs4 import BeautifulSoup
from urllib.parse import urlparse

# Links as keys, list of pages where the link appears as values.
links = {}

def get_links(filepath):
    with open(filepath, 'r') as fhandle:
            text = BeautifulSoup(fhandle, features="lxml")
        except UnicodeDecodeError:
            print("UnicodeDecodeError: " + filepath)
        # Iterate through all the "a" tags
        for link in text.find_all("a"):
            url = link.get('href')
            # Ignore relative links and certain domain names.
            if url and urlparse(url).netloc \
                and urlparse(url).netloc not in [""]:
                # Append link to dictionary.
                if url not in links:
                    links[url] = []
                # Limit number of pages to associate with link.
                if len(links[url]) < 8:

file_count = 0
fout = open("links.txt", "w")
# Iterate through all the files in the flattened site
for root, dirs, files in os.walk('.'):
    for f in files:
        if f not in [".DS_Store"]:
            get_links(join(root, f))
            print(".", end="", flush=True)
            file_count += 1
    # Stop after some files
    # if file_count > 100: break

# Write file with links.
for link, pages in links.items():
    fout.write(link + ", " + str(pages) + "\n")

Thursday, June 20, 2019

Regular expression to match URLs

Here is a regular expression to match URLs, from http to the end.



Note: Does not match some IP addresses.

Sunday, June 16, 2019

FeinCMS installation

Following directions at, I ran into some problems, probably due to a Django version mismatch. I'm using Django 1.11.x. This second tutorial helped fill in some blanks: . Below are my additions to the first documentation link.

Don't add context processors to the default set Django startproject created.

Create a folder for templates. Add it to
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'my_project/templates'),

Create a template base.html with at least the following:
{% block content %} {% for content in feincms_page.content.main %} {{ content.render }} {% endfor %} {% endblock %}

Create a new Django project in VSCode

  • Go to user settings (cmd-,):
"python.venvPath": "~/.virtualenvs",
  • Quit VSCode.
  • Open a Python file in VSCode.
  • Select virtualenv in bottom bar.
  • Debug > Open Configurations to create launch.json. Otherwise, "Add Configurations" may not work.
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit:
    "version": "0.2.0",
    "configurations": [
            "name": "Server",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/",
            "args": [
            "debugOptions": [
            "name": "Script",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/",
            "args": [
                "$(basename -s .py ${file})"
            "debugOptions": [
  • Click button on bottom right to Install Linting.

Install Django on a development Mac

Notes on installing a Django development environment on a Mac.

Install Python

  • Install Python 3 from
  • Run Install Cerltificates.command.
  • Install pip and virtualenv
pip3 install --upgrade pip
pip3 install virtualenvwrapper
Put virtualenvwrapper in .bash_profile:
# Virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
source /Library/Frameworks/Python.framework/Versions/3.6/bin/

Create a Python virtual environment

mkvirtualenv -p /usr/bin/python2 my_proj
cd ~/Documents/my_proj
-p is optional

Install Visual Studio Code

  • Install shell command: Cmd-Shift-p > shell command
  • Install Python extension.

Install Postgres

Install Django

pip install Django

Create directory

cd to the parent directory of the directory you wish to place the source files.
Create directory for source files with the Django startapp command.
django-admin startproject my_proj
cd my_proj

Create app

mkdir my_proj/my_form
./ startapp my_form my_proj/my_form

Configure for VSCode

code . 
Create a new Django project in VSCode

Initialize git

git init
git add .
If .pyc files were uninentionally added:
git rm --cached '**.pyc'

Create .gitignore

touch .gitignore
code .gitignore

Static files

STATIC_URL: URL (relative to domain root) to trigger searching for static files.
STATICFILES_DIRS: List of directories in which to look for static files when collectstatic is run.
STATIC_ROOT: Django serves files from this directory when run under development mode. Also, collectstatic collects static files here. Upload this to server.

In development: project/static, sibling to project/
On production: /home/user/
STATIC_URL = '/static/'
    os.path.join(BASE_DIR, "static"),
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'public/static/')   

Popular Posts

Recent Posts

Unordered List

Text Widget


Powered by Blogger.
Scroll To Top