Skip to content

Instantly share code, notes, and snippets.

View jehugaleahsa's full-sized avatar

Travis Parks jehugaleahsa

View GitHub Profile
@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 / 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 / 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 / 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 / SqlBulkCopier.cs
Created August 24, 2016 14:20
SqlBulkCopy Wrapper
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");
@jehugaleahsa
jehugaleahsa / ConnectionLifetimeManager.cs
Created August 24, 2016 14:21
Connection Lifetime Manager
public class ConnectionLifetimeManager : IDisposable
{
private readonly IDbConnection connection;
private readonly bool needsClosed;
public ConnectionLifetimeManager(IDbConnection connection)
{
this.connection = connection;
if (connection.State == ConnectionState.Closed)
{
@jehugaleahsa
jehugaleahsa / ArgumentAssigner.js
Created February 10, 2012 20:46
Handle Optional Parameters with Default Values in JavaScript
function assignArguments(values, expression) {
// determine how many arguments are needed for each parameter
// grab all of the defaults, too
var needed = 1;
var argsNeeded = {};
var defaults = {};
var queue = [expression];
for (var queueIndex = 0; queueIndex < queue.length; ++queueIndex) {
var node = queue[queueIndex];
if (typeof node === 'string') {
@jehugaleahsa
jehugaleahsa / arm.scala
Created October 5, 2016 17:25
Scala ARM
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 / EventIdLayoutRenderer.cs
Last active January 26, 2017 16:42
Custom NLog Json formatter driven by Exception.Data
[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 / jaded.md
Last active January 31, 2017 01:21
Finding a balance in complexity

The Early Years...

I was one of those eager college grads that went and read the GOF's Design Patterns. Being pretty fresh to development in a professional setting, I used design patterns everywhere, even where they didn't belong. I've also read a ton of books on OOP and software architecture and they had a huge influence on my past projects.

Jaded

Now that I've been at it for about 10 years, I've seen a sharp decline in the number of design patterns I use. In terms of UML and OOP, I barely even think about them anymore. Some of it's just that I'm so familiar with them that I don't really notice when I'm using them. The rest is because I just don't find myself reaching for them as often as before. Recently, I've noticed a sharp correlation between the use of abstract classes and increased code complexity. So, I usually rely on composition and helper classes for my shared functionality. I use interfaces mostly to support dependency injection and unit testing.

Every now and then, I whip out the Deco