Skip to content

Instantly share code, notes, and snippets.

View tallpeak's full-sized avatar

Aaron William West tallpeak

View GitHub Profile
@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
-- 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)
-- 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)
-- 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 $
; 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 )
-- 1) Upgraded to Data.Time 2) Added some timings. 3) 10 million.
-- Otherwise unchanged
-- Result: 14 seconds versus 70 seconds for List.sort, 2.1 GB ram used
-- google: haskell etl
-- > https://www.reddit.com/r/ocaml/comments/3ifwe9/what_are_ocamlers_critiques_of_haskell/
-- > https://www.reddit.com/r/haskell/comments/3inqzk/an_optimal_haskell_quicksort/
-- > http://flyingfrogblog.blogspot.com/2010/08/parallel-generic-quicksort-in-haskell.html
{-# LANGUAGE FlexibleContexts #-}
-- import System.Time
@tallpeak
tallpeak / exportProcs.fsx
Last active November 7, 2019 19:48
Script all stored procedures for all MSSQL databases for select servers
// edit these lines for your liking:
let servers = ["server1"; "server2"]
let baseDir = @"c:\temp"
let getConnectionString (serverName:string) =
sprintf @"Data Source=%s;Initial Catalog=master;Integrated Security=True" serverName
#I """../exportProcs\packages\System.Data.SqlClient\lib\net461"""
#r """System.Data.SqlClient.dll"""
@tallpeak
tallpeak / CIMS_AIMS_4yr.jl
Created January 16, 2020 06:28
export some data from SQL to XLSX using Julia
import DataFrames, XLSX
getsqlpass() = string(strip( open(h->read(h,String), "/home/aaron/secrets/sqlpassword") ,['\r','\n',' ','\t']))
import ODBC
coals = [("CIMS",1016),("AIMS",1019)]
asv = ["A","v"]
yr = 20
for (coalName,coalNum) in coals
for aors in asv
tn = string("top_", coalName, "_sales_", aors)
@tallpeak
tallpeak / CompareDirectories.fsx
Last active February 4, 2020 18:27
Compare directories
// compare.fsx
// for each file, get name-only and hash.
// eliminate files with matching hashes
// display differences for files with the same name-only
// display files not found in destination by name-only
// display files not found in source by name-only
let srcDir = @"C:\temp\xxxx_ProductionInitializeDeploymentScripts"
let destDir = @"C:\Users\[myusername]\Source\Repos\[DH-ODP]\Main\Scripts"
open System
@tallpeak
tallpeak / extsum.jl
Created May 19, 2020 16:18
Summary of file sizes for a directory tree, by extension
using Printf
using Formatting
d=Dict{String, Integer}()
for (root, dirs, files) in walkdir(".")
for file in files
ff=joinpath(root, file)
fs=filesize(ff)
ar=rsplit(file,".";limit=2)
ext=pop!(ar)