Skip to content

Instantly share code, notes, and snippets.

Avatar

Tony McGovern tonmcg

View GitHub Profile
@tonmcg
tonmcg / convertToDate
Created Dec 21, 2020
Power Query M Function to Convert Milliseconds to Date (Datetime)
View convertToDate
(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
Convert to Power Query M Duration from JavaScript Milliseconds
View msToDuration
(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
SVG Transitions using Vue.js + GSAP
View README.md
@tonmcg
tonmcg / README.md
Last active May 1, 2019
SVG Attributes + Vue
View README.md

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

@tonmcg
tonmcg / README.md
Last active May 1, 2019
Moving Bubbles + Vue + GSAP + D3
View README.md

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 Jun 1, 2018
M Language JavaScript Functions
View FileSaver.html
<script type='text/javascript'>
document.write('Hello World!');
</script>
@tonmcg
tonmcg / Theme.ColorAPI.pq
Created May 29, 2018
M Language Custom Report Themes Functions
View Theme.ColorAPI.pq
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
M Language Custom Report Themes Functions
View Theme.PopularPalettes.pq
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 Dec 17, 2018
M Language Text Functions
View Text.IsAlphaNumeric
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
M Language XHR Functions
View UseJavaScript
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();
}
}