<![CDATA[Tech Talk DC]]>https://techtalkdc.com/https://techtalkdc.com/favicon.pngTech Talk DChttps://techtalkdc.com/Ghost 1.26Sun, 29 Jun 2025 21:59:40 GMT60<![CDATA[Router-First Architecture in SPAs]]>https://techtalkdc.com/router-first-architecture-in-spas/5b2ba59d73aee0000101b69bThu, 21 Jun 2018 16:00:00 GMTRouter-First Architecture in SPAs

Router-First Architecture in SPAs

Developing any software is a challenge in today's Agile environment with ever shifting requirements. Today's web is rapidly raising the bar on user expectations on how a good application should work and the pressure on front-end developers to delivering great user experiences (UX) is higher than ever. Especially in Single Page Applications (SPAs) using Angular, React, Vue or any other framework, architecting your solution to support this type of rapid change and potential growth is often an after thought. You can overcome these challenges by using router-first architecture. Let's first dig into what the challenges are.

SPA Challenges

There are two main challenges in developing your apps. First is defining your requirements and the second is the architecture.

Requirements

This is notoriously difficult to do, however even in Agile software development, you must remember that you can't take your first step without a roadmap in place. So, how can we ensure that we have a concrete representation of a roadmap that is not open to wide interpretation like user stories or requirements documents can be?

  • Build a sitemap
  • Define different types of users that can log in to your system
  • Mockup rough drafts of all the views you can
  • Develop a walking skeleton of your application
  • As a bonus, insert the rough mockups in to your in progress app

Doing these things will scope out the entire UX you intend to build. It will be your roadmap. It will help tease early feedback from stakeholders and if you have multiple developers on your team, they can work in parallel, just filling in the blanks without stepping on eachtother's toes.

Architecture

A walking skeleton of your application is a great start, but application archictecture is so much more than just having the right routing structure. The pieces of software you develop should be flexible and performant. However, it is possible to be overly-flexible and ovelry-optimized for the task at hand. This can waste a considerable amount of your budget and rob you users of valuable features or improvements. So, how can you hope to accomplish this?

  • Leverage lazy-loading with modular development from the get go
  • Achieve a stateless, data-driven design
  • Enforce a decoupled component architecture
  • Create reusable user controls
  • Leverage ES6/TypeScript features to reuse code

These are high-level recommendations and dive deep into them for Angular, TypeScript and RxJS, in my recently published book, Angular 6 for Enterprise-Ready Web Applications.

Router-First Principles

In summary, a router-first architecture follows these principles:

  1. Develop a roadmap and scope
  2. Design with lazy loading in mind
  3. Implement a walking-skeleton navigation experience
  4. Achieve a stateless, data-driven design
  5. Enforce a decoupled component architecture
  6. Differentiate between user controls and components
  7. Maximize code reuse with ES6/TypeScript

I will be talking about this topic more in meetups and conferences later this year, like on October 10-12 at Angular Mix in Orlando, FL.

Router-First Architecture in SPAs

Hoping to see you there! In the mean time, you can get my book for a discount until June 24th, 2018.

15% off Print + eBook: AERWA15
50% off eBook: AERWA50

Buy in Print or eBook Today!

]]>
<![CDATA[Check out Doguhan's latest blogs]]>

Until further notice, I'll be blogging on the Excella Blog.

I generally write about Agile Engineering, GitHub, JavaScript, Angular, Node, MongoDB, TypeScript and Docker.

To read my latest blogs, click here.

]]>
https://techtalkdc.com/check-out-my-latest-blogs/5ad6917b59dadd000181384aFri, 07 Apr 2017 16:34:56 GMT

Until further notice, I'll be blogging on the Excella Blog.

I generally write about Agile Engineering, GitHub, JavaScript, Angular, Node, MongoDB, TypeScript and Docker.

To read my latest blogs, click here.

]]>
<![CDATA[Minimal MEAN]]>It can be daunting to pick the right stack to deliver your idea to the cloud. Without realizing, you can introduce one too many "sandbag of complexity" between you and something you can release. For the first time ever it is possible to do full-stack development with a

]]>
https://techtalkdc.com/minimal-mean/5ad6917b59dadd0001813849Sat, 30 Apr 2016 14:30:49 GMTIt can be daunting to pick the right stack to deliver your idea to the cloud. Without realizing, you can introduce one too many "sandbag of complexity" between you and something you can release. For the first time ever it is possible to do full-stack development with a consistent set of tools and best practices using the same language, JavaScript. No more to context switching between front-end and back-end languages, libraries and tools. That is The JavaScript Promise. My easy to learn and use stack 'Minimal MEAN' will get you started and deployed on the cloud over a lazy weekend, without requiring a MongoDB install, while leveraging the latest tools like async/await with Typescript, ng2, Node v6.

In April 2016, I gave a talk on Minimal MEAN at NOVA Code Camp 2016 and posted the code on Excella Labs. You may find my presentation slides below.

]]>
<![CDATA[You Can't Be the Master of Everything]]>Brian Conn gave a great talk at Tech Talk DC on Front-end development for full-stack developers.

Brian highlighted the pressures on full-stack developers to keep up with fast moving front-end libraries, tools and practices and highlighted the focus on integrating software vs creating software.

Brian has concrete suggestions to stay

]]>
https://techtalkdc.com/you-cant-be-the-master-of-everything/5ad6917b59dadd0001813848Thu, 21 Apr 2016 13:26:30 GMTBrian Conn gave a great talk at Tech Talk DC on Front-end development for full-stack developers.

Brian highlighted the pressures on full-stack developers to keep up with fast moving front-end libraries, tools and practices and highlighted the focus on integrating software vs creating software.

Brian has concrete suggestions to stay afloat as a full-stack developer. Some of the highlights includes:

  • Evaluate, re-evaluate but don't expand core tool stack
  • Climb the bandwagon on new/cool tech very carefully
  • Use a small number of mature frameworks
  • Get yourself out of the CSS game
  • Practice good front-end hygiene

Overall, Brian, highlighted the importance of figuring out your strengths and weaknesses and accepting the reality that you can't be the master of everything.

You can download his slides right here.

]]>
<![CDATA[Best Scalable Cloud Architecture: AWS Lambda]]>On March 23rd, Justin Winthers, gave a presentation on AWS Lambda at the Tech Talk DC Meetup. After Justin's excellent presentation, I came away convinced that AWS Lambda is nothing short of revolutionary.

Justin talked about how he leveraged AWS Lambda to build Hoozip, a real-estate app for investors. He

]]>
https://techtalkdc.com/best-scalable-cloud-architecture-aws-lambda/5ad6917b59dadd0001813847Fri, 25 Mar 2016 14:55:17 GMTOn March 23rd, Justin Winthers, gave a presentation on AWS Lambda at the Tech Talk DC Meetup. After Justin's excellent presentation, I came away convinced that AWS Lambda is nothing short of revolutionary.

Justin talked about how he leveraged AWS Lambda to build Hoozip, a real-estate app for investors. He also gave an example on how Zillow was able execute 16 million requests on Lambda a month for a bill of $6 dollars. Yes, you read that correctly, six dollars.

Check out his presentation slides right here and feel free to ask questions in the comments below.

]]>
<![CDATA[WordPress vs Ghost]]>

Tech Talk DC has migrated to Ghost. There were several factors behind this decision. While WordPress is feature-rich and has great community provided plug-ins, it is also unnecessarily complex and is slow.

Bloat and Lock-in

By moving Tech Talk DC to Ghost, I'll be losing some functionality, such as live

]]>
https://techtalkdc.com/wordpress-to-ghost/5ad6917b59dadd00018137f9Sat, 19 Mar 2016 15:00:00 GMTWordPress vs Ghost

Tech Talk DC has migrated to Ghost. There were several factors behind this decision. While WordPress is feature-rich and has great community provided plug-ins, it is also unnecessarily complex and is slow.

Bloat and Lock-in

By moving Tech Talk DC to Ghost, I'll be losing some functionality, such as live blogging, Meetup.com integration or various plug-ins that have been used in some of the blog posts to render them nicely. These plug-ins pile on over time, they create ugly dependencies, but most importantly every plug-in added slows everything else down by a little.

I'll be bringing Disqus back and fix display issues in specific posts over time. However, the fact that I must edit old posts highlights one of the reasons for moving, vendor lock-in. Ghost posts are pure markdown, so they're portable to any current or future blogging platform.

Cost

Hosting WordPress is expensive. I've been using Blue Host at a cost of $155 a year to host Tech Talk DC. Even though I pay for the high cost, because of the aforementioned bloat the blog runs very slowly. I can host Ghost on any server that can run Node.js and it is super fast. This is important because of all the mobile users out there.

I've chosen Digital Ocean as my hosting platform. For $60 a year I can run an Ubuntu server that can not only serve my Ghost blog, but also some of my other websites like The JavaScript Promise and not break a sweat.

How to Migrate

There are many migration strategies as there are stars in the sky. I'll document what worked for me.

  1. Install the Ghost plug-in to your WordPress site.
  2. Under Tools menu, select Export to Ghost
  3. Follow the instructions diligently :)
  4. Export images to Cloudinary
  5. Set-up Ghost on your local machine
  • Note: This requires familiarity with Node.js, if you're not a developer, you can purchase hosting from Ghost directly.
  1. Import content using sqlite3
  • Note: I've tried PostgreSql as well, but importing content never really worked with it. I went to great lengths to try different strategies like exporting SQL scripts out of sqlite and importing them into postgre. I even manually sliced and diced the import json file and tried the import that way manually fixing errors, but it never really fully worked against a postgre target.
  1. Push your code to GitHub or BitBucket
  2. Set up a Digital Ocean droplet
  • Note: Here I wanted to go fancy and leverage Docker. There's an official Ghost docker image. There's one based on Alpine linux with a tiny footprint. My initial idea was that I can isolate all my different sites as containers on my droplet. Initially I chose CoreOS as my OS, because it has a small footprint and pre-configured to host Docker containers. I failed. There were too many cryptic errors that was taking forever to overcome. Instead I went with an Ubuntu Node image. I intentionally didn't pick the Ubuntu Ghost image to avoid dealing with configuration I didn't understand. I ssh'ed into the server, used git to load my code, struggled with Ghost's config.js until I found the magical combination.
  1. Start up your Node app(s) using nodemon, do the port/DNS song and dance and hook things up with your domain name
  • Note: If you want to setup multiple domains and multiple sites, in addition to ensuring your Node.js applications starting back up along side your server, check out this blog.
  1. Configure Mailgun

tl;dr

Configuring Ghost on your own is not for the faint of heart. Expect a lot of banging of head to wall. But if you can overcome the issues, you'll end up with a simple, fast blogging, nay hosting platform of your own to host many Node.js apps in a $5 a month droplet.

]]>
<![CDATA[Why Should A Developer Care About Company Politics?]]>My good friend Sarav Bhatia recently wrote an article on the importance of company politics in relation to the careers of technical people. It is a great read.

If we care about our day to day happiness and the quality of our experiences at our jobs and the places we

]]>
https://techtalkdc.com/why-should-a-developer-care-about-company-politics/5ad6917b59dadd0001813846Tue, 29 Sep 2015 09:03:00 GMTMy good friend Sarav Bhatia recently wrote an article on the importance of company politics in relation to the careers of technical people. It is a great read.

If we care about our day to day happiness and the quality of our experiences at our jobs and the places we live in, politics is an unavoidable tool we must learn to utilize effectively. If you want a great job, chances are you already have that job, you just need to be willing to navigate the political structure of your company to mold your current job into the job you want to keep.

However, if you want to remain disinterested in the politics of your organization or what to “stay out of it”, than you should accept the fact that you’re just a passenger on a boat going somewhere and you really don’t know where that place is.

Check out Sarav’s article here.

]]>
<![CDATA[4 things to consider before creating your Ansible Playbook]]>I recently started automating my build using Ansible for a new project.  I heard great things about Ansible from colleagues who helped me get started and decided to take notes along the way. Here are a few items from the notes that you should consider before getting started.  

#1: The

]]>
https://techtalkdc.com/4-things-to-consider-before-creating-your-ansible-playbook/5ad6917b59dadd0001813845Tue, 25 Aug 2015 10:21:00 GMTI recently started automating my build using Ansible for a new project.  I heard great things about Ansible from colleagues who helped me get started and decided to take notes along the way. Here are a few items from the notes that you should consider before getting started.  

#1: The plays have been created. You only have to put these together

Chances are most of the roles you want to create have been implemented before. Take a look here to find existing roles and use them in your playbook. If you absolutely have to write your own roles, use these as references to guide you. Moreover, there are many existing open-source playbooks for common automated builds that can be found with a quick google search. Here is an example of a common Django build playbook that I was able to reference. Remember to make your playbook, roles, etc open-source if you write your own custom automation.

#2: Know the difference between the Shell and Command modules

Shell executes a task on the remote node using a shell which means it has access to basic shell operations and variable like $HOME, $PATH, &&, etc. Command module executes the specified command with arguments on all selected nodes and is not processed through the shell therefore cannot access shell operations and variables. Here is a example that highlights how one shell task can be used in place of two command tasks.

``` #Example Command 1 - name: Run a script in /usr/bin/ command: /usr/bin/test_script.sh

Example Command 2

  • name: Remove test_script.sh in /usr/bin/
    command: rm /usr/bin/test_script.sh

Example Shell

  • name: Run a script in /usr/bin/ and remove test_script.sh
    shell: test_script.sh ; rm test_script.sh
    chdir: /usr/bin/

 

</div><span class="s1">**#3: Avoid using the Shell and Command modules**</span>

<span class="s1">Ansible has a huge index of core modules that get installed by default. These modules make it easier to achieve simple tasks without the need to write shell scripts or commands. The list of modules can be found [here](http://docs.ansible.com/list_of_all_modules.html). Modules like pip, git, s3 (AWS), copy, yum and service make it easier to write and read Ansible playbooks. </span>

Here is a simple example that migrates a database managed my Django.

<div>```
#Run Django database migration using django-manage module
- name: Run migration
  django_manage:
    app_path=/path/to/manage.py/
    command=migrate
    virtualenv=testenv
  sudo: no

#Run Django database migration using shell
- name: Run migration
  shell: "source /testenv/bin/activate && cd /path/to/manage.py/ && python manage.py migrate"
  sudo: no

As you can see, the built in django_manage module makes it tremendously easier and simpler to run a django specific command. On the other hand, the shell module is very complex in terms of readability and comprehension.

#4: KISS And DRY

I am a big proponent of the KISS (Keep it Simple Stupid!) and DRY (Don’t Repeat Yourself) software development principles. Split up you roles into individual standalone entities that can be used elsewhere. Moreover, this makes it easier for others to follow your playbook and customize as necessary. For example, create two distinct roles for database installation and database setup so that others can use the database install role but not the database specific setup role. A good rule of thumb is to split up a role when it becomes hard to maintain and read.

Conclusion

Ansible is a very simple and direct automation tool with a large contributing user community. They have focused on building a tool that relies heavily on contributors to make modules, roles and playbooks in an open environment. I highly recommend trying out Ansible as your next automation tool and become a part of the growing community.

]]>
<![CDATA[A First Look at Installing ASP.NET 5, Part 3: Ubuntu Linux]]>

This is the final part of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

Overall I found getting ASP.NET 5 to  run on Ubuntu to be quicker and easier than doing so for OS X. It might not have been easier than

]]>
https://techtalkdc.com/a-first-look-at-installing-asp-net-5-part-3-ubuntu-linux/5ad6917b59dadd0001813844Fri, 26 Jun 2015 17:00:05 GMT

This is the final part of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

Overall I found getting ASP.NET 5 to  run on Ubuntu to be quicker and easier than doing so for OS X. It might not have been easier than Installing Visual Studio 2015 RC on Windows given that it involved a lot more typing as opposed to just clicking a couple of “Download” and “Install” buttons, but it was certainly a lot faster.

I set up a fresh Ubuntu 14.04 VM in Parallels on my Macbook Pro and then followed the instructions at http://docs.asp.net/en/latest/getting-started/installing-on-linux.html and https://github.com/aspnet/Home.

Here’s what you need to do:

  1. Install mono: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list sudo apt-get update sudo apt-get install mono-complete
  2. Install libuv: sudo apt-get install automake libtool curl curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src cd /usr/local/src/libuv-1.4.2 sudo sh autogen.sh sudo ./configure sudo make sudo make install sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/ sudo ldconfig
  3. Install the DNVM: curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
  4. Add NuGet sources. Edit ~/.config/NuGet/NuGet.config  with the following content (Note: I had to create this file and add the contents manually – I’m not sure if installing DNVM should have done it for me or not.):
  5. Get the latest DNX version: dnvm upgrade
  6. Install Git if it’s not already installed: sudo apt-get install git
  7. Clone the repo with their sample code: git clone https://github.com/aspnet/Home
  8. Go to the directory containing the sample app you want to try out (I used home/samples/1.0.0-beta4/HelloMvc)
  9. Load dependencies: dnu restore
  10. Start Kestrel: dnx . kestrel
  11. Check http://localhost:5004 in your browser

And lo and behold! I was doing something I never in my wildest dreams imagined would be possible: running an ASP.NET web site on an Ubuntu Linux box.  

Screen Shot 2015-06-09 at 3.51.00 PM

VS Code also seems to work just fine on Ubuntu.  

[![Screen Shot 2015-06-09 at 3.57.39 PM](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_450,w_660/v1455493668/Screen-Shot-2015-06-09-at-3.57.39-PM_mscfgp.png?resize=660%2C450)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493668/Screen-Shot-2015-06-09-at-3.57.39-PM_mscfgp.png)
You’ll never use Sublime Text again.
You’ll note that in the steps above, I pulled Microsoft’s samples from  [https://github.com/aspnet/Home](https://github.com/aspnet/Home) instead of using Yeoman to scaffold a project.

While trying to install Yeoman, I encountered a number of errors and decided to skip ahead and see if I could get it working with one of their existing solutions first. Once I had done that, I did a little more research and discovered it’s a little different than for OS X.

I followed these instructions and although I got some warnings about my node and npm versions being out of date (they aren’t).

I also had to install bower and grunt: sudo npm install -g bower

It worked after that. I ran sudo npm install -g yo generator-aspnet  and then after that the command yo aspnet  worked, allowing me to scaffold out a new solution as described under OS X above.

Overall Impressions

Overall I have to say I was pleasantly surprised. I was expecting a lot more headaches trying to get up and running on a Mac or Linux box than I actually encountered, and as the product matures I’m sure the few errors I did run into will be resolved. Running from a command line in Windows didn’t seem to be a problem either.

Ironically, the most annoying installation was Visual Studio 2015 RC. It was a pretty glaring contrast between installing an enormous IDE and a number of much smaller command line installations. On the other hand – Visual Studio may have taken a long time (and hung at the end) but it was a single download and install – far less typing required and fewer steps where you could screw up.

I’ve only begun to play with VS Code, but I like what I see so far. For developers who’d rather use a Mac or a Linux box, it gives them a nice, lightweight IDE as an alternative to Visual Studio that will let them get up and running fast.

One enormous caveat to all of this is, of course, that ASP.NET 5 is still a work in progress and is not stable.  I’m sure some of you poor readers will try to follow the steps in one of these blog posts and discover all sorts of fun new errors and breaking changes. In that case, by all means leave a comment and let other readers know what you see and if you were able to resolve it. If it’s a new issue that hasn’t been reported yet, reporting it is as an issue in the appropriate Github repo is a great idea as well.

Still, I’m impressed with what Microsoft has come up with so far and I’m excited to see where they go from here.

]]>
<![CDATA[A First Look at Installing ASP.NET 5, Part 2: OS X]]>This is part 2 of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

Having tested ASP.NET 5 via Visual Studio and a command line on Windows in our last post, it was time to give it a try on OS X. I

]]>
https://techtalkdc.com/a-first-look-at-installing-asp-net-5-part-2-os-x/5ad6917b59dadd0001813843Fri, 26 Jun 2015 01:33:00 GMTThis is part 2 of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

Having tested ASP.NET 5 via Visual Studio and a command line on Windows in our last post, it was time to give it a try on OS X. I used my trusty Macbook Pro running OS X Yosemite v 10.0.3.

Since I have heavily abused my Mac, after going through the installation process I spun up an OS X VM with Parallels so I could repeat it on a clean system just in case my existing configuration somehow affected the process. I only noticed a couple of minor differences which I’ll make a note of below.

To install and run ASP.NET 5 on OS X, I followed the instructions at:   http://docs.asp.net/en/latest/getting-started/installing-on-mac.html

I already had X Code and its command line utilities, Homebrew, and Node JS and NPM installed on my Mac. I went ahead and installed the latest versions of all of these tools on my OS X VM as well.

From the terminal:

  1. brew tap aspnet/dnx  (no errors)
  2. brew install dnvm  (no errors)
  3. source dnvm.sh  (no errors)
  4. dnvm upgrade  (get the latest version – no errors)

Note: add source dnvm.sh  to ~/.bash_profile, ~/.bashrc or ~/.zshrc to avoid having to run ‘ source dnvm.sh’ again.

Screen Shot 2015-06-05 at 1.47.10 PM

If DNVM is correctly installed, you should see something like this when you enter dnvm  in the terminal:

Screen Shot 2015-06-05 at 1.50.01 PM

Next, I followed the steps in Microsoft’s “Your First ASP.NET 5 Application on a Mac” tutorial to set up my basic “Hello World” style solution.

First, I confirmed I had beta 4 version of DNX by running dnvm list  :

[![Screen Shot 2015-06-09 at 12.45.10 PM](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_173,w_660/v1455493684/Screen-Shot-2015-06-09-at-12.45.10-PM_zp3wys.png?resize=660%2C173)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493684/Screen-Shot-2015-06-09-at-12.45.10-PM_zp3wys.png)
1.0.0-beta4 is the current-somewhat-stable release as of this post
At this point, I diverged from the Microsoft tutorial. They provide sample ASP.NET apps you can clone and try out   but if you want to build your own ASP.NET from scratch it seems you’re kind of out of luck without visual studio.

In the tutorial, they have some placeholder text that says “Coming soon: instructions for getting started with Yeoman.” Then they tell you to clone and try out some of their sample apps at https://github.com/aspnet/home. Intrigued, I read up on Yeoman and decided to give it a try.

On their website, Yeoman is described as follows:

Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive.

To do so, we provide a generator ecosystem. A generator is basically a plugin that can be run with the yo command to scaffold complete projects or useful parts.

To install Yeoman, you’ll need to install Nodejs and NPM first.

Next, install Yeoman and their asp.net generator:  npm install -g yo generator-aspnet

When I tried this command on my Mac, I received a series of errors: 

Screen Shot 2015-06-05 at 2.07.59 PM

Trying it again with sudo resolved the problem: sudo npm install -g yo generator-aspnet

Screen Shot 2015-06-05 at 2.08.19 PM

SIDEBAR: When I repeated this step on my OS X VM, I was able to run npm install -g yo generator-aspnet  without using sudo . I assume this means when you log into an OS X VM on Parallels you have root access. I’m not sure how this works so if someone is more familiar with this topic please feel free to leave a comment.

Once Yeoman was installed, I used it to scaffold out an ASP.NET 5 app with the ridiculously simple yo aspnet .

This brings up Yeoman’s asp.net generator, a command line tool that provides a list of project templates to choose from. I selected web application.

[![Screen Shot 2015-06-05 at 2.16.12 PM](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_417,w_660/v1455493680/Screen-Shot-2015-06-05-at-2.16.12-PM_wyfiku.png?resize=660%2C417)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493680/Screen-Shot-2015-06-05-at-2.16.12-PM_wyfiku.png)
Fun Fact: The terminal command ‘yo’ is worth less money than the app Yo, despite being far more useful.
Next I gave my app a name when prompted and hit enter to create the scaffolding, then watched as it created all the necessary files:

Screen Shot 2015-06-05 at 2.23.23 PM

A quick glance in Finder confirmed the new project files were all there, as expected.

Screen Shot 2015-06-05 at 2.26.34 PM

It’s beyond the scope of this post, but for future reference Yeoman’s asp generator provides command line options to add new components, such as models, controllers, etc.

Although originally designed for *nix systems, Yeoman now supports Windows as well, so if you want to use a command line on a Windows box to scaffold new ASP.NET apps you can do so. See here and here for more.

Next, I downloaded and installed Visual Studio Code. I noted that in contrast to the massive full version of Visual Studio, VS code was only a measly 64.7 MB download.

Installing VS Code was as simple as unzipping the downloaded file and dragged the VS Code icon to the applications folder. I then opened VS code and marveled at it’s minimalist interface – so far so good.

I opened the project folder I’d just built with Yeoman and got a message about missing dependencies with a prompt to restore:

Screen Shot 2015-06-18 at 9.51.57 AM

Hitting the ‘Restore’ button next to the message automatically downloaded and tried to install all dependencies from Terminal (as if I’d run dnu restore ).

Screen Shot 2015-06-18 at 9.53.57 AM

But I got some more errors and again the suggestion I try as root: 

Screen Shot 2015-06-18 at 9.54.08 AM

So I tried running sudo dnu restore  from terminal myself and got some more errors: 

System.ComponentModel.Win32Exception: ApplicationName='bower', CommandLine='install', CurrentDirectory='/Users/brianpalladino/Projects/MacAspNet5App', Native error= Cannot find the specified file    at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in :0     at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in :0     at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in :0     at Microsoft.Framework.PackageManager.ScriptExecutor.Execute (Microsoft.Framework.Runtime.Project project, System.String scriptName, System.Func2 getVariable) [0x00000] in <filename unknown>:0     at Microsoft.Framework.PackageManager.RestoreCommand+<RestoreForProject>d__74.MoveNext () [0x00000] in <filename unknown>:0   --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0     at System.Runtime.CompilerServices.TaskAwaiter1[System.Boolean].GetResult () [0x00000] in :0     at Microsoft.Framework.PackageManager.RestoreCommand+<>c__DisplayClass73_0+<b__0>d.MoveNext () [0x00000] in :0   --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0     at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in :0     at Microsoft.Framework.PackageManager.RestoreCommand+d__73.MoveNext () [0x00000] in :0   ----------  Restore failed  ApplicationName='bower', CommandLine='install', CurrentDirectory='/Users/brianpalladino/Projects/MacAspNet5App', Native error= Cannot find the specified file

Fortunately, the omniscient demi-God Stack Overflow provided a resolution:

sudo npm install -g bower  sudo npm install -g grunt-cli

I ran these commands and then ran ‘ dnu restore ‘ again. That worked – no more errors!

[![All hails Stack Overflow!](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_212,w_660/v1455493671/Screen-Shot-2015-06-18-at-9.54.45-AM_ay6k3p.png?resize=660%2C211)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493671/Screen-Shot-2015-06-18-at-9.54.45-AM_ay6k3p.png)
All hail Stack Overflow!
Then I tried dnx .kestrel to start the server, but got some more errors:

Missing method .ctor in assembly /Users/brianpalladino/.dnx/packages/Microsoft.AspNet.Cryptography.Internal/1.0.0-beta4/lib/dnx451/Microsoft.AspNet.Cryptography.Internal.dll, type System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute  Can't find custom attr constructor image: /Users/brianpalladino/.dnx/packages/Microsoft.AspNet.Cryptography.Internal/1.0.0-beta4/lib/dnx451/Microsoft.AspNet.Cryptography.Internal.dll mtoken: 0x0a000004  * Assertion at class.c:5607, condition `!mono_loader_get_last_error ()' not met

Turns out I needed to upgrade the version of mono on my Mac. I read this post and tried brew unlink mono  (to unlink v 3, the version I had installed) then brew install mono  to get v 4.

I then ran dnu restore  again, just in case changing the version of mono might affect any project dependencies. I didn’t know if this was necessary but I figured it wouldn’t hurt anything.

THEN, I ran dnx . kestrel  again and it started!

Screen Shot 2015-06-18 at 9.58.15 AM

At this point, the nice tutorial I found on the internet told me I should be able to view the app in my browser at http://localhost:5001/. As usual, the internet lied to me. I got the following exception when I tried to go to http://localhost:5001/:

IOException: kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.  System.IO.KqueueMonitor.Add (System.String path, Boolean postEvents, System.Collections.Generic.List1& fds) [0x00000] in <filename unknown>  System.IO.KqueueMonitor.Scan (System.String path, Boolean postEvents, System.Collections.Generic.List1& fds) [0x00000] in   System.IO.KqueueMonitor.Setup () [0x00000] in   System.IO.KqueueMonitor.DoMonitor () [0x00000] in   … and it goes on and on like that … do people really read these horrible things? ...

Another quick search on this error found this handy post. Solution:

  1. Stop kestrel (by hitting the Enter key)
  2. Run export MONO_MANAGED_WATCHER=false
  3. Restart kestrel with dnx . kestrel
[![Screen Shot 2015-06-09 at 2.05.31 PM](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_528,w_660/v1455493669/Screen-Shot-2015-06-09-at-2.05.31-PM_po8sro.png?resize=660%2C529)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493669/Screen-Shot-2015-06-09-at-2.05.31-PM_po8sro.png)
Trying to justify my salary with Hello World apps.
After this I refreshed my browser and… VOILA!

After completing the steps above, I repeated the process on my Parallels OS X VM.

The second time around it all went very smoothly as I could implement the fixes for the various errors I got right from the start.

OS X Installation Process Summarized

Here is the entire process summarized after taking errors into account. You may need to use sudo on a few of these commands depending on whether or not you’re using a VM.

  1. Before starting: Install X-code, command line tools, and Homebrew
  2. Install DNVM: brew tap aspnet/dnx brew install dnvm source dnvm.sh export MONO_MANAGED_WATCHER=false dnvm upgrade

3. To save yourself some typing and aggravation later, add source dnvm.sh  to ~/.bash_profile, ~/.bashrc or ~/.zshrc and add export MONO_MANAGED_WATCHER=false  to  ~/.bashrc
4. Confirm you have the 1.0.0-beta4 version of DNX: dnvm list
5. Install NodeJs and npm: brew install node
6. Install Yeoman & Asp.Net Generator: npm install -g yo generator-aspnet  
7. Install Bower and Grunt: npm install -g bower grunt-cli 
8. Scaffold an ASP.NET 5 app with Yeoman: yo aspnet 
9. Go to the project directory and update project references: dnu restore
10. Start kestrel: dnx . kestrel 
11. View the new web site in your brower: http://localhost:5001/
12. To view or change the source code, download and install VS Code, open the newly created project in VS Code and verify there are no errors or missing references, then code away.

There! That wasn’t so bad was it? Now that we’ve conquered OS X, in our next post we’ll try this out on Ubuntu.

]]>
<![CDATA[A First Look at Installing ASP.NET 5, Part 1: Windows]]>This is part 1 of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

By now, .NET developers who don’t live in caves are aware that the newest version of ASP.NET, in addition to being open source and in general very different

]]>
https://techtalkdc.com/a-first-look-at-command-line-asp-net-5-part-1-windows/5ad6917b59dadd0001813842Fri, 19 Jun 2015 12:28:00 GMTThis is part 1 of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

By now, .NET developers who don’t live in caves are aware that the newest version of ASP.NET, in addition to being open source and in general very different from previous iterations, is designed to run on multiple platforms, allowing us to finally start coding in C# on Macs and Linux machines. They are courageously helping us “blow out some Windows” so to speak. 

There are already a number of tutorials and resources online for how get started with ASP.NET 5 on a Mac or a Linux box, but since the framework is still under development and is constantly changing, I thought it would be useful to go through the process, see if I ran into any issues not highlighted in Microsoft’s current tutorials and “Getting Started” resources, and generally get a feel for how difficult it would be.

I find that most developers (myself included) spend far more time than they think they will installing and configuring new frameworks, tools, and environments than they think they will going in the door. It shouldn’t take three days to get that shiny new “lightweight” ORM all the cool kids are using working properly in your environment, but then somehow it does.

My goal here was to see just how difficult getting up and running with ASP.NET 5 on my Mac and on a Linux box would be. How many errors would I run into? What forgotten step or missing environment variable would make me lose three hours of my life trying to figure out what was wrong? What cryptic error message would I see that doesn’t show up in a Google search?  How bad would the stress headaches be? Would I be vomiting up blood 16 hours into fixing a bad install?

With Visual Studio Code they have also developed a lightweight, cross platform IDE that I decided to try out as well.

Finally, I noted that Microsoft is now offering an option to run ASP.NET 5 apps via command line in Windows, without having to install Visual Studio, so I decided to give that a go as well. Windows command prompt, Mac OS X and Ubuntu terminals… That’s a lot of keyboard action. Hence the title of this post.

Although I did encounter several issues, overall I was pleasantly surprised. The process was much smoother than I expected.

Before continuing, you should understand a few basic terms specific to the new .NET:

  • DNX: .Net Execution Environment (the new .NET runtime basically)
  • DNVM: .Net Version Manager (select and manage DNX versions)
  • DNU: DNX Utility (package management tool for .Net apps)

For more detail, see Microsoft’s DNX  overview.

Caveat: ASP.NET 5 is still under development and constantly changing at the time of this post. If you try to reproduce the steps I used it is entirely possible you may see different behavior or errors. Keep that in mind.

Now, with all of that out of the way, let’s see how it all went.

My Environment

My experiment was conducted on a Macbook Pro running OS X Yosemite  – v 10.0.3. I used Parallels to create the different VMs I used to test the process.

I set up a Windows 8.1 VM so I could install ASP.NET 5 via Visual Studio the old fashioned way as a control scenario before playing with OS X and Ubuntu. I had a Windows 7 VM I’d already been using and did the command line install for Windows sans Visual Studio on that machine.

Since I have heavily abused my trusty Mac, after going through the installation process I spun up an OS X VM so I could repeat it on a clean system, without having to worry if my existing configuration somehow affected the process. I only noticed a couple of minor differences which I’ll make a note of.

Finally, I created an Ubuntu 14.04 VM to try it out on Linux.

Getting Started on Windows with Visual Studio: The Control Scenario

Before diving into uncharted waters I decided to try out ASP.NET 5 in a familiar environment.

Following Microsoft’s instructions, I tried out ASP.NET 5 on Windows by downloading and installing Visual Studio 2015 RC (Enterprise Edition) on a Windows 8.1 VM.

The download and installation took a while, seemed to be almost done and finally hung at “Configuring your system. This might take a while.” The message didn’t lie. It did take while. I waited over an hour before I finally gave up.

[![Hung VS Install - Screen Shot 2015-06-04 at 8.10.08 PM](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_833,w_660/v1455493697/Hung-VS-Install-Screen-Shot-2015-06-04-at-8.10.08-PM_sfijza.png?resize=660%2C833)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493697/Hung-VS-Install-Screen-Shot-2015-06-04-at-8.10.08-PM_sfijza.png)
How long will it take to configure my system Microsoft? HOW LONG?!?!
Since I like to live dangerously, I decided to take a chance and hope the installation had really finished and that it would still work if I pulled the plug. I tried to cancel the installation (at least, that’s what I assumed the ‘Cancel’ button was for) but it didn’t actually do so – it just kept right on going.

Then I killed it in task manager and tried to open VS 2015 from the start menu, but I got an error that I couldn’t open it since setup was still running – even though I had just killed it in task manager and no process appeared.

Ah, this was the good old Microsoft we’ve all come to know and love.

At this point I defaulted to the old rule of thumb: when in doubt, reboot. So I restarted the VM. Much to my surprise, after Windows rebooted the Visual Studio installation suddenly resumed and this time it actually completed. I was, like ‘woah’.

Once it completed I was able to open VS 2015 from the start menu and started the “Your First ASP.NET 5 Application Using Visual Studio” walk through.

When creating new project, I did spot a small bug – note the Asian characters at the bottom right in the following screen shot. Not being knowledgeable in Asian alphabets I don’t know what language this was, so if you know and would like to leave a comment, please enlighten me.

New Project asian chars - Screen Shot 2015-06-04 at 8.40.10 PM

[![Reading English is already hard enough for me Microsoft.](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_145,w_300/v1455493665/Screen-Shot-2015-06-05-at-1.00.45-PM_zfg5kv.png?resize=300%2C145)](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493665/Screen-Shot-2015-06-05-at-1.00.45-PM_zfg5kv.png)
Reading English is already hard enough for me Microsoft.
Other than that, the rest of the walk through went smoothly and I didn’t have any problems. I was able to get a bare bones “Hello World” type ASP.NET 5 Web app up and running.

I did note two things that might surprise another n00b like myself:

  • One of the coolest new features in ASP.NET 5 is the ability to make code changes and have them immediately show up on refreshing the browser but without rebuilding the whole application. This didn’t seem to work for me at first – then I went back and reread the instructions and also checked Stack Overflow and realized you had to run the app WITHOUT debugging to use this feature.
  • I noticed that if you make a change to project.json, the new and improved framework immediately tries to execute a ‘dnu restore’ command and update project dependencies on the fly. Something to be aware of.

Aside from a sluggish installation and a label from the wrong language appearing on the screen, I didn’t have any other problems doing it the old fashioned way. Visual Studio and its installation process isn’t that different, so if you’re sticking with Windows and Visual Studio “Getting Started” with ASP.NET won’t be too different from previous versions up to this point.

With the control scenario out of the way, I moved on to the main event.

Getting Started on Windows With a Command Line

Microsoft’s Installing ASP.NET 5 on Windows walkthrough also included instructions for doing so without Visual Studio. I decided to give it a try before moving on to OS X and Ubuntu. Run ASP.NET without Visual Studio? “Impossible!” I shouted out loud. After my coworkers stopped staring at me I gave it a shot and confirmed that it is, in fact possible.

As instructed, I opened a command prompt as Admin and ran the following command to download and install the DNVM:<br></br>

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"

No errors – so far so good.

[![Screen Shot 2015-06-10 at 3.42.59 PM](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_328,w_660/v1455493694/Screen-Shot-2015-06-10-at-3.42.59-PM_jn8tjl.png?resize=660%2C328)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493694/Screen-Shot-2015-06-10-at-3.42.59-PM_jn8tjl.png)
Oh Command Prompt, I wish I knew how to quit you.
Next I opened a new command prompt and verified DNVM was working by typing dnvm `.`

I saw the expected result indicating DNVM was installed, but also got an interesting error:

[![Red is usually bad.](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/h_383,w_660/v1455493694/Screen-Shot-2015-06-10-at-3.50.12-PM_zfx4sy.png?resize=660%2C383)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493694/Screen-Shot-2015-06-10-at-3.50.12-PM_zfx4sy.png)
Red is usually bad.
I Googled the error but didn’t find anything relevant, so I decided to try to keep going and see what happened.

The next step was to install the DNX by running dnvm upgrade and I got another error.Screen Shot 2015-06-10 at 4.02.34 PM

I then tried dnx to see if DNX was installed in spite of this error, and it seemed that it was:Screen Shot 2015-06-10 at 4.08.17 PM

Then I cloned the source from https://github.com/aspnet/home so I could try running one of their sample apps. (NOTE: I used the sample apps in the 1.0.0-beta4 folder since I suspect those in the ‘latest’ folder are more likely to be unstable.)

I switched into the HelloMvc sample app directory and ran dnu restore
which seemed to run successfully.

I then ran dnx . kestrel  and it looks like it worked – it started, but only after a nice security warning from Windows popped up:

Once I allowed access I was able to view the site in my browser at http://localhost:5004/

Screen Shot 2015-06-10 at 4.27.33 PM

QAPLA’! Now I had a Hello-World ASP.NET site running without ever touching Visual Studio.

The errors I got installing the DNX do not seem to have been fatal. A cursory Google search didn’t reveal much. I took a quick look at the code, but I’m not sure what the problem is. The affected block of code in the ‘dnvm’ powershell script appears to be intended to spit out a list of DNVM commands.

The next day I tried it again and while I still get the first error when running dnvm from a command prompt, I no longer get the second error when running  dnvm upgrade.

Hmmm. These errors don’t seem to have an effect, but one never likes to see strange errors on a new product.

Here’s a step by step summary of the process described above:

  1. Open a command prompt as administrator
  2. Download and install DNVM: @powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
  3. Confirm DNVM is installed: dnvm
  4. Install latest version of DNX: dnvm upgrade
  5. Get Microsoft’s sample ASP.NET code: git clone https://github.com/aspnet/home
  6. CD to the source folder of whichever sample app you want to run and load dependencies: dnu restore
  7. Start Kestrel: dnx . kestrel
  8. View the site in your browser at http://localhost:5004/

I noticed there didn’t seem to be a way to scaffold out a new solution in any of Microsoft’s docs. So that confused me a bit. Later, I learned about Yeoman, but we’ll get to that shortly.

Now that we’re all suitably impressed that we can run ASP.NET via command line in Windows, in our next post we’ll move on to OS X. Subcribe to TechTalkDC.com for updates and follow @techtalkdc. Stay tuned.

]]>
<![CDATA[Python Technical Guide: An Introduction to PDB]]>Any software developer knows that good code doesn’t get written right the first time, and when unexpected behavior occurs eyeballing the code or even using print statements can end up falling short. This year at PyCon, I had the pleasure of attending a talk by Clayton Parker about an

]]>
https://techtalkdc.com/an-introduction-to-pdb/5ad6917b59dadd0001813841Fri, 05 Jun 2015 15:06:00 GMTAny software developer knows that good code doesn’t get written right the first time, and when unexpected behavior occurs eyeballing the code or even using print statements can end up falling short. This year at PyCon, I had the pleasure of attending a talk by Clayton Parker about an extensively useful Python module affectionately called pdb.

The official Python documents define pdb as “an interactive source code debugger for Python programs.” Those programmers that use IDE’s like Eclipse or PyCharm will probably be familiar with the concept of an interactive debugger as they come with one baked in. This article will assume that you are not using one of these debuggers. Now, let’s look at an example of its use.

import pdb message = "The circumference of the circle is " pdb.set_trace() pi = 3.1415 r = 5 def calculate circumference(pi, radius): return 2pir print message + (calculate circumference(pi, r))

Let’s take a look at what we’ve got here. It’s a simple program that prints out the circumference of a circle with a radius of 5. At the top we’ve imported the pdb module and on line 4 we’ve added the line pdb.set_trace() , which is what’s called a breakpoint for the code to stop at on execution. Now, let’s go ahead and run this program with python circle.py . Here’s what we get:

/Users/kurt/ExcellaDevelop/python/circle.py(5)() -> pi = 3.1415 (Pdb)

The debugger has stopped the execution of the program and is showing the next line after the breakpoint. It is important to note that the line that pdb shows has not been executed yet. So, what if instead you’re debugging a massive file and you forget where you are in the code? There’s a command for that! Enter the command l  or list . That will list out 11 lines of code and an arrow on the line that the debugger is stopped on.

(Pdb) l 1 import pdb 2 3 message = "The circumference of the circle is " 4 pdb.set_trace() 5 -> pi = 3.1415 6 r = 5 7 8 9 def calculate_circumference(pi, radius): 10 return 2pir 11

Now that we know where we are in the program, we can try printing out some values using the command p  or print . You can enter the command, p pi  or p pi, r  to get the value(s) of the variables. If we try to print out a variable that has not yet been instantiated then we’ll get a NameError, as seen below. Now, let’s traverse through the program with the n  or next  command.

(Pdb) n > /Users/kurt/Excella/Develop/python/circle.py(6)() -> r = 5 (Pdb) p pi, r *** NameError: NameError("name 'r' is not defined",) (Pdb) p pi 3.1415

Great, just as expected. It executed line 5 and is now showing line 6, but it hasn’t executed line 6 yet. That’s demonstrated by trying to print out r  before it’s declared. If we decided that we only wanted to execute the program up to this point, we could just use the q  or quit  command to exit the program. However, this is a bit dirty and you could also use c  or continue  to execute the rest of the program to completion (or the next breakpoint).

But we’re not done yet. Let’s move on to the next line. What if we want to test out to code as if the variable r  had a different value? The debugger will let you do that! Let’s set r = 8 .

(Pdb) n > /Users/kurt/Excella/Develop/python/circle.py(6)() -> r = 5 (Pdb) n > /Users/kurt/Excella/Develop/python/circle.py(9)() -> def calculate_circumference(pi, radius): (Pdb) r = 8 > /Users/kurt/Excellanevelop/python/circle.py(12)() -> print message + str(calculate_circumference(pi, r))

What happened? It accepted the input r  and executed a built-in command called return, which resumes execution until the function returns. The way around this is to put a !  before, so now the command is !r = 8 .

/Users/kurt/Excella/Develop/python/circle.py(9)() -> def calculate_circumference(pi, radius): (Pdb) !r = 8 (Pdb)

That’s more like it. The last command that we’ll discuss is the s  or step  command. If we run next  again we’ll skip the function definition because it’s not part of the current execution and get to the last line. This calls the function calculate_circumference()  and returns the circumference. When this line is next in execution step  will “step into” the function call.

(Pdb) s --Call-- > /Users/kurt/Excella/Develop/python/circle.py(9)calculate_circumference() -> def calculate_circumference(pi, radius): (Pdb) n > /Users/kurt/Excella/Develop/python/circle.py(10)calculate_circumference() -> return 2pir (Pdb) --Return-- > /Users/kurt/Excella/Develop/python/circle.py(10)calculate_circumference()->50.264 -> return 2pir (Pdb) The circumference of the circle is 50.264 --Return-- > /Users/kurt/Excella/Develop/python/circle.py(12)()->None -> print message + str(calculate_circumference(pi, r))

That’s all we’ll cover now, but that’s sure not the whole of it. There is still plenty to learn and experiment with pdb. I urge you to use pdb for your debugging needs in python if you’re not already doing so, and keep doing it if you are!

There’s a python package called ipdb that adds syntax highlighting and completion. I highly suggest that you check it out if you have a chance.

]]>
<![CDATA[To ORM or Not To ORM]]>ORM or Object Relational Mapping give developers easy access to the database by connecting objects to database tables. ORMs are easy to use and set up, but can cause performance problems for complex queries. Here are a few tips on when to use the ORM and when not to:

To

]]>
https://techtalkdc.com/to-orm-or-not-to-orm/5ad6917b59dadd0001813840Sat, 30 May 2015 10:00:00 GMTORM or Object Relational Mapping give developers easy access to the database by connecting objects to database tables. ORMs are easy to use and set up, but can cause performance problems for complex queries. Here are a few tips on when to use the ORM and when not to:

To ORM

ORMs should be used when querying database models since they enable you to query the database directly from your code. As a result, you do not have to write extra SQL code in your applications. ORMs make the code base cleaner, easier to maintain and highly readable by centralizing the data models. This makes it easier for other developers to understand and add value to the code base. Therefore, you should use an ORM if your priority is to build lean applications.

Not To ORM

ORMs should not be used when there is a need to specify exactly what SQL runs on the database. For example, ORMs should not be used in data migrations because they permanently change the state of the database. Furthermore, database migrations done via the ORM that update data will update ALL of the data. Therefore you should know exactly what SQL code is executed during database migrations. ORMs should not be used for simple sql scripts that don’t need to be maintained or run more than once. ORMs can also lead to performance issues for complex SQL queries if not configured properly.

In conclusion, ORMs are very powerful and can make your lives better when used properly. ORMs allow you to start developing lean applications quickly and easily. In most cases, you should use an ORM when querying database models instead of writing those queries in SQL. However, queries that change the state of the database like migrations or one-off scripts should not be done via an ORM. Remember, with great power comes great responsibility so be careful or get tangled in the webs.

]]>
<![CDATA[Three of the Most Common Mistakes Made when Using Elasticsearch]]>In addition to being a top choice for enterprise search, Elasticsearch is also growing in popularity as an all-purpose datastore.  It’s easy to scale, it’s extremely fast, and it can be accessed via a RESTful API.  Because the documentation can be difficult to maneuver, there are a number

]]>
https://techtalkdc.com/three-of-the-most-common-mistakes-made-when-using-elasticsearch/5ad6917b59dadd000181383eTue, 05 May 2015 21:15:00 GMTIn addition to being a top choice for enterprise search, Elasticsearch is also growing in popularity as an all-purpose datastore.  It’s easy to scale, it’s extremely fast, and it can be accessed via a RESTful API.  Because the documentation can be difficult to maneuver, there are a number of traps that new Elasticsearch users often fall prey to.  Here are some of the most common mistakes I’ve noticed while working with Elasticsearch at CFPB, with some additional tidbits learned at PyCon 2015 in Montreal:

Not explicitly defining a mapping

Elasticsearch claims to be a “schema-free” data store.  Lo and behold, you can fire up an Elasticsearch cluster, create an index, and feed it a JSON document without even thinking about schemas.  I find calling it “schema-free” to be a little misleading, however.

What’s actually happening behind the scenes is Elasticsearch is going through each field of the JSON document you indexed, making its best guess at which type each field is, and creating a schema for you (a “mapping” in the Elasticsearch world).  For example, if it encounters “2014-05-15”, it will add a “date” entry to the mapping for the field.  Likewise, 15.5 would be a float, and 2500 would be an integer.

So if Elasticsearch makes a mapping for you, what’s the problem?  Well, Elasticsearch isn’t always right.  There are certain situations where the wrong type is picked, and next thing you know you’re getting indexing errors!

How to fix?  Always explicitly define mappings, ESPECIALLY in any production-like environment.  The best practice here is to index a few documents, letting Elasticsearch guess the types for you.  Next go grab your mapping: GET /index-name/doc_type/_mapping
Next, make any changes you see fit.  Don’t leave anything up to chance!

Setting store = yes for one or more fields

By default, the full document you index in Elasticsearch is stored in a field called _source.  When you run a query on a certain field, for example, Elasticsearch has  no problem going into _source and querying on that particular field.

It’s also possible to store individual fields separately by setting store = yes in the mapping for a field.  Keep in mind, everything is already stored in the _source field.  Some people think this will speed things up, but in reality, this often causes multiple reads vs. the default single read of _source, slowing things down.  Unless you know exactly what you’re doing, resist using store = yes

Using queries when you should be using filters

This is easily the most common of the three mistakes.  New Elasticsearch users often use queries only.  Why are there both queries and filters, and what is the difference between the two?

**Queries **should be used when performing a full-text search, when scoring of results is required (think search results ranked by relevancy).

In almost all other cases, **filters **should be used.  Filters are much faster than queries, mainly because they don’t score the results.  If you just want to return all of the widgets that are blue, or that cost more than $10, use filters!

It’s also possible to do a filtered query.  So if you only need to perform a full-text search on a subsection of your data, filter it first, then run the query.  It will be much faster that way.

In conclusion: if you need a full text search server, or if you want to play around with a NoSQL datastore, I highly recommend giving Elasticsearch a try.  Just make sure to avoid these common pitfalls, and you’ll be way ahead of the pack.

]]>
<![CDATA[.NET Technical Guide: AutoFac]]>Introduction

What is AutoFac?

The principle of Dependency Inversion states that you should rely on abstractions instead of concretions. It leads to code that is more scalable, testable, and maintainable because it allows us to quickly and easily swap out implementations (examples of this concept are in the following sections)

]]>
https://techtalkdc.com/net-technical-guide-autofac/5ad6917b59dadd000181383dThu, 30 Apr 2015 11:00:36 GMTIntroduction

What is AutoFac?

The principle of Dependency Inversion states that you should rely on abstractions instead of concretions. It leads to code that is more scalable, testable, and maintainable because it allows us to quickly and easily swap out implementations (examples of this concept are in the following sections). While this can be manually implemented, dependency management tools like AutoFac will automate the process for you. This technical guide will demonstrate the principle of Dependency Inversion and it’s implementation using AutoFac to manage your dependencies.**** ****

Dependency Inversion

What is it and why does it matter?

What does it mean to rely upon abstractions instead of concretions? To put it simply, it means we should strive to use interfaces in place of the implementations of those interfaces. A more concrete example of what this looks like in a program is explored in a later section. The reference section can also provide more information.**** ****

Taking advantage of dependency inversion can provide several advantages in your code:

  • ****Testability:****Injecting implementations of classes at runtime allows us the flexibility to use either the intended production implementation or a mocked version of that class. This swapping makes writing effective and encompassing unit tests a breeze.
  • Separation of Concerns: Good programming practice dictates that independent logic should be isolated from unrelated functionality. Dependency inversion compliments this practice by forcing you to separate your unrelated logic into isolated classes.
  • Extensibility/Scalability: When you have the ability to swap out implementations very quickly, it allows you extend the functionality of your system. For example, it is very simple to swap out one implementation of a class for another implementation with higher performance.
  • ****Maintainability:****Dependency injection allows you to change implementations by changing a few lines instead of hunting down and manually swapping out multiple instances across your system.

One of the most commonly used methods of adhering to dependency inversion is called dependency injection. The key to dependency injection is to “inject” (meaning pass in a version of the class in question at runtime) the implementations of classes at runtime, which allows the code to be flexible in it’s implementations. To illustrate what dependency injection is, let’s explore a simple example.**** ****

Dependency Injection: A Simple Example

An illustration of why to use dependency injection

For our example we will create three main components: a driver class to run the console application, a status monitor class that is responsible for monitoring something, and a status writer for the status monitor to use to output the status. We will go through several iterations of code; first setting up the program, then introducing dependency injection, and finally adding AutoFac and leveraging it’s automated dependency handling.**** ****

FIrst, create a project in Visual Studio. I will be creating a C# Console Application for the purposes of simplicity. I named my main class Driver.cs and also created a helper class called StatusMonitor.cs, as seen in Figures A and B.

[![Figure A - Basic Driver class](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493664/Figure-A_f0t3zo.png?resize=497%2C274)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493664/Figure-A_f0t3zo.png)
Figure A – Basic Driver class
**** ****
[![Figure B - Empty StatusMonitor class](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493771/Figure-B-empty-statusMonitor_anbqjv.png?resize=261%2C163)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493771/Figure-B-empty-statusMonitor_anbqjv.png)
Figure B – Empty StatusMonitor class
The last class we need to write is the OldStatusWriter. The OldStatusWriter simply prints out a string to the console (indicating its “status”) via the WriteStatusToConsole method. OldStatusWriter uses the built-in object StreamWriter to do the actual work of printing to the console. The actual implementation of OldStreamWriter isn’t super important for this example, but the source code is included for reference (Figure C).**** ****

We will also need to implement StatusMonitor to use OldStatusWriter to print out a status. The implementation of this can be seen in Figure D.**** ****

[![Figure C - OldStatusWriter class](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493664/Figure-C_eo9i3q.png?resize=660%2C416)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493664/Figure-C_eo9i3q.png)
Figure C – OldStatusWriter class
**** ****
[![Figure D - StatusMonitor using OldStatusWriter](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493663/Figure-D_hk9pj3.png?resize=526%2C325)](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493663/Figure-D_hk9pj3.png)
Figure D – StatusMonitor using OldStatusWriter
When we run this console application, it will pop open the console, print out its status, and then wait for a key to be pressed before closing.**** ****

Now that we have a foundation, let’s remember the problem we had in the initial example: having to replace an implementation.**** ****

Before we dive into how AutoFac can handle this situation for us, let’s make our lives a little easier by laying the groundwork for using dependency injection. The first thing we’ll do is create an interface for OldStatusWriter: IStatusWriter**** ****

[![Figure E - IStatusWriter interface](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493770/Figure-E-IStatusWriter_xgkh6z.png?resize=294%2C113)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493770/Figure-E-IStatusWriter_xgkh6z.png)
Figure E – IStatusWriter interface
Now, instead of creating a new instance of OldStatusWriter within the StatusMonitor, let’s make it a parameter to the constructor. This will allow us the freedom to use any status writer that we want, as long as it implements the IStatusWriter interface.**** ****
[![Figure F - StatusMonitor with an interface argument](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493662/Figure-F_xsnusn.png?resize=541%2C325)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493662/Figure-F_xsnusn.png)
Figure F – StatusMonitor with an interface argument
Just as a sanity check, let’s re-run our program now that we’ve implemented the beginnings of dependency injection. It should still output the old status. Don’t forget to pass an instance of OldStatusWriter to the StatusMonitor in the Driver!**** ****
[![Figure G - Passing OldStatusWriter to StatusMonitor in the Driver](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493661/Figure-G_ypdzs4.png?resize=660%2C265)](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493661/Figure-G_ypdzs4.png)
Figure G – Passing OldStatusWriter to StatusMonitor in the Driver
So now that we have some infrastructure in place, let’s swap out our OldStatusWriter with the NewStatusWriter (Figure H). For the purposes of this example, the only real difference between the Old and New status writers will be the status that it outputs.**** ****

Because we have created IStatusWriter and passed an instance of it into the StatusMonitor, all we need to do is have NewStatusWriter implement the IStatusWriter interface. Then we can pass in a NewStatusWriter as a parameter when we create a new StatusMonitor in the Driver class (Figure I).**** ****

[![Figure H - NewStatusWriter class](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493769/Figure-H-NewStatusWriter_xbrzf6.png?resize=660%2C359)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493769/Figure-H-NewStatusWriter_xbrzf6.png)
Figure H – NewStatusWriter class
**** ****
[![Figure I - Driver with NewStatusWriter](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493660/Figure-I_scemjb.png?resize=660%2C256)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493660/Figure-I_scemjb.png)
Figure I – Driver with NewStatusWriter
If we run our program again, we see that it prints out a new status, indicating that it is now using the NewStatusWriter. With one simple change, we have now replaced all the instances of OldStatusWriter within project with NewStatusWriter.**** ****

We can register our interfaces and classes with AutoFac, and it will inject whatever implementation we designate for every instance of each interface. This registration code can even be pulled out into AutoFac Modules for better separation of interests. The following sections will cover AutoFac set up, registering classes and interfaces, and making Modules.**** ****

AutoFac

Introducing AutoFac to the example**** ****

Now we will introduce AutoFac to our project and set it up to handle all the dependency injection for us. The first thing to do is include the AutoFac package. Open up the package manager, select “Online”, search for AutoFac and install it.**** ****

[![Figure J - Package Manager with AutoFac](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493768/Figure-J-Package-Manager-with-AutoFac_dinsoa.png?resize=660%2C498)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493768/Figure-J-Package-Manager-with-AutoFac_dinsoa.png)
Figure J – Package Manager with AutoFac
First, we will register the OldStatusWriter with AutoFac. To register types with AutoFac, We must create a ContainerBuilder (called builder in the example code). For each type we want to register, we call builder.RegisterType().**** ****

The ContainerBuilder class is used to register all the Interfaces you wish to be controlled by AutoFac. By calling the ContainerBuilder’s “RegisterType()” method, you can tell AutoFac to register classes as instances of interfaces. When you register a class as an interface, AutoFac will then handle the injection of the actual class through the interface at runtime.**** ****

Once registered, how do you actually get the implementation of an interface to use in your code? There are two main ways of doing this. The first way is to let AutoFac inject the implementation into the constructor of the class using it. This method is the most common approach.**** ****

But what if you’re in a situation where you can’t simply inject an implementation into a constructor? In cases like that, you can use the Container we set up earlier to actually resolve the interface to it’s implementation. See Figure K: when we call “builder.Build()”, we are telling AutoFac that we are done registering and wish to start receiving implementations from the container. This is done by calling “container.Resolve()”. When resolved, the container searches its registered interfaces for one that matches the arguments (See Figure K, line 14) and injects whatever implementation is registered for that interface.**** ****

In the snippet below, we have registered the OldStatusWriter as an instance of the IStatusWriter interface. This tells AutoFac to inject a newly created instance of OldStatusWriter anywhere that the code is using IStatusWriter. When you run this code, it will report the status from the OldStatusWriter, as expected.**** ****

[![Figure K - Driver using AutoFac](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493660/Figure-K_cbtzjd.png?resize=660%2C304)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493660/Figure-K_cbtzjd.png)
Figure K – Driver using AutoFac
Now, let’s register our newer type, NewStatusWriter. We will register it in the Driver class directly after the OldStatusWriter, to demonstrate AutoFac’s ability to inject on the fly. We will then print out the status again (See Figure L).**** ****
[![Figure L - AutoFac Injection at runtime](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493659/Figure-L_okp2ji.png?resize=660%2C396)](http://i1.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493659/Figure-L_okp2ji.png)
Figure L – AutoFac Injection at runtime
When you run this iteration of our project, the console prints out both the old status and the new status. This happens because we first registered OldStatusWriter as IStatusWriter and printed it’s status, and then re-registers NewStatusWriter to IStatusWriter and printed it’s status. AutoFac knows which implementation to inject based on what implementation you register.**** ****

AutoFac allows us to inject whatever implementation of an interface that we want into the code at runtime. One powerful way to leverage this functionality is feature switching. Feature switching is a concept where you use different implementations of things in different environments.Thanks to AutoFac, feature switching is as simple as modifying the registration command. Let’s do a simple example.**** ****

Since we now have some duplication of code, let’s pull out the common code into a shared method.**** ****

[![Figure M - Driver with a common Register method](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493658/Figure-M_pd1sum.png?resize=660%2C482)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493658/Figure-M_pd1sum.png)
Figure M – Driver with a common Register method
As always, let’s test this again to make sure we don’t have any problems. Running the application should result in both status messages printing out to the console.**** ****

While we’re at it, why don’t we use AutoFac to manage our StatusMonitor as well? This is not necessary, but it is good practice because it enforces the concept of what kinds of classes we want to inject versus instantiate. There are three main types of classes in this sense:

  • ****Services:****A class that operates on more than one other class or depends on more than one other class. One way to tell if a class falls into this category is if you are instantiating other classes within it. For an example of what a service might look like, see the FAQ section.
  • Models: A model is a class that primarily contains properties. A model can have methods, but those methods only operate on members of that class. For an example of what a model might look like, see the FAQ section.
  • Helpers: A helper is a class that contains logic, but only performs that logic on data that is passed into the helper. Helpers are typically static classes. See the FAQ section for more examples of helper classes.**** ****

Services are usually the most numerous and are the only classes that are candidates for injection. Dependency injection is useful for swapping out implementations; it doesn’t make sense to swap out a model or helper who really only have one implementation of their functionality. For services, simply create an interface for any classes that are necessary dependencies and pass those interfaces into the dependent method as constructor arguments.**** ****

We will implement an IStatusMonitor interface and use that to inject the implementation in at runtime.**** ****

[![Figure N - IStatusMonitor interface](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493768/Figure-N-IStatusMonitor_ee36tf.png?resize=288%2C115)](http://i2.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493768/Figure-N-IStatusMonitor_ee36tf.png)
Figure N – IStatusMonitor interface
**** ****
[![Figure O - Driver with IStatusMonitor registered](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493657/Figure-O_odmifg.png?resize=660%2C531)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493657/Figure-O_odmifg.png)
Figure O – Driver with IStatusMonitor registered
Great! Now we have removed all of the places where we have created a new instance of a class (except for AutoFac classes, of course). This makes our code more maintainable and testable – maintainable because the injection allows us to easily swap out the implementation of components, and testable because we can write unit tests that inject mocked versions of dependencies that we can test against.**** ****

Let’s clean up our Main method a little bit by pulling out the StatusMonitor creation into its own method. We will use the same Container object that we used for setting up the StreamWriter.**** ****

[![Figure P - Driver using the Single Responsibility Principle](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493656/Figure-P_x3hk7g.png?resize=660%2C591)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493656/Figure-P_x3hk7g.png)
Figure P – Driver using the Single Responsibility Principle
Even though this is a very simple and small project, our Main method feels cluttered with all the AutoFac set up happening in it. This is where the concept of a Module shines. A module is an AutoFac construct that is used to handle all the AutoFac set up and keep that set up out of your code’s logic. The power of modules is they can be separated logically with the structure of your project. In this guide, we use one module for the entire project, but it makes sense to split your modules up by purpose. For example, it is common to have one module for every different part of your system. This could mean one module per project, one module per logical segment of code, or anything in between.**** ****

Create a new class called StatusWriterModule, and we will use it to set up our status writer implementation. For the purposes of this example, we will write one module that takes in a status writer type, so that we can injection either kind of status writer.**** ****

[![Figure Q - AutoFac Module](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493767/Figure-Q-AutoFac-Module_lufkyf.png?resize=581%2C324)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493767/Figure-Q-AutoFac-Module_lufkyf.png)
Figure Q – AutoFac Module
Notice how the StatusWriterModule implements the Module interface, which is built in to AutoFac. The Module interface requires the implementation of one method called Load. In our case, we use Load to inject one or the other type of stream writer that we have created.**** ****

Finally, let’s call the Load() method from the Driver class so we can take full advantage of AutoFac. In Figure R, you can see that we have significantly simplified our Driver code by calling the StatusWriterModule.**** ****

[![Figure R - Driver using AtuoFac Module](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493655/Figure-R_tnlhex.png?resize=660%2C474)](http://i0.wp.com/res.cloudinary.com/hjprwpt5l/image/upload/v1455493655/Figure-R_tnlhex.png)
Figure R – Driver using AtuoFac Module
We’ve taken a look at what dependency inversion and dependency injection are, and how they aid in having good code. We’ve also introduced AutoFac and shown how to use it within your code. To get more information, see the Reference section. If you have any questions, see the Contact section. Happy coding!**** ****

FAQ**** ****

Q: How do I include AutoFac with my project?
A: You can import the AutoFac package to your Visual Studio solution using the package manager console. See Figure I for more information.

Q: How to register an interface / inject it’s implementation
A: To register an interface and it’s associated implementation, you must first create a ContainerBuilder, and use it to register your interface and associated implementation.The code looks similar to the following:

builder.RegisterType(Interface)

See Figure K or L for more information.

Q: What might a service look like?
A: Spotting a service is usually as simple as spotting instantiations of new classes and seeing those classes used to perform encapsulated logic. An example of what a service might look like is provided below. Notice how several classes are instantiated (PaymentReceiver and PaymentLogger), and seem to be performing complex logic behind the scenes:

public class ProcessPaymentService { /* Constructor is here */ public bool ProcessPayment() { var paymentReceiver = new PaymentReceiver(); var paymentInformation = paymentReceiver.ReceivePayment(); var paymentLogger = new PaymentLogger(); var logSuccessful = paymentLogger.LogPayment(paymentInformation); return logSuccessful; } }

Q: What might a model look like?
A: Keep in mind that a model is primarily made up of properties and is usually used to carry information rather than perform logic. A model can have methods, but those methods only operate on the properties of the model itself. An example of a model for an individual might look like this:

public class Individual { public string FirstName { get; set; } public string LastName { get; set; } public string FullName { get { return string.Format("{0}{1}", FirstName, LastName); } } }

Q: What might a helper look like?
A: Typical helpers are things like string formatters and data type converters. The following code illustrates a date helper that takes in a date string in the MM/DD/YYYY format and converts it into a DateTime object:

public static DateConverterHelper() { public static DateTime ConvertStringToDateTime(string date) { // preform validation to check for MM/DD/YYYY format first return new DateTime(date); } }

Reference

More information on the SOLID programming principles can be found here:
http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)**** ****

More information on Dependency Injection can be found here: http://tutorials.jenkov.com/dependency-injection/dependency-injection-benefits.html**** ****

More information on AutoFac can be found here:
http://autofac.org/**** ****

]]>