Skip to content

Instantly share code, notes, and snippets.

View CurtHagenlocher's full-sized avatar

Curt Hagenlocher CurtHagenlocher

  • Microsoft
  • Mercer Island, WA
View GitHub Profile
@CurtHagenlocher
CurtHagenlocher / FoldedRowExpression.pq
Last active August 31, 2021 12:23
Given a table type and a function, returns the AST for the foldable function as JSON
(tableType as type, fn as function) =>
let
TransformNode = (x) => Record.FromList(List.Transform(Record.FieldValues(x), TransformValue), Record.FieldNames(x)),
TransformValue = (x) => if x is record then TransformRecord(x) else if x is list then TransformList(x) else x,
TransformList = (x) => List.Transform(x, TransformValue),
TransformRecord = (x) =>
if x = RowExpression.Row then [Kind="Row"]
else if x[Kind] = "Constant" then TransformConstant(x)
else TransformNode(x),
TransformConstant = (x) => if x[Value] is function and TryFunctionName(x[Value]) <> null then [Kind="Identifier", Name=TryFunctionName(x[Value])]
@CurtHagenlocher
CurtHagenlocher / multipart.m
Created July 20, 2015 20:18
Using multipart/form-data with Power Query. This assumes that any files being uploaded are textual; changing this to support arbitrary binary data is possible, but wasn't interesting to me.
let
Web.MultiPartPost = (url as text, parts as record) as binary =>
let
unique = Text.NewGuid(),
boundary = "--" & unique,
crlf = "#(cr)#(lf)",
item = (name, value) =>
let
filename = Value.Metadata(value)[name]?,
contentType = Value.Metadata(value)[type]?,
@CurtHagenlocher
CurtHagenlocher / FoldingNavigationTable.pq
Created October 8, 2021 20:07
Allows indexing to be folded in a navigation table
section Section1;
// Does a short search on Wikipedia. This is meant to stand in for a function that returns the navigation data.
GetWikipediaSearch = (term) => Json.Document(Web.Contents("https://en.wikipedia.org/w/api.php", [Query=[
action="query",
origin="*",
format="json",
generator="search",
gsrnamespace="0",
gsrlimit="5",
@CurtHagenlocher
CurtHagenlocher / Web.ContentsCustomRetry.m
Created April 30, 2015 13:08
Demonstrates the use of a custom retry duration with Web.Contents.
let
Value.WaitFor = (producer as function, interval as function, optional count as number) as any =>
let
list = List.Generate(
() => {0, null},
(state) => state{0} <> null and (count = null or state{0} < count),
(state) => if state{1} <> null
then {null, state{1}}
else {1 + state{0}, Function.InvokeAfter(() => producer(state{0}), interval(state{0}))},
(state) => state{1})
@CurtHagenlocher
CurtHagenlocher / LoadRecordBatch.cs
Created February 27, 2024 03:45
Load SqlDataReader into Arrow RecordBatch
using Apache.Arrow;
using Apache.Arrow.Types;
using Microsoft.Data.SqlClient;
using System.Data.Common;
using System.Data.SqlTypes;
namespace Loader
{
internal class Program
{