Skip to content

Instantly share code, notes, and snippets.

View afreeland's full-sized avatar

Aaron Freeland afreeland

View GitHub Profile
@afreeland
afreeland / gist:6733381
Last active March 1, 2024 10:32
C#: LINQ Expression Builder dynamic where clause based on filters
public class ExpressionBuilder
{
// Define some of our default filtering options
private static MethodInfo containsMethod = typeof(string).GetMethod("Contains", new[] { typeof(string) });
private static MethodInfo startsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
private static MethodInfo endsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
public static Expression<Func<T, bool>> GetExpression<T>(List<GridHelper.Filter> filters)
{
// No filters passed in #KickIT
@afreeland
afreeland / gist:5957c2a48a15c6501352
Created December 3, 2015 15:00
Zip a directory excluding a folder (node_modules) using 7z
C:\Program Files\7-Zip>7z.exe a -tzip utility.zip C:\nChannel_2014\nChannel\Dev\
nodejs\management -xr!node_modules
@afreeland
afreeland / GetLineNumberDuringException.cs
Last active May 30, 2023 05:22
C#: Get Line Number During Exception
try
{
throw new Exception();
}
catch (Exception ex)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
@afreeland
afreeland / gist:6796800
Last active August 19, 2022 13:58
C#: Reflection - Get Property Type, Switch on Type, Set Property Value
public static void SetKey<T>(T obj, TempDataDictionary _tempData)
{
System.Type type = typeof(T);
// Get our Foreign Key that we want to maintain
String foreignKey = _tempData["ForeignKey"].ToString();
// If we do not have a Foreign Key, we do not need to set a property
if (String.IsNullOrEmpty(foreignKey))
return;
@afreeland
afreeland / kubectl exec cmd multiple pods (envoy example)
Created July 25, 2022 17:08
Pipe `kubectl` pod names into `xargs` to invoke `curl` commands to update `envoy` debugging levels
kubectl -l{LABEL_SELECTOR} --no-headers -o custom-columns=":metadata.name" | xargs -I% kubectl exec % -- curl -X POST http://localhost:{ENVOY_ADMIN_PORT}/logging\?level\=debug
# List clusters
aws eks list-clusters
# You may need to target different profiles
AWS_PROFILE={account-profile-name-here} aws eks list-clusters
# Update kubeconfig with cluster info
aws eks update-kubeconfig --name {cluster-name-here}
@afreeland
afreeland / gist:f2e26e02a784e7cae66795a3281dbdb2
Created June 29, 2022 19:13
Git checkout pull requests
# git fetch {remote} pull/{PR#}/head && git checkout FETCH_HEAD
git fetch upstream pull/855/head && git checkout FETCH_HEAD
@afreeland
afreeland / gist:5532635
Last active January 27, 2022 15:34
XSLT: Set XSLT variable via choose
<xsl:variable name="Qty">
<xsl:choose>
<xsl:when test="Item_Item/Item_Locations/Item_Location[LocationID = $LocationID and ChannelID = $ChannelID]/Quantity = ''">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before(Item_Item/Item_Locations/Item_Location[LocationID = $LocationID and ChannelID = $ChannelID]/Quantity,'.')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
@afreeland
afreeland / gist:8184438
Last active November 11, 2021 11:45
JavaScript: CSV Get Headers from input stream using ArrayBuffer
function CSVImportGetHeaders()
{
// Get our CSV file from upload
var file = document.getElementById('CSVUpload').files[0]
// Instantiate a new FileReader
var reader = new FileReader();
// Read our file to an ArrayBuffer
reader.readAsArrayBuffer(file);
@afreeland
afreeland / middleware.js
Last active August 7, 2020 13:08
Webhook middleware (Chargify)
const app = express();
function rawBodySaver(req, res, buf, encoding) {
if (buf && buf.length) {
req.rawBody = buf.toString(encoding || "utf8");
}
}
// For parsing application/json
app.use(express.json());
// For parsing application/x-www-form-urlencoded (which is the Content-Type from Chargify)