Skip to content

Instantly share code, notes, and snippets.

View random82's full-sized avatar

Dominik Raniszewski random82

View GitHub Profile
@random82
random82 / keybase.md
Created May 25, 2019 08:28
keybase.md

Keybase proof

I hereby claim:

  • I am random82 on github.
  • I am random82 (https://keybase.io/random82) on keybase.
  • I have a public key ASBsec_DylgAs7Y2U1gNgvCHmv7ZOFaoaI0kWiCRuOjbQQo

To claim this, I am signing this object:

@random82
random82 / encode-http-auth-header.pq
Last active April 3, 2019 02:57
Basic HTTP authorisation with PowerQuery
let EncodeBasicCredentials = (UserName, Password) =>
let
result = "Basic " & Binary.ToText(Text.ToBinary(#"UserName" & ":" & #"Password"),0)
in
result
in EncodeBasicCredentials
@random82
random82 / FinancialYear.md
Created March 5, 2019 02:02
Financial year reporting in PowerBI

Step 1 - Generate FY calendar table:

Approvals calendar = CALENDAR(
  IF(
    MONTH(NOW()) <= 6,
      DATE(YEAR(NOW())-1, 7, 1),
      DATE(YEAR(NOW()), 7, 1)
    ),
 IF(
@random82
random82 / DailyJobs.sql
Created March 4, 2019 02:22
Get last job in a day
;WITH cte_dailyJobs AS (
SELECT
DataLoadJobId,
LoadTime,
RANK() OVER(PARTITION BY CONVERT(date, LoadTime) ORDER BY LoadTime DESC) AS Rank
FROM [dbo].[DataLoadJob]
)
SELECT * FROM cte_dailyJobs WHERE Rank = 1
ORDER BY LoadTime DESC
@random82
random82 / Synchronize-AzureRmResourceProviders.ps1
Last active February 19, 2019 03:06
Synchrosing Azure Resource Providers across subscriptions
param(
[String]
$sourceAzureSubscriptionId,
[String[]]
$targetAzureSubscriptionIds
)
Select-AzureRmSubscription -Subscription $sourceAzureSubscriptionId
$registeredProviders = Get-AzureRmResourceProvider | Where {$_.RegistrationState -eq "Registered"}
@random82
random82 / importCsvToSql.py
Created February 6, 2019 03:23
Import CSV to MSSQL with Pandas - Python 3 version
from sqlalchemy import create_engine
import urllib
import pyodbc
import pandas as pd
df = pd.read_csv("./data.csv")
quoted = urllib.parse.quote_plus("DRIVER={SQL Server Native Client 11.0};SERVER=(localDb)\ProjectsV14;DATABASE=database")
engine = create_engine('mssql+pyodbc:///?odbc_connect={}'.format(quoted))
@random82
random82 / tableSha.sql
Created February 4, 2019 06:06
Generate SQL tables schema checksums
WITH cte_tableScripts AS (
SELECT
so.name AS TableName,
'CREATE TABLE [' + so.name + '] (' + o.list + ')' + CASE WHEN tc.Constraint_Name IS NULL THEN '' ELSE 'ALTER TABLE ' + so.Name + ' ADD CONSTRAINT ' + tc.Constraint_Name + ' PRIMARY KEY ' + ' (' + LEFT(j.List, Len(j.List)-1) + ')' END AS Script
FROM sysobjects so
CROSS apply
(SELECT
' ['+column_name+'] ' +
data_type + CASE data_type
WHEN 'sql_variant' THEN ''
@random82
random82 / ytd-total-budget.md
Last active December 19, 2018 01:46
DAX Pattern - % Actual YTD over total budget
% Actual vs Budget YTD OPEX = 
IF(
	ISFILTERED('Calendar'[Date]),
	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
	DIVIDE(
	TOTALYTD(
	    SUM('OPEX'[Actual]),
	    'Calendar'[Date].[Date]
	), 
@random82
random82 / ZipExtrator.cs
Last active January 31, 2018 22:58
U-SQL UDO Zip Extrator
using Microsoft.Analytics.Interfaces;
using System.Collections.Generic;
using System.IO;
namespace DocExtraction.Udo
{
[SqlUserDefinedExtractor(AtomicFileProcessing = true)]
public class ZipExtractor : IExtractor
{
private readonly bool _textMode;
@random82
random82 / PDFExtractor.cs
Created November 19, 2017 09:39
Basic PDFExtractor for Azure Data Lake Analytics
using System.Collections.Generic;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using Microsoft.Analytics.Interfaces;
namespace PDFExtractor
{
[SqlUserDefinedExtractor(AtomicFileProcessing = true)]
public class PDFExtractor : IExtractor
{