Skip to content

Instantly share code, notes, and snippets.

View tallpeak's full-sized avatar

Aaron William West tallpeak

View GitHub Profile
@tallpeak
tallpeak / Livecoding_and_IFsharp.ipynb
Last active August 29, 2015 14:11
Livecoding using IFsharp notebooks
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// from http://stackoverflow.com/questions/21194565/null-coalescing-operator-in-f
// modified to support DBNull
open System
let inline isNull value = obj.ReferenceEquals(value, null)
let inline isDBNull value = obj.ReferenceEquals(value, DBNull.Value)
type NullCoalesce =
static member Coalesce(a: 'a option, b: 'a Lazy) = match a with Some a -> a | _ -> b.Value
static member Coalesce(a: 'a Nullable, b: 'a Lazy) = if a.HasValue then a.Value else b.Value
@tallpeak
tallpeak / parsing.hs
Created November 22, 2016 15:44
Parsing Stuff in Haskell - London Haskell
-- https://www.youtube.com/watch?v=r_Enynu_TV0
-- Hey, I parsed the largest JSON on my hard drive!
import Text.ParserCombinators.Parsec hiding ((<|>),many)
import Control.Applicative
import Control.Monad
matchTrue :: Parser String
matchTrue = string "true"
alwaysTrue :: Parser Bool
-- decode.enable1.stm.hs
-- inspired by a word guessing game
-- https://www.futurelearn.com/courses/functional-programming-haskell/1/steps/116475
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString as B
import Data.Binary.Get
import Data.Word
# CreateExcelUnlocker.ps1
# Originally by Anton P. ([email protected])
# see http://lbeliarl.blogspot.com/2014/03/excel-removing-password-from-vba.html
# Powershell conversion by Aaron West, [email protected]
$strFile = "ExcelUnlockerFromPowershell.xlsm"
$strPath = "$($env:TEMP)\$strFile"
$xl = New-Object -ComObject Excel.Application
@tallpeak
tallpeak / LongestRunningQueries.vbs
Created November 16, 2017 21:43
LongestRunningQueries.vbs : a perf analysis tool for MS SQL 2005 and greater, posted to SqlServerCentral in 2006
'LongestRunningQueries.vbs
'By Aaron W. West, 7/14/2006
'Idea from:
'http://www.sqlservercentral.com/columnists/rcarlson/scriptedserversnapshot.asp
'Reference: Troubleshooting Performance Problems in SQL Server 2005
'http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx
Sub Main()
Const MinimumMilliseconds = 1000
Dim srvname
srvname = "." ' Feel free to place your most used servernname here
@tallpeak
tallpeak / longestrunningqueries.sql
Created November 16, 2017 21:56
Currently executing slow queries on SQL 2005 or greater
select
t1.session_id,
CASE WHEN t2.total_elapsed_time > 86400e3 THEN CAST(CAST(t2.total_elapsed_time/86400e3 AS DEC(5,1)) AS VARCHAR(7))+' days' ELSE SUBSTRING(CONVERT(VARCHAR(27),CONVERT(DATETIME,t2.total_elapsed_time/864e5),121),12,15) END AS elapsed,
-- t1.request_id,
t1.task_alloc,
t1.task_dealloc,
-- t2.sql_handle,
-- t2.statement_start_offset,
-- t2.statement_end_offset,
-- t2.plan_handle,
@tallpeak
tallpeak / getDriveCEncryptionPercentage.fsx
Last active November 29, 2017 21:24
Watch bitlocker encrypting a drive
// duplicating this PowerShell one-liner in F#:
// (Get-BitLockerVolume C:).EncryptionPercentage[1]
// Or perhaps this slightly longer version:
// while ($true) { Get-BitLockerVolume C: | %{ echo $_.EncryptionPercentage } |
// Tee-Object -FilePath c:\temp\bitlockerstatuslog.txt -Append ; [Console]::Out.Flush() ; sleep 1 }
#r "System.Management"
open System
open System.Management
open System.Linq
let strComputer = "."
let fn = @"C:\Enter\Your\Filename\Here.pbix"
open System.Text.RegularExpressions
#if INTERACTIVE
#r @"System.IO.Compression"
#r @"System.IO.Compression.FileSystem"
#endif
open System
open System.IO
open System.IO.Compression
// GeneratePbiImportModelQueriesFromDataSource.fsx
// Outline:
// Query tabular model metadata for all tables
// Build queries with DAX SUMMARIZECOLUMNS and PowerQuery's Table.RenameColumns
// open text file in notepad for user to paste from (and add FILTERs as desired)
// Usage: edit the two lines below, then run:
let tabServer = "SSAStabularServerName"
let tabDb = "SSAScatalog"