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 / 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)
@jehugaleahsa
jehugaleahsa / ng-signalr.md
Last active Sep 29, 2019
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 / 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 / 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 / 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

@jehugaleahsa
jehugaleahsa / nested-forms.md
Created Jun 23, 2017
Angular 2- Nested Model-Driven Forms
View nested-forms.md

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

@jehugaleahsa
jehugaleahsa / rpn.hs
Created Mar 3, 2018
Reverse Polish Notation
View rpn.hs
calculate :: [String] -> Maybe Double
calculate [] = Nothing
calculate a = calculateHelper a []
where
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
You can’t perform that action at this time.