Friday, October 13, 2017

uwsgi wrong python interpreter

In some projects, I use uwsgi behind nginx to drive Django. I also use virtualenv to manage my environments (by the way, Panda's introducing .ix and then deprecating it wasn't fun). In a recent update, I was pulling my hair out trying to figure out why I'm getting the following error message, and a wrong Python interpreter.


Could not find platform independent libraries
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
Python version: 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
Set PythonHome to /opt/anaconda
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'



It turned out that the problem was in the binary code of uwsgi in my environment. It was compiled for another environment, with the environment path hard-coded in. Yes, in the binary. I had done that in another environment and the compiled package stayed in the pip cache, and the new environment just picked it up from the cache, causing inconsistency!

The solution:


pip install --no-cache uwsgi

Tuesday, July 11, 2017

Ergodox EZ Configurator Layer Manipulation

Ergodox EZ provides a great configurator; however, it doesn't provide all editing functions I need. Unfortunately, the source code disappeared from github (multiple unofficial documents have links to that repo so I assume the source was once available; this is rather disappointing, since the company made it look like that they are using all open source resources.)

One of the functions that I need the most is swapping the layers.

Here's what I did to achieve it:

Upon examining the minimized javascript, it was written against the React framework. Therefore, I installed the React debugger extension for chrome, in order to find and manipulate the variable that stores the layer information.

Once the extension is installed, reload the page, and open up the Developer Tools in Chrome.
Click on React to open the debugging panel.
Make sure the correct scope "App" is selected.
Now the variable $r will contain the React object, including the state, for editing.
The layers (including all key assignment) information is in the array: $r.state.layout.layers

Here's an example of swapping layer 3 and 4.


$r.state.layout.layers = [
$r.state.layout.layers[0],
$r.state.layout.layers[1],
$r.state.layout.layers[2],
$r.state.layout.layers[4],
$r.state.layout.layers[3],
$r.state.layout.layers[5],
$r.state.layout.layers[6],
$r.state.layout.layers[7],
]



Note that if there are layer switching keys, you'll also need to manually modify those from the GUI.

I also did some batch editing offline, and then re-assign the whole $r.state.layout.layers
by first converting the variable to JSON and write it to a local file, with this snippet.

Also when you copy/create a layer, make sure to use the GUI to first allocate the variable $r.state.layout.layers[x].keyboard_layout_id on their server and then carefully copy those values.

Here's my current setup, if you are interested.