Skip to content

Instantly share code, notes, and snippets.

View Hugoberry's full-sized avatar

Igor Cotruta Hugoberry

View GitHub Profile
@Hugoberry
Hugoberry / Tabluar.xml
Created March 7, 2017 12:55
Hidden Tabular SSAS specific DMVs
<Batch Transaction="false" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>TMSCHEMA_MODEL</RequestType>
<Restrictions>
<RestrictionList>
<DatabaseName>b7b2993d-570b-4c92-9e5d-d5e8f72c935d</DatabaseName>
</RestrictionList>
</Restrictions>
<Properties>
<PropertyList/>
@Hugoberry
Hugoberry / RemovePassword.m
Created March 9, 2017 16:30
Fetching Remove Password comments from Github. Using Power Query and R
let
header = [#"Accept"="application/vnd.github.cloak-preview"],
response = Web.Contents("https://api.github.com/search/commits?q=remove password",[Headers=header]),
json = Json.Document(response),
select = Table.SelectColumns(Table.FromRecords(json[items]),{"url","commit","repository"}),
expand_commit = Table.TransformColumns(Table.ExpandRecordColumn(select, "commit", {"committer", "message"}),{"message",each Text.Clean(_) }),
expand_commiter = Table.ExpandRecordColumn(expand_commit, "committer", {"date", "name", "email"}),
expand_repo = Table.ExpandRecordColumn(expand_commiter, "repository", {"html_url"}),
commits = Table.AddColumn(expand_repo, "commit", each Json.Document(Web.Contents([url]))),
files = Table.ExpandListColumn(Table.ExpandRecordColumn(commits, "commit", {"files"}),"files"),
@Hugoberry
Hugoberry / ReadRZip.m
Created March 9, 2017 23:42
Reading a Zip file in Power Query via R
let
RScript = R.Execute("datacsv<-read.csv(unz(""d:\\Downloads\\R_Twitter_sample.zip"",""R_Twitter_sample.csv""))"),
out = RScript{[Name="datacsv"]}[Value]
in
out
@Hugoberry
Hugoberry / 10MlinesToCSV.m
Created March 9, 2017 23:54
Writing 10M lines of a query result to a table in Power Query via R
let
seed = {1..10000000},
seedTable = Table.FromList(seed, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
RScript = R.Execute("write.csv(dataset,""d:\\Downloads\\out.csv"")",[dataset=seedTable]),
out = RScript
in
out
@Hugoberry
Hugoberry / STOUTin.m
Created March 11, 2017 11:03
STDOUT as data source in Power Query M
let
RScript = R.Execute("output <- read.table(text=system2(""whoami"", stdout=TRUE))"),
output = RScript{[Name="output"]}[Value]
in
output
@Hugoberry
Hugoberry / msmdsrvr.r
Created March 12, 2017 20:56
Getting $Embedded$ connection details in Power Query via R
##Get msmdsrv process details
msmdsrv_proc <- system2("tasklist",args = c('/fi','"imagename eq msmdsrv.exe"'), stdout=TRUE)
msmdsrv_clean<-msmdsrv_proc[-c(1,3)]
msmdsrv<-read.fwf(textConnection(msmdsrv_clean),widths=c(25,9,17,12,13),comment.char="")
##Get all TCP ports
tcp <- system2("netstat", args = c('-anop','TCP'), stdout=TRUE)
ports<-read.fwf(textConnection(tcp),skip=3,widths=c(9,23,23,16,10))
let
Source = #table(null,{{1}}),
RScript = R.Execute("output<-dataset #(lf)msmdsrv_proc <- system2(""tasklist"",args = c('/nh','/fi','""imagename eq msmdsrv.exe""'), stdout=TRUE) #(lf)msmdsrv_pid <- strsplit(msmdsrv_proc[2],""\\s+"")[[1]][2]#(lf)msmdsrv_regex <- paste(c(""ESTABLISHED\\s*"", msmdsrv_pid),collapse="""")#(lf)tcp <- system2(""netstat"", args = c('-ano'), stdout=TRUE) #(lf)msmdsrv_connections<-grep(msmdsrv_regex,tcp,value=TRUE)#(lf)msmdsrv_inbound<-strsplit(strsplit(msmdsrv_connections[1],""\\s+"")[[1]][3],"":"")[[1]] #(lf)output$port<-tail(msmdsrv_inbound,n=1)",[dataset=Source]),
out = RScript{[Name="output"]}[Value]
in
out
@Hugoberry
Hugoberry / msmdsrvPORT.M
Created March 13, 2017 00:24
Power Query script to get msmdsrv.exe port number via R
let
RScript = R.Execute("msmdsrv_proc <- system2(""tasklist"",args = c('/fi','""imagename eq msmdsrv.exe""'), stdout=TRUE) #(lf)msmdsrv_clean<-msmdsrv_proc[-c(1,3)]#(lf)msmdsrv<-read.fwf(textConnection(msmdsrv_clean),widths=c(25,9,17,12,13),comment.char="""")#(lf)tcp <- system2(""netstat"", args = c('-anop','TCP'), stdout=TRUE)#(lf)ports<-read.fwf(textConnection(tcp),skip=3,widths=c(9,23,23,16,10))"),
formatTable = (T) => Table.PromoteHeaders(Table.TransformColumns(T,{{"V1",Text.Trim},{"V2",Text.Trim},{"V3",Text.Trim},{"V4",Text.Trim},{"V5",Text.Trim}})),
msmdsrv = formatTable(RScript{[Name="msmdsrv"]}[Value]),
ports = formatTable(RScript{[Name="ports"]}[Value]),
match = Table.SelectRows(ports, each [PID]=Table.ToRecords(msmdsrv){0}[PID]){0}[Local Address],
out = List.Last(Text.Split(match,":"))
in
out
@Hugoberry
Hugoberry / Number.DEC2BIN.m
Last active March 15, 2017 17:30 — forked from IvanBond/Number.ToBinaryString.m
DEC2BIN or HEX2BIN in Power Query M
(num as number)=>
List.Last(
List.Generate(
() =>[reminder = num,
binString= Number.ToText(Number.BitwiseAnd(reminder,1))],
each [reminder]> 0,
each [reminder = Number.BitwiseShiftRight([reminder],1),
binString= Number.ToText(Number.BitwiseAnd(reminder,1))&[binString]],
each [binString]
)
@Hugoberry
Hugoberry / PowerQueryThief.ps1
Last active March 20, 2017 15:24
Extracting Power Query queries
#Finding the portnumber on which the $Embedded$ tabular model is running on
$embedded = "$env:LOCALAPPDATA\Microsoft\Power BI Desktop\AnalysisServicesWorkspaces"
$ports = Get-ChildItem $embedded -rec | where {$_.Name -eq "msmdsrv.port.txt"}
$port = Get-Content $ports.FullName -Encoding Unicode
#Getting the data sources from the $Embedded$ tabular model
[xml] $db = Invoke-ASCmd -Server:localhost:$port -Query:"SELECT * from `$SYSTEM.TMSCHEMA_DATA_SOURCES"
$db.return.root.row
$cs = $db.return.root.row.ConnectionString