Skip to content

Instantly share code, notes, and snippets.

View deldersveld's full-sized avatar

David Eldersveld deldersveld

View GitHub Profile
@deldersveld
deldersveld / README.md
Created March 11, 2016 02:19
fresh block
@deldersveld
deldersveld / README.md
Last active May 3, 2016 13:46
stats tests
library(leaflet)
library(htmlwidgets)
library(webshot)
customPalette <- colorFactor(c("red", "red", "navy", "#00274c"), domain = dataset$OwnerType)
m <- leaflet(data = dataset) %>%
setView(-85.5, 42.3, zoom = 6) %>%
addProviderTiles("CartoDB.Positron") %>%
addCircleMarkers(~Longitude, ~Latitude, radius = ~ifelse(OwnerType == "Private", 1, 3), color = ~customPalette(OwnerType), stroke = FALSE, fillOpacity = 0.8)
/*
double #map required for map to appear in FF,Edge,IE (and I have no idea why)
final map should appear as fixed 60% width
fixed for scrolling story pane
top 55px because it covers up the Export button in DevTools...
*/
#map {
position:absolute;
top:20px;
bottom:0;
@deldersveld
deldersveld / Power BI Sample Bar Chart Custom Visual.md
Last active October 26, 2021 11:45
Sample Power BI bar chart custom visual adapted from https://bl.ocks.org/mbostock/3885304

Sample Power BI bar chart custom visual adapted from https://bl.ocks.org/mbostock/3885304

  • Follow the instructions at https://github.com/Microsoft/PowerBI-visuals-docs to install the Power BI Custom Visual CLI Tool
  • Follow the steps on the same site to create a new visual and install the typings for D3
  • Copy and paste the code from this gist's "visual.ts" into "src/visual.ts"
  • Copy and paste the code from this gist's "visual.less" into "style/visual.less"
  • Start the visual in CLI and view it using the Developer Visual in Power BI service

Adapting a visual like this from a static D3 example is not a simple matter of copying and pasting. If you look through the original D3 example and compare it with the Power BI version, you will see some changes where the original was split between constructor() and update(). The original D3 also only used enter(), but for a dynamic visual in Power BI, code for transition() and exit() were also added. Some other tweaks were needed to get it working decently

@deldersveld
deldersveld / R-Syuzhet-Sentiment-for-Power-BI.R
Last active September 23, 2016 13:23
R script that compares sentence/phrase sentiment using various lexicons from the Syuzhet package. Script is geared toward Microsoft Power BI with the "dataset" data frame, but it can easily be adapted for any data frame.
bing.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="bing")
afinn.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="afinn")
nrc.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="nrc")
raw <- cbind(bing.sentiment, afinn.sentiment, nrc.sentiment)
scaled <- scale(raw, center=TRUE)
colnames(scaled) <- c("bing.scaled", "afinn.scaled", "nrc.scaled")
sentiment.output <- cbind(dataset, raw, scaled)
@deldersveld
deldersveld / PowerBI-CustomHTMLTooltip
Last active March 7, 2017 18:14
Use this code in a Power BI calculated column to enhance the default tooltip in the ArcGIS Maps for Power BI visual
HTML Tooltip = "<img src='https://www.blue-granite.com/hs-fs/hub/257922/file-2333776730-png/IMG_2015/Blue-Granite-Logo.png' width='200px' /><br>" &
"<br>Reported: <em>" & Table1[OutageReported] & "</em>" &
"<br>Restoration Est: <em>" & Table1[RestorationEstimate] & "</em>" &
"<br><br><table bordercolor='#FFFFFF' cellspacing='8'><tr>" &
"<th style='color:#01B8AA;'>Customers Affected</th><th style='color:#01B8AA;'>Status</th></tr><tr>" &
"<td style='color:#" & IF(Table1[Number of Customers Affected] > 50,"DD0000","FFFFFF") & ";'>" & Table1[Number of Customers Affected] & "</td>" &
"<td>" & Table1[Status] & "</td></tr></table>"
@deldersveld
deldersveld / PowerBI-PercentOfGrandTotal
Created October 15, 2016 11:39
Some DAX snippets for % of Grand Total
//Single measure version
% of Total = DIVIDE(SUM('Sales'[Revenue]), CALCULATE(SUM('Sales'[Revenue]), ALLSELECTED('Product'[Category])))
//As traced in Power BI Quick Calc "% of Grand Total"
EVALUATE
TOPN(
1001,
SUMMARIZECOLUMNS(
'Product'[Category],
"M0", CALCULATE(
@deldersveld
deldersveld / ATUS-ActivityLexicon.pq
Last active February 2, 2024 14:29
American Time Use Survey - Activity Lexicon from PDF
let
FilePath = "[replace with folder path]\tabula-lexiconnoex0315.csv",
Source = Csv.Document(File.Contents(FilePath),[Delimiter=",", Columns=6, Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
#"Removed Top Rows" = Table.Skip(Source,1),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([#"Major #(cr)category"] <> "ATUS 2003-2015 Activity coding lexicon" and [#"Major #(cr)category"] <> "Major #(cr)category")),
#"Replaced Value" = Table.ReplaceValue(#"Filtered Rows","",null,Replacer.ReplaceValue,{"Major #(cr)category", "First and #(cr)second-tier #(cr)categories"}),
#"Filled Down" = Table.FillDown(#"Replaced Value",{"Major #(cr)category", "First and #(cr)second-tier #(cr)categories"}),
#"Filtered Rows1" = Table.SelectRows(#"Filled Down", each ([#"6-digit #(cr)activity #(cr)code"] <> "")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"", "_1"})
@deldersveld
deldersveld / RemoveAzureBlobContainerByPrefix.ps1
Created January 3, 2018 17:03
Remove all blob containers and child blobs based on the specified container name prefix
Login-AzureRmAccount
$containerPrefix = <<string containing prefix to search. wildcard character not needed after prefix.>>
$storageContext = New-AzureStorageContext -ConnectionString <<connection string to storage account>>
Get-AzureStorageContainer -context $storageContext -prefix $containerPrefix | ForEach-Object {Remove-AzureStorageContainer -context $storageContext -Container $_.Name -Force}