Skip to content

Instantly share code, notes, and snippets.

View vector623's full-sized avatar

David Gallmeier vector623

View GitHub Profile
public class StatusController : Controller
{
public ILoggerFactory LoggerFactory { get; }
public DbConnectionStringBuilder ConnectionStringBuilder { get; }
public StatusController(DbConnectionStringBuilder connectionStringBuilder, ILoggerFactory loggerFactory)
{
ConnectionStringBuilder = connectionStringBuilder;
LoggerFactory = loggerFactory;
}
}
public class Startup
{
public IConfigurationRoot Configuration { get; }
public ILoggerFactory LoggerFactory { get; }
public DbConnectionStringBuilder DbConnectionStringBuilder { get; }
public Startup()
{
Configuration = new ConfigurationBuilder()
.AddEnvironmentVariables("TROICENET_")
@vector623
vector623 / Replicate.sh
Created March 20, 2018 19:54
Simple script to migrate configuration from one host to the next
scp root@oldhost:/root/.bash_history /tmp/migrate.sh
sudo sh /tmp/migrate.sh
@vector623
vector623 / ObjectInitializer.cs
Created March 19, 2018 14:40
Example of object initialization.
var apolloUpdateAdjustment = new Apollo.UpdateAdjustment
{
supply = record["SUPPLY"].ToString(),
prosales = record["ProSales"].ToString(),
release_date = record["Release Date"].ToString(),
reason_for_update = record["Reason For Update"].ToString(),
itemid = Convert.ToInt64(record["ItemID"].ToString()),
};
@vector623
vector623 / AssignmentStatementExample.cs
Last active March 19, 2018 14:35
Example of assignment statement
var apolloUpdateAdjustment = new Apollo.UpdateAdjustment();
apolloUpdateAdjustment.itemid = Convert.ToInt64(record["ItemID"].ToString());
apolloUpdateAdjustment.reason_for_update = record["Reason For Update"].ToString();
apolloUpdateAdjustment.release_date = record["Release Date"].ToString();
apolloUpdateAdjustment.prosales = record["ProSales"].ToString();
apolloUpdateAdjustment.supply = record["SUPPLY"].ToString();
@vector623
vector623 / CsvHelperExample.cs
Created March 14, 2018 17:19
Example use of CsvHelper nuget package; also example usage of dynamic and RouteValueDictionary
public static void ImportPricingFile()
{
using (var streamReader = new StreamReader(@"C:\Users\d.gallmeier\gits\daytoday\20180308\pricingFile.csv"))
using (var csv = new CsvReader(streamReader))
using (var db = new SqlConnection(Config.AthenaConnectionString))
{
var pricingLines = csv
.GetRecords<dynamic>()
.Select(record =>
{
@vector623
vector623 / AggregateUntilAdWordsExample.cs
Created March 7, 2018 20:55
example usage of AggregateUntil() with Google's AdWords API
private static List<CriterionBidLandscape> GetCriterionBidLandscapes(DataService dataService, string awql)
{
var bidLandscapes = Enumerable
.Range(0, Int32.MaxValue)
.AggregateUntil(
new CriterionBidLandscapePage()
{
entries = new CriterionBidLandscape[] { },
totalNumEntries = 0,
},
@vector623
vector623 / AggregateUntil.cs
Created March 7, 2018 20:19
A customized version of C#'s Aggregate() method, tailored for paged web API results
public static TAccumulate AggregateUntil<TSource, TAccumulate>(this IEnumerable<TSource> source,
TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate,bool> untilFunc)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (func == null)
{
@vector623
vector623 / RouteValueDictionaryUsage.cs
Created March 5, 2018 21:41
use RouteValueDictionary to de-anonymize dynamic types
using (var reportResponse = reportRequest.GetResponse())
using (var reportReader = new StreamReader(reportResponse.Stream))
using (var csv = new CsvReader(reportReader))
{
var records = csv
.GetRecords<dynamic>()
.Select(record =>
{
var recordDictionary = new RouteValueDictionary(record);
var newKeywordStat = new KeywordPerformanceStat() {
@vector623
vector623 / PhantomRunner.cs
Created February 20, 2018 17:57 — forked from DotNetNerd/PhantomRunner.cs
Grabbing a site in C# using phantomJS
class Program
{
static void Main(string[] args)
{
var grabby = new Grabby();
string output = grabby.Grab("http://www.dotnetnerd.dk/cv");
Console.WriteLine(output);
File.WriteAllText("c:\\test.html", output);
}