Skip to content

Instantly share code, notes, and snippets.

Travis Parks jehugaleahsa

View GitHub Profile
View join.cs
public static string Join<TItem>(IEnumerable<TItem> items, string separator = ", ", string end = " and ")
var builder = new StringBuilder();
using (var enumerator = items.GetEnumerator())
if (enumerator.MoveNext())
var item = enumerator.Current;
if (enumerator.MoveNext())
jehugaleahsa / rpn.hs
Created Mar 3, 2018
Reverse Polish Notation
View rpn.hs
calculate :: [String] -> Maybe Double
calculate [] = Nothing
calculate a = calculateHelper a []
calculateHelper [] [a] = Just a
calculateHelper ("+":items) (x:y:rest) = calculateHelper items ((y+x):rest)
calculateHelper ("-":items) (x:y:rest) = calculateHelper items ((y-x):rest)
calculateHelper ("*":items) (x:y:rest) = calculateHelper items ((y*x):rest)
calculateHelper ("/":items) (x:y:rest) = calculateHelper items ((y/x):rest)
calculateHelper (a:items) rest = case (readMaybe a :: Maybe Double) of
jehugaleahsa /
Last active Sep 26, 2018
Encoding the future

Encoding math

I have been spending the last month reading Euler's Elements of Algebra. It's an interesting way of teaching and learning algebra because it's broken out into small paragraphs that introduce algebraic rules one at a time and tries to relate them to each other in some logical sequence. It's a little odd some times, though, because right after learning about logarithms, you go back to subtraction.

One strange thing I learned about myself in college is that I am much better at math involving variables than I am numbers. I've always been slow adding 5 + 6 or taking 8 * 9. Most people by the time they're out of 3rd grade can't even help but recite the answers. Not me - I still have to think about it everytime. I find it strange, then, that I am much more comfortable reducing expressions like 3x^2 + 9x + 12. In fact I get a kick out of it! Euler's book is geared much more toward people who like my kind of math.


jehugaleahsa /
Last active May 29, 2020
Consume SignalR Using Angular 2+

Consume SignalR Using Angular 2+

The beautiful thing about the web was that this article is outdated before I even started writing it. I am going to show how I was able to encapsulate SignalR functionality behind a simple service that works nicely in an Angular 2+ environment. I find myself frequently ruminating about the fact that Angular 2+ is more of an "environment" than a framework. It's not just a handful of libraries strewn together - it literally drives your development process - pretty much forcing you to introduce Node.js, TypeScript and a build tool (eg., Webpack) into your daily activities. It also strongly reinforces how you organize your files and what you name them. It's so painfully opinionated and I love it!


If you are working on an Angular 2+ application and you don't have a lot of services, you are doing something woefully wrong. One of the biggest parts of getting your head wrapped around Angular 2+ is familiarizing yourself with their new approach to dependency injection an

jehugaleahsa /
Last active Sep 26, 2018
Good model design

Good model design

If you implement modern applications, you are probably familiar with the concept of view models and API models. Just to be clear, these are dumb classes normally made up of simple getters and setters (aka., properties) useful for passing data around. When working with REST services, these classes are usually serialized to JSON. You usually don't want them to have a whole lot of functionality since it won't get serialized. Instead, these are denormalized objects that save the UI or other clients from performing business logic.

About 5 years ago, I was working on a project where I had to quickly define a new set of models for the REST API. On a previous project, I had run into a lot of problems with deeply nested models - in other words, models containing other models. On this new project, I let that bad experience influence my decision making. To not nest my models, I flattened everything into one giant, denormalized model. The team immediately ran into issues, though, because we would hav


A lot of cool things have happened in the last year or so that really get me excited. We got to see .NET core reach all new platforms; TypeScript has quickly become my favorite language; we saw Angular 2+, React, Webpack and other awesome tools bring the web into the next generation. Five years ago, I wasn't a big fan of web development -- it seemed way too chaotic for my tastes. It took some time, but now I love that chaos! It doesn't bother me that my node_modules folder contains over 22K files.

I would be extremely happy if I spent 100% of my time programming in TypeScript by 2020. I have some wild dreams about what would enable that possibility. One possibility is I switch to using Node.js for all of my backend coding, foresaking more than 10 years of C# experience and the awesome power ASP.NET Core promises. I take the .NET framework for granted -- I know -- I worked in Python for 4 months and was constantly annoyed how disconnected all the libraries felt. The JavaScript community sees a lot more chur

jehugaleahsa / loc.ps1
Created Aug 18, 2017
A simple PowerShell script to count the lines of code in a solution
View loc.ps1
$path = "C:\path\to\solution\folder"
$files = Get-ChildItem -Path $path -Include *.cs,*.ts,*.vb -Recurse `
| ? { $_.FullName -notmatch ".*\\obj\\.*" } `
| ? { $_.FullName -notmatch ".*\\node_modules\.*" }
$shortNames = $files | % {
$fullName = $_.FullName
$lines = [System.IO.File]::ReadAllLines($fullName)
$lines = $lines | ? { -not [System.String]::IsNullOrWhiteSpace($_) }
jehugaleahsa /
Last active Jun 4, 2019
Razor and TypeScript

Once more around the bend

We're just going in circles...

If you have been a web developer for a while, you probably feel like you're going in circles. Going all the way back to CGI scripts, you were generating HTML using string literals, formatting and concatenation:

const message = "Hello, World!!!"
console.log("<html><body>" + message + "</body></html>");

Then someone decided it would be easier to inline code into HTML documents directly, using a more declarative approach:

jehugaleahsa /
Created Jun 23, 2017
Angular 2- Nested Model-Driven Forms

Angular 2 - Supporting Nested Model-Driven Forms

Introduction - It worked in AngularJS

If you build real business applications, then you know most of your development effort goes into forms. AngularJS struck me right away as an amazing improvement over the previous generation of HTML libraries, simply because model binding was really well done. Integrating binding with validation made it a first-class web framework.

Business applications of any moderate complexity often have reusable user controls and AngularJS directives were great for that purpose. AngularJS had this amazing feature, whereby placing an ng-form inside of another ng-form the state of the child form was automatically reflected in the parent! You could build up directives with their own validation completely independent of what page they belonged to. Simply by dropping them on your page, all of your validation was auto-wired up. Brilliant!

It doesn't work in Angular2

It is a little surprising, then, that Angular2 did not follow in

View tree.ps1
# let rows: 10
# let lines = from row in 0..rows
# let spaceCount = rows - row
# let spaces = " " * spaceCount
# let stars = "*" * (2 * row + 1)
# let line = spaces + stars + spaces
# select line
# lines.join("\r\n")
You can’t perform that action at this time.