Don’t forget to remove the end forward slash when enabling CORS

You ever run into an issue with your code, spend way to long looking at it and not get anywhere?  Especially one that you’ve solved before but having a lapse in memory.  That was me all too recently.  I was setting up an app that consisted of three projects in a solution.  One project for the API, one for the DTO, and another for the MVC.  The problem with this setup is that any Javascript call from the MVC project to the API will be blocked when the data comes back due to the browser enforcing same-origin policy.  Microsoft has a great write-up on how to Enable CORS within an ASP.NET Web API 2 project.  For your own sanity please make sure you go the whole through section.  I mean, the whole thing, all the way to the end, because at the end of the section is a rather important fact.  When you are defining the EnableCors attribute on the API controller you need to make sure that the forward slash at the end of the origins parameter is removed.

Good: [EnableCors(origins: "http://localhost:49332", headers:"*", methods:"*")]

Bad: [EnableCors(origins: "http://localhost:49332/", headers:"*", methods:"*")]

That is it.  That single forward slash tripped me up.  The error written to the web DevTools console was
Access to XMLHttpRequest at 'http://localhost:49342/api/users/name/smith/' from origin 'http://localhost:49332' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Hope this helps you waste a little less time.

ion-toggle Toggle/Change event handling

I’m working on an Ionic v2+ app that requires some extra logic to be executed when a toggle switch, also known as a radio button, is changed.  In Ionic this component is called an ion-toggle.  I tried using the normal Angular.io decorators like (change) or (click) but none of them were firing.  What I didn’t realize, mainly because I didn’t see it in the Ionic documents was that in order to handle changes in the state I needed to use the (ionChange) decorator on the component.  With this I could pass in more details to the function being executed.

<ion-toggle id="toggle{{parent.name}}{{child.name}}"
     [(ngModel)]="child.selected"
     (ionChange)="onChildSelection(parent.name, child.name, child.selected)">
</ion-toggle>
 In the above example the id of the component is being set to include the name of the parent and child.  The state is based on the child.selected state which in this case is a boolean value.

We need A.I. powered traffic signals

How often have you been at a stoplight waiting for it to turn green and there is no one else on the road?  It is 3am and every soul for fifty miles is sleeping except for you and the local police and there you are waiting for the light to change.  This waiting shouldn’t be happening.

We should have traffic signals that utilize multiple sensors to see what traffic is currently at the lights as well as the traffic coming down the road from a farther distance.  If the traffic lights for a local area are all connected then they can communicate with each other to pass along details about the number of vehicles, speed of travel, and size of the vehicles to the lights nearby.  With this information traffic should be able to flow more efficiently by timing the lights so that lanes with more vehicles will have longer green light times.  And when a signal senses that there are no other vehicles on the road except for the single person waiting to turn left at 3am it will turn all other lights red except for that person.

The technology is here.  By using thermal, video, LIDAR, and many other types of sensors the signals can get a good understanding of the road.  May signals are already wired up to communicate with each other so that they stay in sync so there shouldn’t be a need to lay down new wires for the communication.  If anyone knows of research already being performed in this area let me know.

Show the New Years resolution that you’re serious

It is three weeks into the new year and how many of us are still being loyal to our resolution?  Hopefully whatever was picked for this year is obtainable and not something like winning the PowerBall.  Each year I tend to pick a personality trait and something health related as my goal for the year.  Usually it is something generic enough that by the end of the year I have no real idea on if the goal was actually accomplished.  This would leave me not feeling too bad about the goal at the end of the year but I also felt that I really hadn’t changed.  So last year I decided to try something different.

I’ve never really enjoyed salads but knew I needed to start eating healthy.  There was no way I could just dive in and start eating a salad everyday so I made it simple.  Each week I would eat one salad.  If I missed a week then I would double up another week to make it up.  To add another level to it I teamed up with a coworker who decided to give up smoking.  I made a deal to myself that as long as he kept to his goal I had to keep to mine, no matter what.  There really is no tie in between our goals but I knew that if I add another person to the mix then I will have a better chance at keeping my goal.

2015 has come and gone and I have had at least 52 salads and my coworker didn’t smoke once last year.  Now that we’re in 2016 I’ve upped the ante and now have to eat two salads a week.  Nothing exciting, but with any luck I’ll not only get myself to enjoy salads but will also get to the point where I don’t need goals to keep me eating healthy.  It will just become a habit.

Earlier this month HBR IdeaCast had a podcast covering ways to keep your goals.  I suggest listening to it, at 20 minutes in length it isn’t going to take up much of your time.  Check it out at HBR IdeaCast, Achieve Your Goals (Finally).  Some of the advice they gave were to keep the goal were to be specific about what you want to accomplish, be flexible, try replacing a bad behavior with a good one, and be prepared for temptation.  Putting these strategies together should help you to keep your resolution this year and end the year on a success.

Hello world!

I’ve owned the bnolan.org domain for a number of years.  Initially the website was used as a development site where I could try out different Javascript and PHP technologies.  This remained true until after college and life became consumed with work and family.  Now that a more predictable rhythm has developed I am hoping to bring this site back to life with posts about technology, politics, and life.  My hope is to break down some of the more complex technologies being discussed these days into easier terms so that even readers who don’t have a passion for the field can understand what is going on around them.

With that said I’ll hopefully have my first real post up in the next two weeks.