Skip to content

Instantly share code, notes, and snippets.

View joshgo's full-sized avatar
🏠
Working from home

Josh joshgo

🏠
Working from home
View GitHub Profile
@joshgo
joshgo / convert-json-date.js
Created January 18, 2013 21:10
Convert a JSON Date string (epoch value) to a javascript Date object as described here: http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json
function ConvertToDatetime(dateValue) {
var regex = /-?\d+/;
var match = regex.exec(dateValue);
return new Date(parseInt(match[0]));
}
@joshgo
joshgo / self-install-windows-service.cs
Last active May 3, 2024 05:55
self install windows service
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Reflection;
using System.Configuration.Install;
namespace test
{
@joshgo
joshgo / nodebus.cs
Created March 1, 2013 23:13
sample code for possibly having ETL's as "nodes". - Each node can pass the data to it's child or children (2) - Some nodes can transform - Some nodes can split data - Some nodes can write/read from queue
using System;
namespace NodeBus
{
class Program
{
public static void Main(string[] args)
{
INode square = new TransformNode(new OutfileNode(null, "file2.txt"), (x) =>
{
@joshgo
joshgo / reader-extensions.cs
Created March 19, 2013 13:16
Simple reader extensions. Converts reader records into Entities/Objects - Support for simple types - And just dabbling with Expression Trees
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace ReaderExtensions.Extensions
{
public static class DataReaderExtensions
@joshgo
joshgo / LumenICsvParser.cs
Last active December 15, 2015 04:59
CsvHelper - ICsvParser implementation using Lumenworks Lumenworks is a very efficient and very reliable CsvParser.
public class LumenICsvPaser : CsvHelper.ICsvParser
{
private LumenWorks.Framework.IO.Csv.CsvReader _reader = null;
public LumenICsvPaser(System.IO.TextReader stream) : this(stream, new CsvConfiguration())
{
}
public LumenICsvPaser(System.IO.TextReader stream, CsvConfiguration config)
{
@joshgo
joshgo / datarow-comparer.cs
Last active December 15, 2015 17:09
DataRow Comparer == Solution for sorting rows with your own comparer. Helps with customizing the comparison function. Helps the C# Sort() match the ORDER BY in SQL. http://msmvps.com/blogs/deborahk/archive/2009/07/23/linq-sorting-a-datatable.aspx http://stackoverflow.com/questions/3808158/string-comparison-differences-between-net-and-t-sql
public class RowComparer : IComparer<System.Data.DataRow>
{
public Dictionary<int, bool> SortColumns { get; set; }
public int Compare(System.Data.DataRow x, System.Data.DataRow y)
{
foreach (int key in SortColumns.Keys)
{
int compareResult;
@joshgo
joshgo / disposable-template.cs
Created May 17, 2013 02:38
Disposable Template - Courtesy of http://blog.phatboyg.com/
public class DisposableClass : IDisposable
{
bool _disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
@joshgo
joshgo / chocolatey-install-proxy.bat
Created July 29, 2013 14:40
Chocolatey Install Behind Proxy
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$a = new-object net.webclient; $a.proxy.credentials=[system.net.credentialcache]::defaultnetworkcredentials;$a.DownloadString('https://chocolatey.org/install.ps1') | iex" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
@joshgo
joshgo / svn-precommit.sh
Created November 20, 2013 17:21
SVN Pre-Commit script
REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null
GREP_STATUS=$?
if [ $GREP_STATUS -ne 0 ]
then
@joshgo
joshgo / test-expression-memberinit.cs
Created January 9, 2014 19:11
Playing around with expressions - Create a copy function
private Func<object, object> CreateInitFn(object obj)
{
var keyType = obj.GetType();
if (_initFn.ContainsKey(keyType))
{
return _initFn[keyType];
}
ParameterExpression xTmp = Expression.Variable(obj.GetType(), "tmp");