Monday, September 05, 2016

Another try at Matplotlib

Awhile back, I finally managed to install Matplotlib (and Mayavi) through general package management tools on the Mac. Through a combination of Homebrew and Pip and a lot of finagling, my take-3-or-so try at getting the Python graphing libraries to work actually came to fruition.

Some recent feedback on the tXtFL AI prompted me to revisit the modeling software, but alas, Matplotlib was no longer working on my system. When I tried to run my scripts, I got a "Fatal Python error: PyThreadState_Get: no current thread. Abort trap: 6" error. As far as I can tell, the error tracks back to a bug in the latest version of vtk included with Homebrew.

What was odd to me was that the Virtualenv technique I had used was supposed to isolate the dependency chain so that the packages would continue to work even if some of them got updated and broke compatibility with other packages. I realized, however, that the Homebrew package installations take place outside of the virtual environment, so at least the way that I've been using Virtualenv probably does not fully isolate the environment.

Not being able to run a modeler just because of a broken dependency is of course a real bummer, so I set out to find alternative solutions. I've been reluctant to try commercial offerings in hopes of sticking with generalized package management solutions such as Homebrew, but I came across an at least partially open source solution called Anaconda. The trouble with installed Matplotlib from scratch is the sheer number of dependencies (no less than "pycairo, PyQt4, PyQt5, PySide, wxPython, PyGTK, Tornado, or GhostScript" listed on the official installation page), which makes having a dedicated package manager via  Anaconda for these and other Python scientific computing dependencies make perfect sense.

Anaconda offers the option of a complete install ("Anaconda") vs a minimalist install ("Miniconda"), and I went for the Miniconda install to see if I could get by with it. After installing the 64-bit Windows version, I created a separate virtual environment inside it with the Matplotlib and Mayavi libraries as follows:

conda create --name pystat matplotlib mayavi

Apparently including all required packages at environment creation time is preferable. Anaconda pulled in all the other required dependencies and set up the virtual environment. All of these packages apparently are available for new virtual environments as well, which streamlines future downloading.

I'm used to using Cygwin for all my Bash-within-Windows computing, but Anaconda and Cygwin do not appear to always play nicely with each other. I tried at activate the virtual environment within Cygwin, but the detected python appeared to be from Cygwin rather than from Anaconda.

Instead, I dropped into an old-fashioned Windows command prompt and fired up Anaconda from there. A simple "activate pystat" command brought me into the correct environment. I had to learn though that "cd d:\src" does not automatically bring one into that folder, but apparently typing "d:" as a separate command first is required. Clearly I'm a Windows command prompt newbie.

From there, both matplotlib and mayavi worked out of the box. I didn't even need to use the custom launch script that I had used previously. The beauty of Anaconda it is cross-platform, so I next plan to see if it will work as seamlessly back on my Mac as it has on Windows. Or maybe by then, vtk with brewed python will be friend again.

Sunday, June 26, 2016

Crowdsourced Prayer

I've always wondered why we should ask others to pray for us if God hears the prayers even of one--and especially if he knows our needs even before we ask of him. Having others pray for us might seem to be redundant, or if we were to take it to the extreme, even faithless.

One Scripture that comes to mind regarding the prayers of many is from Revelation, where the multitude if prayer is likened to incense being poured out to God. There is no indication that these prayers somehow grab his attention better or that they might get lost otherwise, but rather that just as incense is a way of worship, so also the prayers of many combine to form collective praise to our God.

Asking people to pray for us may then be less about maximizing the chances that God might answer our prayer and instead more about creating an opportunity where more people might worship God. And how does that happen through prayer? By asking others to enjoin in our requests, we give opportunity for more people to see how God answers our requests. By crowdsourcing our prayer, we collectively reap the rewards. Our concerns become others' concerns, and likewise our answered prayers become others' answered prayers.

Wednesday, August 19, 2015

Troubleshooting SELinux

As much as I hoped to make the greatest use of SELinux to secure my servers, I've typically dropped it into "permissive" mode after encountering cryptic security restrictions. I recently set up a basic Fedora server on Digital Ocean including SELinux and decided to try sticking it out with SELinux in full protection mode.

And as usual, I encountered a cryptic "failed to start" error while reconfiguring an Apache server. Thanks to a comment on one of the Fedora forums, I found a convenient tool, audit2why, to help decipher the error message. Piping the error output into audit2why (eg systemctl status httpd.service|audit2why), the tool actually gave me the specific command to adjust the setting in SELinux.

Now we can have peace of mind and peace of configuration too!

Thursday, December 11, 2014

Migrating Git repo from Eclipse to Android Studio

I've been tracking the Android Studio releases from afar for awhile and have been looking for an excuse to truly give it a shot. Besides the fact that Java 7 for IntelliJ wasn't really supported on the Mac for some time, the transition from the Eclipse build system to Gradle seemed a bit invasive.

One of the biggest barriers in my mind was migrating my Git repository to the new Gradle structure without losing file history. Android Studio will migrate an Eclipse project to an Android Studio, Gradle-based one, which involved moving a number of folders as well as replacing Eclipse- with Gradle-specific configuration files. I wanted to use the Android Studio migration tool but was unsure whether Git would identify these changes as file moves or treat them as entirely new files, which would make tracking file history more cumbersome.

Some have found that Git will identify these files as simply moved/renamed, but unfortunately I did not experience that. Instead, I found that I could run the migration tool in a separate location and manually recreate the moves on the original repository. Here's how I did that, in case anyone else is trying the make the move as well.
  1. Create a new branch in the Eclipse project location. This will make it easier to delete any changes if migration gets messy.
  2. Start the Android Studio migration tool. To get it running, I closed any open Android Studio project, and the wizard popped up. I then chose to import a non-Android Studio project and pointed to the Eclipse project location. For the new project, I chose a distinct outside folder location.
  3. Migrate the project! There were some errors upon actually building the project, but at least for me the migration itself went smoothly.
  4. Mirror the major folder moves. Back in the original Eclipse project location, I started moving folders via git to mirror the new structure. The key is that there are really only a few folders to move, so it's not as painful as it looks. Here are the main commands I ran, with help from this post:
    mkdir -p app/src/main/java
    git mv src/com app/src/main/java
    git mv res app/src/main
    git mv assets app/src/main
    git mv AndroidManifest.xml app/src/main

    "src/org" can be changed to whatever your source sub-root folder is, and "assets" or other folders may need to be in/excluded according to your project files.
  5. Commit these changes in the new branch. Now they are ready to be picked up in your new Gradle-based project!
  6. Copy the Eclipse project's .git folder into the new Gradle-based project location. This will make the Git repo with all the major moves available in your Gradle location, including the new branch where all the dirty work is being done.
  7. Turn on VCS for the new project. Android Studio has a dedicated VCS menu with the option to turn on various versioning systems. Once it's activated, you can show changes and confirm that Git sees all those moved files as being in the right place.
  8. Add all the new Gradle-based files. The nice thing about using the Android Studio VCS is that it knows not to show a bunch of Gradle build files that shouldn't be version controlled. It also deletes a bunch of Eclipse-specific project files from Git simply because they weren't migrated. The challenge however is that it doesn't by default offer to add all the files you do in fact need. Here are the files that appear to be key, which I learned from viewing the Android Samples project structure:
  9. Commit all changes to Git. If you've pushed them, you should be able to pull them on another machine right from within Android Studio to access your project there.
From my brief taste of Android Studio so far, it's been quite a treat!

Wednesday, April 30, 2014

FlightGear Mod Repo

I've been enjoying FlightGear too much recently and felt it's high time to finally start giving back what little I can. I've set up a small repository to collect modifications I've made to existing components, which for now merely consists of one aircraft and the joystick I use.

Feel free to incorporate any elements into your own midnight flights and to post any changes of your own!

Wednesday, March 26, 2014

EXTRA_PLAYERS in Google Play Services

I noticed while updating an Android app to the new Google Play Services API 4.3 that the EXTRA_PLAYERS constant appeared to have disappeared. The Google Play Games documentation (as of 3/26/2014) suggests that it had moved to Multiplayer.EXTRA_PLAYERS as did several other constants, but no such variable or any other location for the variable could be found.

Using Google's own cached pages feature, I found that an older version of the documentation refers to another method, RealTimeMultiplayer.getSelectOpponentsIntent. That method's documentation in turn refers to a Games.EXTRA_PLAYERS_IDS. It looks as if this variable is the new equivalent of the old EXTRA_PLAYERS constant, although I have no other way of verifying this except that my app appears to be working in multiplayer mode.

Hope this helps anyone looking for an extra variable to take the place of EXTRA_PLAYERS.