Skip to content

Instantly share code, notes, and snippets.

View tallpeak's full-sized avatar

Aaron William West tallpeak

View GitHub Profile
; find the combinations of letters which have the most anagrams
; word list is from
; https://raw.githubusercontent.com/dolph/dictionary/master/enable1.txt
(ns anagrams-sort
(:require [clojure.string :as cs]) )
(def words
(let [ home (System/getenv "HOME")
filename (str home "/Downloads/enable1.txt")
words (->> filename slurp cs/split-lines)
] words )
-- find the combinations of letters which have the most anagrams
import qualified Data.Map as M
import Data.List(words,sortBy,sort,groupBy,map,intercalate)
import Text.Printf(printf)
import System.Environment(getEnv)
type Anagrams = (Int,String,[String])
printer :: Anagrams -> IO ()
printer (len,sortword,words) = putStrLn $
-- based on
-- https://stackoverflow.com/questions/4522387/how-can-i-emulate-gos-channels-with-haskell
-- but this version encodes end-of-stream on the communication channel, as a Nothing
-- I could not get Intero or ghc to accept a type-annotation for the helper function,
-- even using the exact inferred type from Intero.
import Control.Monad (forM_)
import Control.Concurrent (forkIO, ThreadId, threadDelay)
-- based on
-- https://stackoverflow.com/questions/4522387/how-can-i-emulate-gos-channels-with-haskell
-- switched to TChan
-- still does not work right, because it requires a threadDelay between "generate" and "process",
-- of at least 30 to 3000 microseconds to finish queueing the input,
-- because the channel will be empty if the producer can't keep up with the consumer.
import Control.Monad (forM_)
import Control.Concurrent (forkIO, ThreadId, threadDelay)
import Control.Concurrent.STM.TChan (newTChan, readTChan, writeTChan, isEmptyTChan, TChan)
@tallpeak
tallpeak / go1.hs
Last active October 23, 2018 21:50
-- https://stackoverflow.com/questions/4522387/how-can-i-emulate-gos-channels-with-haskell/38277207#38277207
import Control.Monad
import Control.Concurrent (forkIO, ThreadId, threadDelay)
import Control.Concurrent.Chan (newChan, readChan, writeChan, Chan)
import Control.Concurrent.MVar (newMVar, swapMVar, readMVar, MVar)
data GoChan a = GoChan { chan :: Chan a, closed :: MVar Bool }
go :: IO () -> IO ThreadId
go = forkIO
// 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"
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
@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 = "."
@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 / 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