View Web.ContentsCustomRetry.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
View multipart.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]?, |
View FoldedRowExpression.pq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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])] |
View DetectLanguage.pq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section Section1; | |
Detect1000Languages = (input as list) as list => | |
let | |
// TODO: support nulls, truncate text to avoid service limits | |
text = List.Buffer(input), | |
data = Table.FromColumns({text}, type table [text=text]), | |
indexed = Table.AddIndexColumn(data, "id", 1), | |
textId = Table.TransformColumnTypes(indexed, {{"id", type text}}), | |
body = [documents=Table.ReorderColumns(textId, {"id", "text"})], |
View RowExpression.From.pq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Value.FixType = (value, optional depth) => | |
let | |
nextDepth = if depth = null then 3 else depth - 1, | |
result = if depth = 0 then null | |
else if value is type then TextType(value) | |
else if value is table then Table.TransformColumns(value, {}, @Value.FixType) | |
else if value is list then List.Transform(value, each @Value.FixType(_, nextDepth)) | |
else if value is record then | |
Record.FromList(List.Transform(Record.ToList(value), each @Value.FixType(_, nextDepth)), Record.FieldNames(value)) |
View AzureTable.pq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section AzStorage; | |
[DataSource.Kind="TableStorage"] | |
shared TableStorage.Contents = (url) => | |
Text.FromBinary(Web.Contents(url, [Headers=SignRequest(url)])); | |
[DataSource.Kind="TableStorage"] | |
shared FileStorage.Contents = (url) => | |
Text.FromBinary(Web.Contents(url, [Headers=SignRequestBlob(url)])); |
View EnforceSchema.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
EnforceTypes = (table as table, schema as table) as table => | |
let | |
map = (t) => if t = type list or t = type record or t = type any then null else t, | |
mapped = Table.TransformColumns(schema, {"Value", map}), | |
omitted = Table.SelectRows(mapped, each [Value] <> null), | |
transforms = Table.ToRows(omitted), | |
changedType = Table.TransformColumnTypes(table, transforms) | |
in | |
changedType, |
View json.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
ByteToHex = (i as number) as text => | |
let | |
chars = "0123456789abcdef", | |
low = Text.Range(chars, Number.Mod(i, 16), 1), | |
high = Text.Range(chars, Number.RoundDown(i / 16), 1) | |
in high & low, | |
Json.EscapeChar = (text as text) as text => | |
if text = """" or text = "\" or text = "/" then "\" & text | |
else if Character.ToNumber(text) < 32 then "\u00" & ByteToHex(Character.ToNumber(text)) |
View gist:1917426
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UrlBuilder : IDynamicMetaObjectProvider | |
{ | |
/// <summary> | |
/// Usage: UrlBuilder.Build(url, key1: value1, key2: value2) | |
/// </summary> | |
/// <remarks> | |
/// values will be converted to strings via "ToString()". Any url-encoding must happen before | |
/// this method is called. Pass null as the value at runtime in order to omit the parameter | |
/// entirely. Use String.Empty for query parameters which should be present but have no value. | |
/// If url is a string, the result will be a string. If it is a System.Uri, the result will |
NewerOlder