Skip to content

Instantly share code, notes, and snippets.

"""
The Premedicant Dose for animal type is the weight of animal multipled by drug dose rate, divided
by drugconcertration.
"""
from __future__ import division
drug_concentrations = {"meloxicam": 5.0, "amoxicillin clavulanic acid": 32.5, "ketamine": 100,
"enrofloxacin 2.5 percent solution": 25, "enrofloxacin 5.0 percent solution": 50}
from xml.etree import ElementTree
import json
import os
import shutil
import requests
"""
todo:
A better solution that manually togglign `FORCE_CACHED`
@ninmonkey
ninmonkey / PingLog valid query else explicit error.pq
Created May 13, 2020 07:04
Example of forcing valid data on queries in Power BI
// PingLog - returns valid table otherwise entire query errors
// Output looks like: https://i.imgur.com/60oUF0C.png
let
Source = Sql.Databases("sandbox"),
nin = Source{[Name="nin"]}[Data],
PingLog = nin{[Schema="dbo",Item="PingLog"]}[Data],
#"Renamed Columns" = Table.RenameColumns(
PingLog,
{
{"Latency", "Ping"},
{
"Metadata": {
"Encoding": "utf8",
"Description": "appears to be query names and GUIDs",
"Path": "Metadata",
"ContentType": "text serialized text with null terminated chars?"
},
"ReportLayout": {
"Encoding": "utf_16le",
"description": "layout, slicer settings, etc and contains escaped JSON",
@ninmonkey
ninmonkey / Using JSON from a web api in PowerBI.pq
Created June 5, 2020 00:21
Using JSON from a web api in PowerBI.pq
let
// basic json ( non-authenticated get request )
Source_Json = Json.Document(Web.Contents("https://api.publicapis.org/random")),
Source_Table = Record.ToTable(Source_Json),
Entries = Source_Table{ [Name="entries"] }[Value],
result=Entries
in
result
@ninmonkey
ninmonkey / nin_dynamic_prompt.ps1
Created June 5, 2020 20:57
dymamic prompt: switches between the VS Code addon profile, and windows terminal
function Prompt() {
$ProfileName = nin_guess_terminal
# ... switch
}
function nin_guess_terminal() {
<#
detect whether you're running from
vscode addon, windows terminal or other
#>
@ninmonkey
ninmonkey / using XPaths with powershell.png
Last active June 24, 2021 14:25
navigate XML using XPaths -- choosing which children to visit -- PowerShell [xml]
using XPaths with powershell.png
@ninmonkey
ninmonkey / If not actually distinct, PowerQuery force early query failure.pq
Created June 7, 2020 22:14
Get early explicit errors, prevents distinct-errrors from being applied.
/// if conditions fail, don't allow the query
// to silently complete as "successful"
let
Source = Sql.Databases("server"),
nin = Source{ [Name="instance"] }[Data],
PingLog = nin{ [Schema="dbo",Item="PingLog"] }[Data],
// optional function: prints list values as a `csv` without having to drill down
list_to_string = (text_list as list) as text =>
let
@ninmonkey
ninmonkey / powershellDocs_compare.ps1
Last active June 26, 2020 15:08
Compare Command docs across powershell versions
@'
Usage:
> cd c:\github\powershell
> git clone https://github.com/MicrosoftDocs/PowerShell-Docs.git
set $doc_path
$doc_path = 'c:\github\powershell\PowerShell-Docs\reference'
@ninmonkey
ninmonkey / Making Regular expressions readable.md
Last active May 8, 2021 17:41
Making Regex's readable using 'x' or .VERBOSE flags

Making regular expressions readable

What is easier to understand two months from now? Note that they are exactly equal in this example.

$regex = '(?n)(?<destination>(\d{1,3}\.){3}\d{1,3}).*time=(?<ms>\d+)ms'

verses