Tuesday, October 10, 2017

Python and SublimeText

Function hints and autofill of function parameters - notes to help me out in the future.

Install the SublimeText Anaconda Package (not the Python distribution Anaconda).

The Python Improved package and the Neon Color Scheme provide nice Python typing support

When using Docker, Anaconda doesn't necessarily know where the python package your are editing is so you need to help it by adding the following into the SublimeText Project settings (Project -> Edit Project). Note you can't open up the .sublime-project file using SublimeText as it will just keep opening up the Project and not the file. Add in the settings with the top folder of the python package:
"settings": {
        "extra_paths":
        [
            ""
        ]
    }
Also, make sure you add the python modules using pip that you are using in the Docker python system to the python interpreter (you can also use a virtual env for the project and that should be added to the SublimeText project. You should now have function and method hints from your project and any additional python modules you are using. My Anaconda user settings:
{
    "python_interpreter": "/opt/local/bin/python",
    /*
        If complete_parameters is true, anaconda will add function and class
        parameters to its completions.

        If complete_all_parameters is true, it will add all the possible
        parameters, if it's false, it will add only required parameters
    */
    "complete_parameters": true,
    "complete_all_parameters": false,

    // If true, anaconda draws gutter marks on line with errors
    "anaconda_gutter_marks": true,

    // Inline error messages by inserting extra lines as needed
    "anaconda_linter_phantoms": false,

    /*

        If anaconda_gutter_marks is true, this determines what theme is used.
        Theme 'basic' only adds dots and circles to gutter.

        Other available themes are 'alpha', 'bright', 'dark', 'hard' and
        'simple'. To see icons that will be used for each theme check
        gutter_icon_themes folder in Anaconda package.
    */
    "anaconda_gutter_theme": "bright",

    /*
        If 'outline' (default) anaconda will outline error lines
        If 'fill' anconda will fill the lines
        If 'none' anaconda will not draw anything on error lines
    */
    "anaconda_linter_mark_style": "outline",

    /*
        A list of pep8 error numbers to ignore. By default "line too long" errors are ignored.
        The list of error codes is in this file: https://github.com/jcrocholl/pep8/blob/master/pep8.py.
        Search for "Ennn:", where nnn is a 3-digit number.
    */
    "pep8_ignore": [
        "E127", "E128", "E501", "E402"
    ],

    "anaconda_linter_mark_style": "outline",

    /*
        Set the following option to true if you want anaconda to check
        the validity of your imports when the linting process is fired.

        WARNING: take into account that anaconda compiles and import the
        modules in the JsonServer memory segment in order to check this
    */
    "validate_imports": false,

    /*
        MyPy

        Set the following option to true to enable MyPy checker.
    */
    "mypy": false,

    /*
        Command to execute tests with. nosetests by default
    */
    "test_command": "py.test",

    // Maximum line length for pep8
    "pep8_max_line_length": 79

}

Thursday, March 23, 2017

Aurelia View Engine Hook for importing enums, static variables, etc

Thanks to a query from Github user @TheNavigateur asking "Allow[ing] import of exported module items into aurelia template, to allow access to static methods, static variables, enums, type definitions, etc. "

and then Rob Eisenberg's example (issue/comments) of how to do this:

Thursday, March 17, 2016

Aurelia custom element async life cycle event

I saw a really good conversation in the Aurelia/framework Github issue queue that I wanted to save for later.  https://github.com/aurelia/framework/issues/367#issuecomment-198104416

From Rob Eisenberg:

We can't provide this (async promise life-cycle events) across all components. It would be a disaster for performance and would no longer map in any way to web components. 
If you don't care about web components, you can use the new CompositionTransaction: http://aurelia.io/docs.html#/aurelia/templating/1.0.0-beta.1.1.2/doc/api/class/CompositionTransaction 
Simply have that injected into your component constructor and then call enlist() this will return you a CompositionTransactionNotifier: http://aurelia.io/docs.html#/aurelia/templating/1.0.0-beta.1.1.2/doc/api/interface/CompositionTransactionNotifier 
You can call done on that when your async operation is complete. The global composition will wait to attach until after you are done.

How do I wait for async data for an Aurelia custom element?


Thursday, March 3, 2016

JSON Web Token payloads

I really like the JSON Web Token (JWT) technology for Single Page Application (SPA) user authentication.  I started off quite excited about storing things like permissions and other user profile data in the JWT.  My initial thoughts around JWT is that it was a good ‘state’ variable to hold user profile information on the client side.

The problem with that idea is that it is hard to expire and update a JWT if the user changes their display name or gets new permissions/claims.  If your SPA client is using the JWT payload to hold this mutable (server side mutable) information, your client won’t be updated in a timely manner - it will have to wait for a new JWT to be issued.  It is a little mean to require the user to logout and back in again to be able to use their new permissions or see their new display name show up on the web application.

Don't get me wrong, I'm not talking about concerns of the client side manipulation of the JWT payload.  I don’t trust anything from the client side.  Anything coming from the client has to be checked/validated on the server.  I know the new permissions really matter on the server side, but I would generally only allow users to see functionality that they are permitted (not that they can’t hack the front end code and do whatever they want on the front end - they just would not be able to complete the transaction on the server).

Wednesday, March 2, 2016

Aurelia delegate vs trigger

Great StackOverflow answer: Aurelia delegate vs trigger question

Aurelia change event Firefox woes

In the continuing adventures of Firefox vs other browsers (see Aurelia Firefox and Input fields), I was watching a checkbox using a change.trigger() to update the checkbox selection state for a search facet.  I noticed in Firefox that the change event checkbox selection value was pre-change vs Chrome and other browsers where the selection value was post-change.

Gitter Aurelia conversation discussed the issue and approach to fix it.

Using change.delegate gives the change event time to finish processing before it's handled.  I'm a little concerned about timing issues still as this doesn't seem deterministic, but it's working pretty well now.

Wednesday, January 27, 2016

We all make our mountains and we make them as tall as we need them

Putting things into perspective doesn't seem to work well as a coping mechanism.  If we have a problem, it doesn't matter that the problem isn't a big deal to anyone else.  It only matters how large a problem it is to us.  When other people try to minimize a problem (mountain) or put it in perspective, that doesn't help to make our mountain smaller to us, it just minimizes us compared to our mountain.