Skip to content

Instantly share code, notes, and snippets.

View anton-dudarev's full-sized avatar
🎯
Focusing

Anoubis anton-dudarev

🎯
Focusing
View GitHub Profile
@anton-dudarev
anton-dudarev / fnJsonToTable.pq
Last active September 5, 2020 11:50 — forked from Hugoberry/JSON2table.m
JSON to Table in Power Query M
(json) => 
  let
    //List the expandable columns
    expandableColumns = (_) => List.Accumulate(
        Table.ColumnNames(_), 
        {}, 
        (s, c) => 
          s
            & (
            if Type.Is(Value.Type(Record.Field(_{0}, c)), type record)
@anton-dudarev
anton-dudarev / PowerQueryThief.ts
Created September 5, 2020 11:44 — forked from Hugoberry/PowerQueryThief.ts
Displays all of the Power Query M scripts from the opened instances of Power BI. (ignore the ts extension, this is an M script:)
let
//Declaring compact function
MSMDSRVport = () => let cu=Table.FirstN(Table.Sort(Folder.Contents("C:\Users"),{{"Date accessed",Order.Descending}}),1)[Name]{0} in List.Transform(Table.SelectRows(Folder.Files("C:\Users\"&cu&"\AppData\Local\Microsoft\Power BI Desktop\AnalysisServicesWorkspaces"),each [Name]="msmdsrv.port.txt")[Content],each Lines.FromBinary(_,null,null,1200){0}),
GetConnectionString = (port) => let c=AnalysisServices.Databases("localhost:"&port)[Name]{0} in AnalysisServices.Database("localhost:"&port,c,[Query="select * from $system.TMSCHEMA_DATA_SOURCES"])[ConnectionString],
ConnectionString2Bin = (cs) => let sp=Splitter.SplitTextByDelimiter(";") in Binary.FromText(Text.Replace(Text.Replace(List.Last(sp(cs)),"Mashup=",""),"mashup=","")),
Unz = (bZ,fN) => let UInt32=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32,ByteOrder.LittleEndian),UInt16=BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),H=BinaryFormat.Record([MH=BinaryFormat.Binary(1
@anton-dudarev
anton-dudarev / setParameters.ts
Created September 5, 2020 11:05 — forked from Hugoberry/setParameters.ts
[Power Query] Replace an unary function type with a custom type that contains metadata for allowed parameter values
(f as function, allowedValues as list)=>
let
//create a new parameter type with metadata for allowed values
parameterType = Value.Type(allowedValues{1}) meta [Documentation.AllowedValues = allowedValues],
//create a function type with custom parameter type
myFunType = type function (select as parameterType) as function
in //replace the orginal function type with the new myFunType
Value.ReplaceType(f,myFunType)
@anton-dudarev
anton-dudarev / settings.jsonc
Last active October 9, 2020 04:36
Microsoft Terminal Settings
// This file was initially generated by Windows Terminal 0.11.1191.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@anton-dudarev
anton-dudarev / xmlPath.pq
Created January 20, 2020 16:10 — forked from Hugoberry/xmlPath.pq
[Power Query] return the table at the end of the path eg. xmlPath(XML,{"auditfile","customersSuppliers","customerSupplier"})
(xml as table, path as list)=>
let
isEmptyTable = each Type.Is(Value.Type(_), Table.Type) and List.Count(Table.ToRows(_))=0,
xmlRow2record = (rec, row) => Record.AddField(rec,row{0},if isEmptyTable(row{2}) then null else row{2}),
xmlTableExpandNode = (xmlTable, node) => List.Accumulate(Table.SelectRows(xmlTable, each [Name] = node)[Value],#table(1,{}),(s,c)=>s&c),
head = List.RemoveLastN(path,1),
tail = List.Last(path),
exceptTail = List.Accumulate(head,xml,xmlTableExpandNode),
tailRecords= List.Transform(Table.SelectRows(exceptTail, each [Name]=tail)[Value],each List.Accumulate(Table.ToRows(_),[],xmlRow2record)),
out = Table.FromRecords(tailRecords)
let func =
(SelectionList as list, ListOfPositions as list, optional StartWithOne as number) =>
let
selectionList = List.Buffer(SelectionList),
listOfPositions = List.Buffer(ListOfPositions),
StartPosition = if StartWithOne = 1 then -1 else 0,
Result = List.Transform(ListOfPositions, each SelectionList{_ + StartPosition}?)
in
$InFile = 'Filename.txt'
$OutFile = 'Filename2.txt'
filter replace-chars { $_ -replace '\^',';' }
if (test-path $OutFile)
{ Clear-Content $OutFile }
Get-Content $InFile -ReadCount 1000 |
replace-chars |
@anton-dudarev
anton-dudarev / Get-PublicIPInfo.ps1
Created December 29, 2019 12:48 — forked from AndrewPla/Get-PublicIPInfo.ps1
Returns Public IP info from ip.nf Can be ran on remote computers
function Get-PublicIPInfo {
<#
.Description
Returns Public IP info from ip.nf
.Parameter IPAddress
Supply an IP address that you would like to lookup.
.Parameter ComputerName
Names of computers to run this command on.
.Parameter Credential
Credential used by Invoke-Command when performing the lookup on a remote machine.
@anton-dudarev
anton-dudarev / New-TempDirectory
Created December 29, 2019 12:48 — forked from AndrewPla/New-TempDirectory
Cross-platform function to create temp folders. Created by Justin Grote https://twitter.com/JustinWGrote/status/1190311627746267136
function New-TempDirectory {
$pathToCreate = join-path ([io.path]::GetTempPath()) ([io.path]::GetRandomFileName())
New-Item -ItemType Directory -Path $pathToCreate
}
@anton-dudarev
anton-dudarev / index.js
Created May 25, 2019 22:20 — forked from JaldeepAsodariya/index.js
HelloThings - A Firebase Cloud Function for manage webhook request from Dialogflow for Turn On/Off LED light.
'use strict';
process.env.DEBUG = 'actions-on-google:*';
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
const functions = require('firebase-functions');
const Assistant = require('actions-on-google').ApiAiAssistant;
const admin = require('firebase-admin');