Posts

Clean up your LINQ with Load Expressions

Often times in an application, you will need data from across several tables. One approach to get all this data at once is to use the LINQ .Include() function, which will pull in all the data of the specified parent or child table. However, this can often be too heavy, as you may not need every column so you end up pulling more data from the database than is required. When this is the case, the best practice is to use a Data Transfer Object or DTO which is one flat object that combines properties from parents and children. Below, I demonstrate a simple use of a DTO, using . Include() var products = Uow.Context.Products.Include(x => x.ParentTable).Include(x => x.ChildTable).ToList(); var dtoList = new List<ProductDto>(); foreach ( var product in products) { var dto = new ProductDto{ // Copy over properties ... // Copy over parent properties ... // Copy over child properties ... }; dtoList.Add(dto); } As I mentioned before, this i...

Scheduling Tasks With Azure Scheduler

Image
In many applications it is necessary to send email notifications on a schedule. There are many ways to achieve this functionality: using a Windows service,  Windows Task Scheduler, or a number of other third party solutions. In our case, we don't have much control over our web server and so we decided against a Windows service. We ended up going with Azure Scheduler which provides a reliable way to hit a network endpoint on a user defined schedule. While not a free solution in most cases, the cost is low for the majority of small applications. Here's how to set up Azure Scheduler: Open the Azure portal and open the Scheduler Job Collections blade. This can be accessed by searching for scheduler in the top search bar in the Azure portal. Click Add in the top left corner. Name the job. The name can only have alphanumeric characters, hyphens, and underscores. Select or create a new job collection.  If creating a new job collection, select your...

Git good with Git

There will come a time in every developers life where they will have to learn how to use more than one version control software. Here are some steps to set up a Git repository. STEP 1  - Download the latest version of  Git here . STEP 2  - Open your terminal on your local machine. STEP 3  - You will need to tell Git who you are so that all your commits are labeled properly git config --global user.name "YOUR NAME HERE" And your email address: git config --global user.email "YOUR EMAIL ADDRESS HERE"   STEP 4  - Initiate your local repo: cd <directory you want to use git on> git init Finally you can clone your repo: git clone ssh://milo@example.com/path/to/my-project.git cd my-project STEP 5  - Get to work! The code won't write itself!

Software Versioning and You

It's hard to image that after developing for so long that there was a time that I didn't use any type of software versioning software. Yes, you heard me right, there was a time that I would simply edit some code and upload it to a live environment without a way to track any changes. Versioning software like Subversion allows you to keep track of changes to your code in case. Below you will find steps to set up a svn (Subversion) repository on a host machine and locally. STEP 1  -    Insure your host machine has svn install. Just log into the machine and punch in: which svn Your output should look something like this: :~$ which svn /usr/bin/svn If your some reason you don't have svn installed on your host,  here  is where you can get started. STEP 2  -  Now that you have svn installed on your host you can create a repository. Here is the command for that: svnadmin create (PATH TO YOU REPO HERE eg. /users/svnuser/myrepo) STEP 3  ...

HighCharts Tech Tip

Image
So you have a website with tons of data but don’t have a visualization solution. HighCharts is a purely JavaScript based chart solution that may be the answer to your searching. It is compatible with all modern browsers. If you need a solution for school or your non-profit organization HighCharts is free to use. It offers line, spline, area, area spline, column, bar, pie, scatter, angular gauges, area range, area spline range, column range and polar chart types. Many of which can also be combined. It allows for multiple axes, tooltip point labels, export and print, and zooming. HighChart can have data supplied statically or dynamically through ajax. The GSA Carbon Footprint tool uses the Highcharts library to visualize carbon emissions data.  The General Services Administration (GSA) developed the GSA Carbon Footprint Tool to help Federal Agencies calculate, report, and reduce their greenhouse gas (GHG) emissions as specified under Executive Order (EO) 13514.  https://www.car...

Create your own Short URLs

URLs for deeply nested pages can be difficult to read and even harder to remember, especially for new visitors to a website. When giving a presentation or participating in a technical conference, website owners tend to put shortened URLs on their slides so that the audience can write down the link on a piece of paper or navigate on their phone. Many URL shortening sites have caught on and you can find many examples with a quick search. But, these URLs are most often a string of random characters that do not have much meaning. What if we wanted them to be more memorable? Creating Your own Short URLs Lets say you have the following URL which is for a page that has information about the event at which you are presenting. www.mywebsite.com/events/northamerica/2017/july/exampleconference    As you can see from the structure of the URL, the page for this conference is nested within some hierarchy that is related to the organization of the site. Yet, this URL may be difficult...

Smart Relative date formatting in C# using extension methods.

The C# DateTime object has some nice .ToString() overloads for formatting dates but sometimes we would like a friendly, relative format like what you see in many Android or iPhone apps. The idea is to only include year, month, and day when they are not the current one. Examples are as follows... Just now         55 seconds ago 1 min ago 15 mins ago 1 hour ago 13 hours ago Sunday, 25th at 12:53 PM              -  different day, same month Tuesday, May 2nd at 12:53 PM     -  difference month, same year May 2nd, 2016 at 12:53 PM          - different year I like this format because it's flexible enough to give you a nice relative format that scales well with dates far in the past. To implement, I used an extension method. Since I am using ordinals for the days, I used another extension that I found in a Stack Overflow post . The Humanizr library accomplishes ordinals very well...