Skip to content

Instantly share code, notes, and snippets.

View BrutalSimplicity's full-sized avatar
💭
Simplicity is hard

Kory Taborn BrutalSimplicity

💭
Simplicity is hard
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Text.RegularExpressions;
using System.IO;
namespace XmlDiffLib
@BrutalSimplicity
BrutalSimplicity / GetAllWireProperties.cs
Last active June 22, 2016 01:03
Enumerates nearly all public properties in an object graph.
/// <summary>
/// Enumerates "all" public properties in an object graph. All is used loosely as this
/// may miss some older public property types that aren't enumerable (.Net v1 maybe).
/// CAUTION: Do not use on object graphs with cycles, as it will cause infinite reucrsion.
/// Additionally, this can be a VERY expensive call if used on a large object graph.
/// Ensure your use case can sustain the time-cost implications.
/// </summary>
/// <param name="obj">Object to traverse</param>
/// <returns>Enumerable set of properties</returns>
private static IEnumerable<Tuple<object, PropertyInfo>> GetWiredProperties(object obj)
@BrutalSimplicity
BrutalSimplicity / RateCache.cs
Last active June 23, 2016 07:14
A class for Caching data across multiple threads. This was used to allow better communication among threads via a shared memory cache.
/// <summary>
/// This class caches data involved in rating. It uses a Guid as a key
/// to the cached Rate Data. Most methods involve manipulating the cached Rate Data,
/// not the cache itself. This is useful in Rate Modules that need to reference
/// data from previous rates by the same user (i.e. Multiple Programs with Single Request).
/// </summary>
public class RateCache
{
#region Public Properties
/// <summary>
@BrutalSimplicity
BrutalSimplicity / nfldb_fpp.sql
Last active September 18, 2016 16:02
Postgresql query for calculating fantasy points for all players in the 2015 season from nfldb (See nfldb wiki on github for more info on setting this database up)
CREATE OR REPLACE FUNCTION nfl_ffps(_season_year int, _season_type season_phase)
RETURNS table("name" varchar, "position" text, ffps double precision) AS $$
BEGIN
RETURN QUERY
-- points come from my yahoo fantasy league, but can be applied arbitrarily for other leagues
WITH kicker_ffps AS (
SELECT
play_player.player_id as player_id,
play_player.kicking_xpmade as kicking_xpmade,
(
@BrutalSimplicity
BrutalSimplicity / Base64Compression.cs
Created September 26, 2016 18:50
Methods for converting and object to/from a base-64 encoded string
public static void CopyTo(Stream src, Stream dest)
{
byte[] bytes = new byte[4096];
int cnt;
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
{
dest.Write(bytes, 0, cnt);
}
}
// this is only a marker for resolving the TransactionalQueryManager
public interface ITransactionRepository
{
}
public class ProductRepository : IProductRepository, ITransactionRepository
{
}
<?xml version="1.0" encoding="utf-8" ?>
<root>
<players>
<player name="Pam" >
<tile terrain="B" cost="1" />
<tile terrain="Z" cost="2" />
<tile terrain="N" cost="2" />
<tile terrain="M" cost="2" />
<tile terrain="P" cost="5" />
</player>
@BrutalSimplicity
BrutalSimplicity / gist:eff9fcc5e2de652683aa3cb3e87e8bf4
Created November 20, 2019 14:23
Multi-Stage Deployment via Jenkins
stage('QA Deployment') {
environment {
AWS_ACCESS_KEY_ID = credentials('Dev_Access')
AWS_SECRET_ACCESS_KEY = credentials('Dev_Secret')
}
when {
beforeAgent true
branch 'develop'
}
options {
import { safeLoad } from 'js-yaml';
import { readFileSync } from 'fs';
import { getOutputValues, EnvironmentProps } from './infrastructure/environments';
import { LoadBalancerServiceProps, Route53Stack } from './infrastructure/route53';
import { App } from '@aws-cdk/core';
type FargateConfig = {
environments: EnvironmentProps[];
}
@BrutalSimplicity
BrutalSimplicity / Olo.fs
Created November 21, 2018 21:26
One of our restaurant clients wants to know which pizza topping combinations are the most popular. Write a throw-away .NET console application that will download orders directly from http://files.olo.com/pizzas.json and output the top 20 most frequently ordered pizza topping combinations. List the toppings for each popular pizza topping combinat…
open FSharp.Data
type Pizza = JsonProvider<"pizzas.json">
type ToppingFrequencyPair = { Toppings: string[]; Frequency: int }
let getToppingFrequencyPair grouping =
{ Toppings = fst grouping; Frequency = snd grouping |> Array.length }
[<EntryPoint>]