Skip to content

Instantly share code, notes, and snippets.

View JamesIgoe's full-sized avatar

James J. Igoe JamesIgoe

View GitHub Profile
@JamesIgoe
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)
{
try
{
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
JamesIgoe / GenerateJsonExample.py
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:
try:
if email:
memberChange.append({'Email': email[0], 'MemberName': '', 'MemberType': 'Person', 'Action': 'Add'})
except:
@JamesIgoe
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)
{
try
{
using (HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("X-API-KEY", apiKey);
@JamesIgoe
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
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
JamesIgoe / filterForLabels.py
Last active August 23, 2020 17:27
Filter for multiindex (2-column) series
def filterForLabels(df: pd.DataFrame, label) :
try:
sideLeft = df[label,]
except:
sideLeft = pd.DataFrame()
try:
sideRight = df[:,label]
except:
sideRight = pd.DataFrame()
@JamesIgoe
JamesIgoe / corrFilter.py
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
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: https://stackoverflow.com/a/55611789/3272594
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
<style>
</style>
<script>
(function () {
@JamesIgoe
JamesIgoe / PostExamples.js
Created March 5, 2020 17:54
Variety of POST examples in JavaScript
function postMessageXhr() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
ApplicationName: "",
ComputerName: "",
OperatingSystem: "",
UserName: "",