Skip to content

Instantly share code, notes, and snippets.

Avatar

Travis Parks jehugaleahsa

View GitHub Profile
@jehugaleahsa
jehugaleahsa / join.ps1
Last active Oct 19, 2020
PowerShell Script to Split Large Files
View join.ps1
function join($path)
{
$files = Get-ChildItem -Path "$path.*.part" | Sort-Object -Property @{Expression={
$shortName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
$extension = [System.IO.Path]::GetExtension($shortName)
if ($extension -ne $null -and $extension -ne '')
{
$extension = $extension.Substring(1)
}
[System.Convert]::ToInt32($extension)
@jehugaleahsa
jehugaleahsa / LTT.md
Last active Oct 14, 2020
LINQ Tricks and Techniques
View LTT.md

Learn to Love LINQ

I've been using LINQ for years and I've come to deeply respect it as a technology. Unfortunately it has not been adopted by the .NET community as much as I would have expected. I honestly believe it is the single one feature that gives C# a competitive edge over many of the other general-purpose languages out there today. This document will go over some of the tricks I have learned to make the most of LINQ's powerful features. Hopefully you'll learn at least one trick along the way.

Query vs Method syntax

Yup, you can write your queries as a series of method calls or you can use the query syntax. Method syntax is fine when you're first starting out, but query syntax is more expressive in the long run. My experience has been that operations such as where, select, join, group by and order by should be expressed using query syntax and "reduce" operations should be done in method syntax. Unavoidably, you sometimes have to use method calls inside of your queries simply because th

@jehugaleahsa
jehugaleahsa / MAC.md
Created Jan 24, 2017
Modern Architecture Concepts
View MAC.md

Modern Architectural Concepts

Core Concepts

Dependency Injection

At the core of most modern software architecture is dependency injection. Rather than creating dependencies on-the-fly, all dependencies are injected into a class upon construction. This allows representations to be swapped out at runtime, making it easier to enable features based on a configuration file. This also enables the isolation of code, making it easier to test.

Dependency injection also puts a burden on the developer, making it clear when a class has too many dependencies and, therefore, responsibilities. This often acts as an early warning system that there is a design flaw. If taken seriously, DI can lead to smaller, more cohesive classes that are easier to test.

Below, you’ll find a section on dependency injection concepts that make modern architectures possible.

Onion Architecture

@jehugaleahsa
jehugaleahsa / ng-signalr.md
Last active Aug 30, 2020
Consume SignalR Using Angular 2+
View ng-signalr.md

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!

Services

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
jehugaleahsa / MEH.md
Last active Jul 10, 2020
Minimal Exception Handling
View MEH.md

Minimal Exception Handling

Introduction

With so many other aspects of daily development completely unattainable by your average developer, exception handling is often ignore in lieu of bigger fish to fry. On the surface, exception handling appears sufficiently complicated enough that most developers have simply resolved to ignore it on a day-to-day basis or altogether. Only during the last weeks of development do they tack on a top-level try/catch block to avoid complete system failure or to log that "some" error occurred. Rather than a simple error dialog appearing to users, they are greeted with the "yellow screen of death". Even when the developer does manage to display an error dialog, the message is often vague or cryptic, e.g., "An error occurred".

We can do better than this. I believe the issue is that not a lot of focus has been given to providing simple, bare-minimum exception handling. For the majority of applications, exception handling only needs to satisfy the following requirements:

@jehugaleahsa
jehugaleahsa / presql.sql
Last active Aug 30, 2019
Query Language Examples
View presql.sql
-- Entities come in the form of aliases (e.g., X as x)
-- and comma-separated fields are wrapped with curly braces (e.g., { x, y }).
-- Field names must be unique within entities.
-- Field names can be overwritten using a colon (e.g., { x: y, a: b }).
-- select - get all applications
from Application as a
select a
-- The distinct keyword following select removes duplicates from the results.
@jehugaleahsa
jehugaleahsa / web-circles.md
Last active Jun 4, 2019
Razor and TypeScript
View web-circles.md

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:

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
jehugaleahsa / math.md
Last active Sep 26, 2018
Encoding the future
View math.md

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.

One

@jehugaleahsa
jehugaleahsa / models.md
Last active Sep 26, 2018
Good model design
View models.md

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

You can’t perform that action at this time.