Skip to content

Instantly share code, notes, and snippets.

Travis Parks jehugaleahsa

Block or report user

Report or block jehugaleahsa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jehugaleahsa
jehugaleahsa / LTT.md
Last active Jun 14, 2019
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 / iippp.md
Last active Feb 9, 2017
The Inane Insistence on Patterns Pertaining to Persistance
View iippp.md

The Inane Insistence on Patterns Pertaining to Persistance

An annoying pattern

I have been noticing an annoying pattern lately. Whenever I hear about a new project starting, more often than not, I see someone on the team jump into "DB architect" mode. For those individuals, literally every last ounce of energy goes into designing the database. Worse, they want sole ownership and literally forego all other development activities until they are satisfied.

It has been a long time since I've seen a requirements document that was thorough enough or accurate enough that I could devise a perfect database on day one of the project. I have two guesses why some developers are drawn to early database design: 1) it gives them a sense of control over the project, thinking it establishes them in some essential role; or 2) they have been burned too many times in the past with bad database designs.

My experience is that quality software projects grow organically. When you start a new project in Visual Studio, you're n

@jehugaleahsa
jehugaleahsa / ATTS.md
Last active Feb 2, 2017
A Transition to Statelessness
View ATTS.md

A Transition to Statelessness

Introduction

In 2012, I took a psychedelic journey into the world of functional programming. I started learning some ML-based languages, including F#, OCAML and Haskell. I also discovered Scala, which is now one of my all-time favorite languages.

I think too many people stop learning functional programming before they get into the really interesting parts. Filter/map/reduce is just the tip of the iceberg. Even if that is all you end up learning, you should at a minimum take to heart Command Query Separation. But the real meat of functional programming comes in the form of closures, partial application, currying, high-order functions and immutability. Check out this C#:

Func<int, int> getAdder(int value)
{
    return i => i + value;
@jehugaleahsa
jehugaleahsa / EventIdLayoutRenderer.cs
Last active Jan 26, 2017
Custom NLog Json formatter driven by Exception.Data
View EventIdLayoutRenderer.cs
[LayoutRenderer("event-id-json-data")]
public class EventIdLayoutRenderer : LayoutRenderer
{
private const string _eventIdKey = "EventId";
private static JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
@jehugaleahsa
jehugaleahsa / MEH.md
Last active Oct 30, 2017
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 / 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

View arm.scala
import scala.language.reflectiveCalls
def using[TResource <: { def close(): Unit }, TResult](resource: => TResource)(action: TResource => TResult): TResult = {
val instance = resource
try {
action(instance)
} finally {
instance.close()
}
}
@jehugaleahsa
jehugaleahsa / join.ps1
Last active Oct 14, 2019
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)
View ConnectionLifetimeManager.cs
public class ConnectionLifetimeManager : IDisposable
{
private readonly IDbConnection connection;
private readonly bool needsClosed;
public ConnectionLifetimeManager(IDbConnection connection)
{
this.connection = connection;
if (connection.State == ConnectionState.Closed)
{
View SqlBulkCopier.cs
public class SqlBulkCopier<T>
{
private readonly string tableName;
private readonly Dictionary<PropertyInfo, PropertyMapping> mappings;
public SqlBulkCopier(string tableName)
{
if (String.IsNullOrWhiteSpace(tableName))
{
throw new ArgumentNullException("tableName");
You can’t perform that action at this time.