Skip to content

Instantly share code, notes, and snippets.

View tonmcg's full-sized avatar

Tony McGovern tonmcg

View GitHub Profile
@tonmcg
tonmcg / convertToDate
Created December 21, 2020 19:20
Power Query M Function to Convert Milliseconds to Date (Datetime)
(milliseconds as any, optional returnDateTime as nullable text) =>
let
result =
if milliseconds <> null then
let
javaScriptBaseDate = #datetime(1970,1,1,0,0,0),
//milliseconds = 1576483200000,
isDateTime = if returnDateTime = "false" or returnDateTime = "" then false else true,
seconds = milliseconds / 1000,
durationInSeconds = #duration(0,0,0,seconds),
@tonmcg
tonmcg / msToDuration
Last active May 6, 2020 09:06
Convert to Power Query M Duration from JavaScript Milliseconds
(s as number) as duration =>
let
// patterned after https://stackoverflow.com/a/9763769/4637650
// s = 28860000, //481 minutes
ms = Number.Mod(s,1000),
t = (s - ms) / 1000,
secs = Number.Mod(t,60),
r = (t - secs) / 60,
mins = Number.Mod(r,60),
hrs = (r - mins) / 60,
@tonmcg
tonmcg / README.md
Last active May 8, 2019 20:52
SVG Transitions using Vue.js + GSAP
@tonmcg
tonmcg / README.md
Last active October 19, 2022 13:57
SVG Attributes + Vue

Using Vue.js to adjust properties on an SVG element.

@tonmcg
tonmcg / README.md
Last active January 4, 2024 06:50
Moving Bubbles + Vue + GSAP + D3

This visualization tracks a sample of couples in the 1970's to show how long they transition through relationship stages. It is wholly based on Nathan Yau's The Stages of Relationships, Distributed and his companion tutorial How to Make a Moving Bubble Chart, Based on a Dataset (note: you'll need a FlowingData membership to view this tutorial.)

Nathan's example uses D3.js to get the data, render the text and circles, simulate physical forces, apply transitions and animations, and update DOM elements. This example uses the browser's native Fetch API to get the data, Vue.js instance lifecycle statges to update the data and render the circles and text; GSAP to transition and animate SVG circle

@tonmcg
tonmcg / FileSaver.html
Created June 1, 2018 15:07
M Language JavaScript Functions
<script type='text/javascript'>
document.write('Hello World!');
</script>
@tonmcg
tonmcg / Theme.ColorAPI.pq
Created May 29, 2018 13:52
M Language Custom Report Themes Functions
let
Theme.ColorAPI = (hexColorCode as text, optional numberOfColors as number) =>
let
number = if numberOfColors is null then 11 else numberOfColors,
Source = Json.Document(Web.Contents("http://www.thecolorapi.com/scheme?hex=" & hexColorCode & "&mode=analogic-complement&count=" & Number.ToText(number))),
colors = Source[colors],
ConvertedToTable = Table.FromList(colors, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ExpandedColors = Table.ExpandRecordColumn(ConvertedToTable, "Column1", {"hex", "rgb", "hsl", "hsv", "name", "cmyk", "XYZ", "image", "contrast", "_links", "_embedded"}, {"hex", "rgb", "hsl", "hsv", "name", "cmyk", "XYZ", "image", "contrast", "_links", "_embedded"}),
ExpandedHex = Table.ExpandRecordColumn(ExpandedColors, "hex", {"value"}, {"value"}),
colorName =
@tonmcg
tonmcg / Theme.PopularPalettes.pq
Last active May 28, 2018 17:43
M Language Custom Report Themes Functions
let
Theme.PopularPalettes = (palette as text) as text =>
let
Source = Text.Clean(Web.BrowserContents("http://www.color-hex.com/color-palettes/popular.php/")),
colorPalettes = Table.FromList(
List.Generate(
()=>
[
n = 0,
title = Text.BetweenDelimiters(Source,"""clearfix""></div></div>","</a>",n),
@tonmcg
tonmcg / Text.IsAlphaNumeric
Last active December 17, 2018 13:29
M Language Text Functions
let
Text.IsAlphaNumeric = (string as text) =>
let
// ASCII representation of numbers 0-9 and letters a-z and A-Z only
// analogous to the regex "^[a-zA-Z0-9]*$"
ASCIIList = List.Transform({48..57,65..90,97..122}, each Character.FromNumber(_)),
textLength = Text.Length(string),
isAlphaNumeric = // does the string contain only numbers and letters
List.Generate(
()=>
@tonmcg
tonmcg / UseJavaScript
Created May 24, 2018 00:55
M Language XHR Functions
let
javascriptDates = Web.Page("
<script type='text/javascript'>
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}