Skip to content

Instantly share code, notes, and snippets.

View JamesIgoe's full-sized avatar

James J. Igoe JamesIgoe

View GitHub Profile
JamesIgoe / GenericPOST.cs
Last active May 30, 2023 12:40
Basics of generic method for making API POST calls
public static async Task<bool> PostInfoAsync<T>(string url, T request, string apiKey)
byte[] reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.None));
using HttpClient client = new();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Referer", Environment.MachineName);
JamesIgoe /
Last active April 9, 2023 15:45
Example code to generate JSON from 2 prior lists. Pulled from code that takes 2 DataFrames, one that list members to a add, and one that includes members to remove, then generates nested JSON.
import pandas as pd
import json
memberChange = []
for email in df_add.values:
if email:
memberChange.append({'Email': email[0], 'MemberName': '', 'MemberType': 'Person', 'Action': 'Add'})
JamesIgoe / GenericGET.cs
Created March 31, 2023 14:15
Basics of generic method for making API calls
//using System.Net.Http
//using System.Net.Http.Headers
public async Task<T> GetInfoAsync<T>(string url, string apiKey, string referer)
using (HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("X-API-KEY", apiKey);
JamesIgoe / EnumExtensions.cs
Last active October 27, 2022 06:32
When creating Swagger definitions using Swashbuckle, this enables detailing of ENUM properties as text
using CitrixSessionManagement;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
import os
os_name = os.sys.platform
pc_download_folder = '//tbd.../'
mac_download_folder = '/tbd.../'
file_name = 'tbd.csv'
#Mac or PC Path
if os_name == 'darwin':
JamesIgoe / ConsoleSpinner.cs
Last active October 27, 2022 06:34
Simple spinner for console app on long operations, providing viaul feedback.
Public Class ConsoleSpinner
Private counter As Integer
Public Sub New()
counter = 0
End Sub
Public Sub Turn(userText As String)
counter += 1
JamesIgoe /
Last active August 23, 2020 17:27
Filter for multiindex (2-column) series
def filterForLabels(df: pd.DataFrame, label) :
sideLeft = df[label,]
sideLeft = pd.DataFrame()
sideRight = df[:,label]
sideRight = pd.DataFrame()
JamesIgoe /
Created August 22, 2020 18:27
Correlation Filter: Creates a correlation matrix from a data frame. filters it for upper and lower bounds fo correlation, and then flattens it
#requires pandas and numpy
def corrFilter(x: pd.DataFrame, bound: float):
xCorr = x.corr()
xFiltered = xCorr[((xCorr >= bound) | (xCorr <= -bound)) & (xCorr !=1.000)]
xFlattened = xFiltered.unstack().sort_values().drop_duplicates()
return xFlattened
JamesIgoe / PartialViewForHTML5VideoWithFallback.vbhtml
Last active April 15, 2020 15:38
Javscript to hide HTML5 Video element from IE, as it cannot display it, and instead displays a link only,, Source:
(function () {
JamesIgoe / PostExamples.js
Created March 5, 2020 17:54
Variety of POST examples in JavaScript
function postMessageXhr() {
var xhr = new XMLHttpRequest();"POST", "", true);
xhr.setRequestHeader('Content-Type', 'application/json');
ApplicationName: "",
ComputerName: "",
OperatingSystem: "",
UserName: "",