Skip to content

Instantly share code, notes, and snippets.

View toddmeinershagen's full-sized avatar

Todd Meinershagen toddmeinershagen

View GitHub Profile
@toddmeinershagen
toddmeinershagen / build-df-from-scratch.py
Created July 1, 2022 03:00
Build DataFrame from Scratch in Python
df = None
for index in range(0,5):
row1 = {'text': f'this is text', 'skills': [{"skill": "Credit", "confidence": 0.53}], 'error': 93}
row_df = pd.DataFrame(row1, index=[f'abcd{index}'])
if df is None:
df = row_df
else:
df = df.append(row_df)
@toddmeinershagen
toddmeinershagen / generate-employees-in-snowflake.sql
Last active April 15, 2022 18:16
Snowflake: Generate Employees Routine
--STEP 1: Create Employees
SET numberOfEmployees = 20000;
CREATE OR REPLACE TEMPORARY TABLE employees (
ROWID INT,
MANAGERID VARCHAR(255),
MANAGERFIRSTNAME VARCHAR(50),
MANAGERLASTNAME VARCHAR(50),
EMPLOYEEID VARCHAR(255),
EMPLOYEEFIRSTNAME VARCHAR(50),
EMPLOYEELASTNAME VARCHAR(50)
@toddmeinershagen
toddmeinershagen / Program.cs
Created September 1, 2021 19:19
Demo of Task Parallelization Timing
class Program
{
static async Task Main(string[] args)
{
var source = new CancellationTokenSource();
var cancellationToken = source.Token;
var tasks = new List<Task>
{
Task.Run(async () => await ATask(TimeSpan.FromMilliseconds(2600), cancellationToken), cancellationToken),
@toddmeinershagen
toddmeinershagen / logging.py
Created June 28, 2021 23:23
A sample of logging set up in python.
import logging
import time
logger = logging.getLogger(__file__)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(name)s | %(levelname)s | %(message)s",)
logging.Formatter.converter = time.gmtime
logger.addHandler(logging.StreamHandler())
@toddmeinershagen
toddmeinershagen / gather-metrics-by-operation-for-run.kql
Last active February 2, 2021 14:20
Kusto - Gather Metrics for Run by Operation
let correlationId = 'bf125a40-efc8-4414-84f9-cede7aeb1305';
let t = traces
| where customDimensions.prop__CorrelationId == correlationId
| where message contains 'started' or message contains 'ended' or message contains 'failed'
| project timestamp, operation_Id, operation_Name, function = substring(message, 0, indexof(message, " ")), result = substring(message, indexof(message, " "), string_size(message) - indexof(message, " ") - 1);
let t2 = t
| project timestamp, operation_Id, operation_Name, function, result = case(result contains ".", substring(result, 0, indexof(result, ".")), result);
let starts = t2
| extend operation = strcat(operation_Id, ":", function)
| extend start = timestamp
@toddmeinershagen
toddmeinershagen / ShieldExceptionsAttribute.cs
Created October 29, 2020 14:00
Aspect - Shielding Exceptions using AspectInjection
[Injection(typeof(ExceptionShieldingAspect))]
public class ShieldExceptionsAttribute : Attribute
{
}
[Aspect(Scope.Global)]
public class ExceptionShieldingAspect
{
public const string ErrorFormat = "{0} Id: {1}";
public class FeatureFunctions
{
private readonly ILogger _logger;
private readonly IFlagService _flagService;
private readonly IConfigurationRefresher _refresher;
public ReminderFeatureFunctions(ILogger<FeatureFunctions> logger, IFlagService flagService, IConfigurationRefresher refresher)
{
_logger = logger;
_flagService = flagService;
@toddmeinershagen
toddmeinershagen / Functions.cs
Created August 6, 2020 14:50
Timer Trigger Function to Keep Serverless DB Alive from 7am-6pm every 15 minutes
[FunctionName("TimerTriggeredFunction1")]
public static async Task Handle1(
[TimerTrigger("0 */15 7-18 * * *")] TimerInfo timer, ILogger logger)
{
if (Convert.ToBoolean(Configuration["keep-db-alive"]))
{
logger.LogTrace("Executing logic to keep the db alive.");
using (var connection = new SqlConnection(Configuration["connection-string"]))
{
@toddmeinershagen
toddmeinershagen / get-data-dictionary.sql
Created April 19, 2020 16:49
Get Data Dictionary for the Current DB in SQL Server
SELECT T.name AS TableName ,
C.name AS ColumnName ,
P.name AS DataType ,
P.max_length AS Size ,
CAST(P.precision AS VARCHAR) + '/' + CAST(P.scale AS VARCHAR) AS PrecisionScale
FROM sys.objects AS T
JOIN sys.columns AS C ON T.object_id = C.object_id
JOIN sys.types AS P ON C.system_type_id = P.system_type_id
WHERE T.type_desc = 'USER_TABLE'
ORDER BY
@toddmeinershagen
toddmeinershagen / pointers-example-in-c.c
Created September 10, 2019 00:16
Pointers Example in C
#include <stdio.h>
int main(void) {
int counter = 0;
int * pointer_to_counter = &counter;
int ** pointer_to_pointer = &pointer_to_counter;
int *** pointer_to_pointer_to_pointer = &pointer_to_pointer;
counter += 1;
*pointer_to_counter += 1;