Skip to content

Instantly share code, notes, and snippets.

View jehugaleahsa's full-sized avatar

Travis Parks jehugaleahsa

View GitHub Profile
@jehugaleahsa
jehugaleahsa / settings.json
Last active August 22, 2016 14:30
MS Code User Settings
// Place your settings in this file to overwrite the default settings
{
"editor.wrappingColumn": 0,
"editor.rulers": [80],
"editor.autoClosingBrackets": false,
"window.openFilesInNewWindow": false,
"window.restoreFullscreen": true,
"window.format.wrapLineLength": 0,
"html.format.indentInnerHtml": true,
"terminal.integrated.shell.linux": "bash",
@jehugaleahsa
jehugaleahsa / Program.py
Created August 9, 2016 15:08
Python - Count Occurrences
def getSegments(input):
start = 0
length = len(input)
while start != length:
current = input[start]
end = next((i for i in range(start, length) if input[i] != current), length)
count = end - start
yield (count, current)
start = end
@jehugaleahsa
jehugaleahsa / performance comparison.txt
Created May 29, 2016 23:54
FlatFiles CSV vs CSV Helper
Flat Files: 00:00:05.4573869
Flat Files: 00:00:05.4114582
Flat Files: 00:00:05.3200663
Flat Files: 00:00:05.3753001
Flat Files: 00:00:05.3733791
Flat Files: 00:00:05.4018424
Flat Files: 00:00:05.3608055
Flat Files: 00:00:05.4624856
Flat Files: 00:00:05.3894682
Flat Files: 00:00:05.5045739
@jehugaleahsa
jehugaleahsa / try.java
Created March 17, 2016 17:05
Try/Catch/Finally Hell
List<String> requestCodes(String dbUrl, String id) {
List<String> result = new ArrayList<String>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(dbUrl);
stmt = conn.prepareStatement("SELECT * FROM customers WHERE id = ?");
stmt.setString(1, id);
rs = stmt.executeQuery();
@jehugaleahsa
jehugaleahsa / factories.md
Last active March 8, 2016 01:28
Factories and the Rebirth of Object-Oriented Programming

As familiar as I am with OOP and design patterns, I rarely see myself coding in an object-oriented fashion. I make heavy use of the strategy pattern to swap out implementations based on configuration settings, but that's about it. Like most OOP enthusiasts, at one time I used patterns pretty heavily. Some composite pattern here, decorator there -- sprinkle in a little bridge pattern for taste. With a gradual introduction to TDD and functional programming, that's slowly faded away over the years.

In 2012, it dawned on me how freaking awesome functional programming is. With a few tricks here and there, you can almost completely eliminate the need for stateful classes. Instead, classes just get passed their dependencies via dependency injection (DI). Any other information is passed via method parameters. Closures and other functional hacks handled those edge cases where there seemed to be a need for state. This style of programming is especially effective when you start working with RESTful APIs or heavily thre

@jehugaleahsa
jehugaleahsa / ObservableModel.cs
Last active February 2, 2016 15:38
Smart or stupid...
public abstract class ObservableModel<TModel> : INotifyPropertyChanged
where TModel : ObservableModel<TModel>
{
private readonly Dictionary<PropertyInfo, object> lookup;
protected ObservableModel()
{
this.lookup = new Dictionary<PropertyInfo, object>();
}
@jehugaleahsa
jehugaleahsa / di.js
Last active August 29, 2015 14:17
JavaScript Dependency Injection
var di = (function () {
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
function getContainer() {
var container = function () {
@jehugaleahsa
jehugaleahsa / QueryOrderer.cs
Last active August 29, 2015 14:16
EF Orderer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace DataModeling
{
public class QueryOrderer<TEntity>
where TEntity : class
@jehugaleahsa
jehugaleahsa / preql.txt
Last active March 17, 2021 13:36
Query Language Examples
# Literals, such as booleans, integers, floats, and character strings are actually vectors of length 1.
# booleans:
true
# or
false
# integers (can have arbitrary _ as separators):
1, 45, 1_000_000
# floats
@jehugaleahsa
jehugaleahsa / navigator.js
Created September 11, 2014 15:23
Navigator Using Earl.js
application.factory('navigator', ['$http', '$window', 'baseUrl', function ($http, $window, baseUrl) {
function enrich(urlTemplate) {
if (!urlTemplate) {
return null;
}
var template = earl(urlTemplate);
var resource = {