Sunday, April 15, 2018

Net Ninja's React JS tutorial in c9.io - skipping webpack by using create-react-app

OK, many are the quirks in c9.io and many many are the quirks in configuring webpacket.

At this point I just want to improve how react itself works and not get bogged down in figgerin out webpacket (I will do that later, however).

So what I did was go through the first page or two of this tutorial: http://www.react.express/environment and am just figuring out how to do the Net Ninja tutorial on top of the template you get when you use create-react-app

The flavors of react are a little different bu I believe that will save me a lot of time.

First I got the create-react-app up and running just fine in the browser.

So going forward I am just tacking the Net Ninja components onto the existing app.

So for example the react app gives you

    import React from 'react';
    import ReactDOM from 'react-dom';
    import './index.css';
    import App from './App';
   import registerServiceWorker from './registerServiceWorker';

     ReactDOM.render(<App />, document.getElementById('root'));
     registerServiceWorker();

and 


    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';

    class App extends Component {
     render() {
         <header className="App-header">
              <img src={logo} className="App-logo" alt="logo" />
              <h1 className="App-title">Welcome to React</h1>
             </header>
            <p className="App-intro">
              To get started, KLJHKJLHKJ dit <code>src/App.js</code> and save to reload.
             </p>
        );
      }   
    }

    export default App;

So, for the very first component Net Ninja has us build, I just changed App to 

    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';

    class App extends Component {
     render() {
         return (
          <div className="App">
           <h1>hellooooooooo</h1>
          </div>
        );
      }   

    }

    export default App;


Now, if I wanted to in turn add a child component to App I can just do this:



    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';
    import Howdy from './Howdy';

    class App extends Component {
     render() {
         return (
          <div className="App">
           <h1>hellooooooooo</h1>
           <Howdy />
          </div>
        );
      }   

    }

    export default App;


and here is the 'Howdy' component:

    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';

    class Howdy extends Component {
     render() {
         return (
          <div className="App">
           <h1>howdy howdy howdy howdy howdy!</h1>
          </div>
        );
      }   
    }

    export default Howdy;

NOTICE THE FOLLOWING:

The App component can use the Howdy component because the App component contains

     import Howdy from './Howdy';

And the Index component can use the App component because the Index component contains

    import App from './App';

Monday, April 2, 2018

Learning to Code Over 40

I did not get super-serious about learning to code until I myself was in the 40+ set.

Allow me to share with you some hard-won wisdom:

1. DO NOT BE A HELP VAMPIRE

Don't know what a "help vampire" is? Google it. For at least the first year that you are learning this stuff, there are absolutely no questions or conundrums you will encounter that have not already been solved and documented in at least eight places. Unless you are trying to learn some brand spankin' new language or framework that just came out last year, the answers are already there somewhere for you to google. Do NOT add to the pile of stupid, poorly researched questions that have already been answered. You will only serve to discourage those who are willing to provide their time and talent to places like stackoverflow. Ultimately, you are shooting yourself in the foot. Train yourself to dig in and research the crap out of every corner of the internet when you encounter a sticky problem - apparently that is what real developers do. Welcome to the new normal.

2. DO NOT CODE ALONE

OK, obviously you are going to have to code all by yourself to get through the first few dozen tutorials in order to get a baseline understanding (unless you are starting down this road with a coding buddy, which I wish to heck I had!). What I mean, however, is that there is going to be a point where your mind has been expanded by this stuff, and you are champing at the bit to do more than just tutorials. It is a really, really bad idea to continue on all alone at this point. What you are going to end up doing is spend months reinventing the wheel to create nothing but irrelevant, low quality crap. If I sound bitter it is because I myself have wasted several months getting all wrapped up in projects I dreamed up and planned on my own, while all that time and energy could have gone to working with other people and learning the proper things like what good design actually is, what quality code actually is, and how things like Github work. Don't waste your time. Hook up with an opensource project when you are ready to actually start building new stuff.

3. IF IT DIDN'T HAPPEN ON GITHUB, IT DIDN'T HAPPEN

Most likely, the first five questions of any tech interview that you might go to sometime down the road are going to be questions about Github. Github is where your work will be expected to be stored. Github is how the quality of your code will be assessed. If you don't know Github, you don't know squat. If your code is not on Github, nobody is going to bother looking. Again, learn to code as part of a group of remote devs; this will force you to become very github-capable.

Thursday, March 15, 2018

Visual Studio 2012 Coded UI Test for Crystal Reports are too slow - how to speed them up

OK I have been getting really discouraged writing coded UI tests to test the output of Crystal Reports.

Seriously it was taking over seven minutes for one test to run. Ridiculous.

So I took a step back and asked what is the original problem. What do I the human tester actually need and do when manually testing one of these reports?

I decided to set formatting aside. Important, but for my particular needs I could indeed relegate that to other tests or even to manual testing.  The most important thing for me was to test the content of the Crystal report output to make sure what was coming from the database was correct. The other important thing was to run the multiple data exports, which manually involved clicking buttons, waiting, clicking more buttons, dozens of times over.

So the answer so far is to divide, focus, and conquer.

I put the button pushing into entirely separate tests. Now I can just run those UI tests and the machine does all the button pushing for me while I do something that really requires the attention of an actual person.

Back to the content: I just want to make sure the content is correct.

Remember how in your mapWhatever.cs code you've got lines of code that look like

     var something = rpt.UIWEbblahbalh.UIBobjidyaddayadda.somethingsomethingFrame...InnerText

?

That's called threading. Threading is what is going to kill your efficiency with this tool and with theses tests. Threading takes a looong time for some reason. YOU ONLY WANT TO THREAD ONCE IF YOU CAN HELP IT. My problem was I was threading multiple times, slowing my test way down.

So I just figured out how to thread once and get all the content of the report into a single long string (this will vary depending on how your page was built). Then, for the assertion I did StringAssert.Contains(<bigString>, <smallString>)

<bigString> is the big long string of content.

<smallString> is the value I need to make sure appears in the content.

Test takes less than two minutes now. Still slow, but in the acceptable range, because I have to do this same test dozens of time every time we update and have to do general regression testing. Better to have the machine do it.

Tuesday, March 6, 2018

Invalid Host Header Error in a C9 react App

So I am working remotely on a Chingu Voyage remote development project. I need to run and test changes to the application in c9 so I can work on this on my lunch breaks.  To that end, I created a c9 workspace from project's GitHub and tried to run the application we are developing.  I kept getting the invalidHostHeader error message after running npm start.

Tried to google the answer for a couple hours.

Oh my what a headache.

OK, so I FINALLY arrived at what I think is at least a stop-gap solution for my particular situation.

1. Create a file in the root of the application called ".env.development"

2. Update that file to say "DANGEROUSLY_DISABLE_HOST_CHECK=true"

3. Save


BE SURE TO INCLUDE the ".env.development" file in your gitignore file. You DO NOT want this going out with you application. I probably don't even want this on my c9 workstation but it is the only way for me to proceed at the moment.

Saturday, February 24, 2018

Integrating Passport with an Existing Node.JS Application

This is not an exhaustive step-by-step. It is a high level overview of what questions you should be asking yourself as you integrate an authorization service like GitHub's Passport service with an existing node.js application, and roughly in what order you should be asking those questions. Step 0: get an app fully working that you will then be able to open up to other users via some sort of authorization service. So for example I worked through this tutorial and got it working: http://www.clementinejs.com/tutorials/tutorial-beginner.html, then to learn Passport started down this road: http://www.clementinejs.com/tutorials/tutorial-passport.html. Step 1: You then have to register your app with the service ( for this I am registering with GitHub but I think the overall process is roughly the same for any other service like Twitter, Google, or Facebook). The result of your efforts will be an API key that is like the secret door between that service and your app! Step 2: Back in your application, set up the data model to use the information that will come in from the API. The fields you add will typically be something like id, displayName, userName, and publicRepos (notice there is no need to store passwords or any of the associated headaches; that is one big reason for using one of these authorization services) Step 3: In you application, make sure the API key and any related stuff from the authorization service gets stored in your .env file and then that .env file gets included in the stuff that does NOT get pushed up to GitHub (if you are indeed using GitHub as your code version management repository - sorry, this is an assumption on my part) Step 4: Authorization Configuration. Huh-boy, here we go. The thing is, the authorization service we are using (gitHub in this case) needs to be able to confirm your application has permission to access the authorization service's API and retrieve user information. To that end, your application needs to reference the Node process.env object. So you have to export it so it is available (via require) in other parts of your application. Step 5: Set up the authentication part of your application. Step 6: Changing your existing application means adding lots of new functionality and changing a lot of existing functionality. This varies from application to application and authorization service to authorization service. What follows are examples of the kinds of questions you have to ask yourself before you can get your application to play ball with the authorization service you chose to work with. - Make sure that, in the transition from your original application to a version that uses Passport, you made any modifications to your server-side code that accounts for these changes ( for example, did changes to which model you are using require updates to the server-side controller?) - Do not forget to also change and update routes accordingly (for example, make sure passport is one of the arguments for the main function in routes - this will expose the stuff that comes with Passport to your routes)! - Now that the application is using an authentication service, the user needs to have a loggedin/notloggedin state; typically this is handled by a function in routes. - Similarly, did you update your AJAX functionality? Step 7: Changing your existing application to use an authorization service will mean adding new views and updating others Step 8: Changing your existing application to use an authorization service will mean some of the views that you add to your application will need additional controllers to work with the API connecting your application to the data the authorization service provides. Most likely you will need an additional controller that updates the view(s) with information it retrieves the user information from the API.

Saturday, January 6, 2018

Interval

Interval