Skip to content

Instantly share code, notes, and snippets.

View Curts0's full-sized avatar

Curtis Stallings Curts0

View GitHub Profile
@Curts0
Curts0 / virtualkeys.py
Created March 9, 2024 22:07 — forked from biqqles/virtualkeys.py
Cross-platform Win32 virtual-key codes
"""
Win32 virtual-key (VK) constants for Python, extracted from winuser.h with
comments.
Original copyright notice printed below:
/****************************************************************************
* *
* winuser.h -- USER procedure declarations, constant definitions and macros *
* *
* Copyright (c) Microsoft Corporation. All rights reserved. *
@Curts0
Curts0 / pbi_helper.py
Created December 16, 2022 22:58
Get connection string for localhost pbi file
import subprocess
def get_msmdsrv() -> list:
msmdsrv = subprocess.check_output(
[
"powershell",
"""Get-CimInstance -ClassName Win32_Process -Property * -Filter "Name = 'msmdsrv.exe'" | Select-Object -Property ProcessId -ExpandProperty ProcessId""",
]
)
import pytabular
model = pytabular.Tabular(CONNECTION_STR)
df = pytabular.Table_Last_Refresh_Times(model, group_partition = False)
model.Create_Table(df, 'Refresh Times')
import pytabular
model = pytabular.Tabular(CONNECTION_STR)
tables = pytabular.Return_Zero_Row_Tables()
if len(tables) > 0:
model.Refresh(tables, Tracing = True) #Add a trace in there for some fun.
#You have a few options when refreshing.
model.Refresh('Table Name')
#or...
model.Refresh(['Table1','Table2','Table3'])
#or...
model.Refresh(<Table Class>)
#or...
@Curts0
Curts0 / pytabularqueries.py
Created September 22, 2022 23:08
PyTabular Queries
#Run basic queries
DAX_QUERY = "EVALUATE TOPN(100, 'Table1')"
model.Query(DAX_QUERY) #returns pd.DataFrame()
#or...
DMV_QUERY = "select * from $SYSTEM.DISCOVER_TRACE_EVENT_CATEGORIES"
model.Query(DMV_QUERY) #returns pd.DataFrame()
#or...
SINGLE_VALUE_QUERY_EX = "EVALUATE {1}"
@Curts0
Curts0 / connectmodel.py
Created September 22, 2022 23:02
Connect to Tabular Model with PyTabular
import pytabular
model = pytabular.Tabular(CONNECTION_STR)
@Curts0
Curts0 / re_encoding_examples.csv
Created April 16, 2022 19:43
Re-Encoding Examples
Start_Time [Local Time] End_Time [Local Time] Table Column Duration_Seconds Text Database Model Partition Resource
Start Time End Time Sales QUANTITY 1.828 Encoding Details Database Model CFY Resource1
Start Time End Time Sales TOTAL_AMT 0.063 Encoding Details Database Model CFY Resource1
Start Time End Time Product PRODUCT_SKU 0.203 Encoding Details Database Model Partition Resource1
Start Time End Time Product PRODUCT_SKU 0.203 Encoding Details Database Model Partition Resource1
@Curts0
Curts0 / re_encoding.kql
Created April 16, 2022 19:37
Re Encoding Logs
AzureDiagnostics
| where OperationName == "ProgressReportEnd"
| where EventSubclass_s == 55
| project-keep Resource, DatabaseName_s, ObjectReference_s, TextData_s, Duration_s, StartTime_t, EndTime_t
| extend Object_Json = parse_xml(ObjectReference_s)
| extend Database = tostring(Object_Json.Object.Database)
| extend Model = tostring(Object_Json.Object.Model)
| extend Table = tostring(Object_Json.Object.Table)
| extend Partition = tostring(Object_Json.Object.Partition)
| extend Duration_Seconds = toint(Duration_s)/1000.00
@Curts0
Curts0 / processing_errors.csv
Created April 14, 2022 20:22
Lists Processing Errors
End_Time [Local Time] Database Details Error Server Resource User Application
4/14/2022, 10:57:32.583 AM Database1 Processing Info Like DB, Table, Partition, Max Parallelism, Type Error Text Server Resource serviceuser@company.com PowerBi
4/14/2022, 10:45:22.583 AM Database1 Processing Info Like DB, Table, Partition, Max Parallelism, Type Error Text Server Resource serviceuser@company.com TabularEditor
4/14/2022, 10:59:32.583 AM Database1 Processing Info Like DB, Table, Partition, Max Parallelism, Type Error Text Server Resource serviceuser@company.com PowerBi