Jon's Programming Blog

HTML Traits

Introduction

Imagine you want to add multiple interactive behaviors to a single HTML element—maybe an auto-expanding textarea that also validates character limits. With traditional web components, you’d end up with nested wrapper elements cluttering your markup, or you’d be limited to Safari’s refusal to support built-in web components.

What if you could simply write <textarea traits="elastic character-limit"> and be done?

HTML Traits is a lightweight JavaScript library that makes this possible. It adds multiple behaviors to existing HTML elements through a simple traits attribute, giving you clean, composable functionality without the wrapper element overhead.

Progressive Enhancement

The idea behind progressive enhancement is that you start with a web page which doesn’t require any JavaScript, and for that matter, CSS, and you enhance the page depending on what the browser allows on the user’s device. This allows older devices to continue to use the web and saves on people’s resources as they no longer need to update their devices in order to keep up with the modern web.

Retrieving Multiple JSON Arrays into Single SQL Table

Now that SQL Server is working better with JSON it is becoming easier to just put plain JSON into columns. It’s nice to be able to query the JSON directly in the database. The other day I was wanted to get a list of values in arrays. Here’s how I did it.

First let’s set up the table:

DECLARE @JSON TABLE
( JsonID INT PRIMARY KEY IDENTITY(1, 1)
, JsonData nvarchar(max) NOT NULL
);

Some test data:

INSERT INTO @JSON (JsonData)
VALUES
    (N'{"json":[{"name": 1},{"name": 2}]}'),
    (N'{"json":[{"name": 3},{"name": 4}]}'),
    (N'{"json":[{"name": 4},{"name": 5}]}');

To get the arrays we need to use a JSON_QUERY function which let’s us get at inner JSON.

Over 5 Years of F#

Originally when I was planning on doing a post for the F# Advent Calendar I was thinking I would do one on a tool I’m building for C# in F# that mimicks some of the functionality of the fantastic library FSharp.Data.SqlClient. But then I was thinking, “I’ve been messing around with F# for a while and have done some production work with it; why not share some of the experiences that I have had with F#?”

Desert Code Camp 2017

Desert Code Camp 2017 was yesterday. I was slated to give four presentations yesterday. I ended up giving three.

Three of them were on F#. I did Introduction to F# in the morning and had two more ready to go in the evening. But by that time everyone in the morning had already gone home, I’m guessing, and so the evening attendees probably would have enjoyed hearing Introduction to F# again!

Database Programming Yin Yang

There are two different ways people like to write their SQL scripts when calling the database. One way is to write the SQL statements in their application code. Sometimes they will write an ORM to make this process similar to their language constructs. Sometimes they will write the SQL code directly in procedures.

Pros and Cons of Developing in the Application

  • Pros

    • Low friction between application and database.
      • Any refactoring in your application is simple since all your code is accessed in the same location.
    • Need to know only single language (back end language)
  • Cons

An Introduction to Functional Programming in JavaScript

This is the talk I gave at the JavaScript meetup in Phoenix. One the othe largest programming meetups in the valley.

Here are the slides to the talk.

Here’s some books that can help you get ramped up into the functional programming paradigm Introducing functional programming with Underscore.js by Michael Fogus. And for a more in depth look into functional patterns Professor Frisby’s Mostly Adequate Guide to Functional Programming.

The Power of Static Typing

From what I understand static typing makes programmers more productive and gives implicit documentation to the code base

  • although explicit documentation is also very helpful. It also seems to make the tools we use much more powerful.

One of the problems of static typing is that your code becomes more verbose. With programming languages like F# the compiler will implicitly type as much of your program as possible. Where it fails, you need to type it yourself.

Authentication and Authorization in ASP.NET Core

One thing that really got me frustrated in WebAPI 2.0 was creating custom authentication. Eventually I found a blog post by Rick Strahl that showed how to roll your own authentication/authorization. I wanted to implement a login (Basic Authentication) with username/password that would return a token for later (Bearer Authorization) use. It was quite simple but really frustrating because there wasn’t a whole lot of documentation on the subject.

Now I want to do something similar for ASP.NET Core. But there wasn’t any documentation on that either. For ASP.NET Core I wanted to implement an OAuth 2.0 with a custom provider. But there isn’t any documentation on the subject. I’ve struggling to find a solution to it I ran across a couple of Stack Overflow.

F# with Web API and Railway-Oriented Programming

I presented at the 2016 Desert Code Camp. The topic was WebAPI with F#. I also did a video series to go along with the talk. The talk and video series basically goes over how to use F# in a functional manner by building out all the pieces from scratch.

Here’s the series, hope you enjoy it!

F# WebAPI From Start to Finish.

Some set up steps and notes that are important to the success of the project:

  1