Author Archives: Octopusgrabbus

About Octopusgrabbus

Works as a programmer in municipal information technology, performing database and web programming, systems integration, and data conversion.

A Nice Oracle Post

I don’t use Oracle, but this is a well-written post on performance. Bon Apetit!

Leave a comment

Filed under database, SQL

Before and After 2016 Election

From twitter ‏@langeIand :

1 Comment

Filed under Humor, Musings

F# Free Disk Space

So, here is a small, F# program to report on disk usage. This is from a real example on our Munis server.


(*
A simple checker of Windows disks.
Charles M. Norton   11/01/2016
Will be greatly improved over time.

Modifications
Charles M. Norton   11/1/2016
Initial version.
*)

open System
open System.Text
open System.Net.Mail
open System.IO
open System.Threading

open Toa.volLib // local library

let SendEmail msg =
use msg =
new MailMessage (
"dbadmin@town.arlington.ma.us", @"itadmin@town.arlington.ma.us", @"Munis Server Disk Space Report\n",
msg )

use client = new SmtpClient(@"webmail.town.arlington.ma.us")
client.DeliveryMethod client.Credentials client.Send msg

let main argv =
let localDriveList = driveList ()
let dn = (Seq.head(localDriveList)).Name

let drive_c = (Seq.head(localDriveList)).Name
let data_drive = (Seq.nth(1) localDriveList).Name

let fs_c = freeSpace drive_c
let fs_d = freeSpace data_drive

let gb_c = cvtBytesToGB fs_c
let gb_d = cvtBytesToGB fs_d

let system_name = System.Environment.MachineName

let strings = ["System name: "; system_name; "Volume "; drive_c; gb_c.ToString(); "GB\n"; "Volume"; data_drive; gb_d.ToString(); "GB\n"]
let gbs = String.concat " " strings
printfn "System name: %A: Drive C %f -- Data Drive %f" system_name gb_c gb_d

if gb_c < volLib.GB5 || gb_d < volLib.GB5 then printfn "Disk free space is below thresholds; send out warning email." SendEmail gbs else printfn "Disk free space is at or above thresholds. All is well, at least for now." printfn "Sleeping 5 seconds to let you read." Thread.Sleep 5000 |> ignore
0 // return an integer exit code

Leave a comment

Filed under F#

A Utilitarian F# Library

I started building an F# library that could be used to hold housekeeping routines. This is the start of that library.

namespace Toa.volLib
open System
open System.Threading
open System.Collections.Generic
open System.Text
open System.IO
open Microsoft.Win32

type DiskFreeLevels =
  | GB1   = 1000000000L
  | GB5   = 5000000000L
  | GB10  = 10000000000L

[<AutoOpen>]
module volLib =
  let libInit = ref false

  let driveList () =
    DriveInfo.GetDrives()

  let freeSpace drive =
    let di = DriveInfo(drive)

  if di.IsReady then int64(di.AvailableFreeSpace)
  else int64(DiskFreeLevels.GB10)

  let cvtBytesToGB (inBytes:int64) =
    truncate((float(int64(inBytes)) / float(1024L) / float(1024L)) / float(1024L))

  let GB1     = cvtBytesToGB(int64(DiskFreeLevels.GB1))
  let GB5     = cvtBytesToGB(int64(DiskFreeLevels.GB5))
  let GB10    = cvtBytesToGB(int64(DiskFreeLevels.GB10))

Leave a comment

Filed under F#

F#: Reading From Console

open System

let readInput() =
   Seq.initInfinite (fun _ -> Console.ReadLine())
   |> Seq.takeWhile (fun s -> not (s.Equals("")))
   |> Seq.map int

There are a lot of ways to read information from the console, and with GUIs
having been around a long time, console I/O is not as big a deal as it
was years ago. For F#, this seems to be a good way to read integers from the command line, and then convert them from ASCII to int.

From a sequence, conversion is possible to an array or list.

Leave a comment

Filed under F#

Buzzards Inc.

It finally happened. With the exception of local stores, like your favorite restaurant, fabric, hardware,  or your mechanic, all large companies are beginning to blur in my mind. I cannot seem to tell them apart.

Whether it is a company that produces products for the utility sector, home and automobile insurance, or specialized software for government, to me, they might as well just be one large company. Their behavior seems to be merging into a set of common behaviors.

Here are some of the telltale signs this is happening.

  1. It is almost impossible to reach someone on the phone. Most companies have had phone menus for many years, but now, these menus seem protected with nearly impenetrable armor. You’ll be prompted with questions to get you past a checkpoint. Some of these questions could easily be used on Jeopardy.
  2. To solve a problem, like you want some information sent by mail, you are presented with impossibilities that would give master players of the original Adventure game fits. You are told that this other department cannot send you that information, because they cannot see it.
  3. Support personnel are reading from a script: “Well, you need to adjust the spark advance and fuel mixture.” Your car does not have settings for spark and fuel, but a 1926 Rolls Royce might.

So, I am thinking it might just be easier to have one company with a suitable name. The Three Stooges had the right idea, with Panther Brewing Company, A Panther President.

Leave a comment

Filed under rants

So an F# Sequence Should Stick Around For a While

If you create a sequence in Clojure, the sequence sticks around within the scope of its creation. That is, once a Clojure sequence is created and bound to a var, nothing special has to be done to make sure its contents stick around. This is not so with F#.

Take this program


open System
open System.Collections.Generic
open System.Text
open System.IO
#nowarn "40"

let rec readLines () =
    seq {
    let line = Console.ReadLine()
    if not (line.Equals("")) then
           yield Int32.Parse(line)
           yield! readLines ()
    }

[<EntryPoint>]
let main argv =
    let inSeq = readLines ()    

    inSeq

    |> Seq.length

    |> printfn "%d lines read"

    // This will keep it alive enough to read your output
    Console.ReadKey() |> ignore
    0

Because of a sequences’ inherent laziness, the reading in of numbers does not begin until inSeq’s length is computed. Without caching inSeq, you will have to read the integers in again if you want to iterate the sequence, unless this change is made


let inSeq = readLines () |> Seq.cache

Leave a comment

Filed under Clojure, F#

Generating F# Sequences From Console Input

I got a very nice answer on SO to why a function was not executing.


open System
open System.Collections.Generic
open System.Text
open System.IO
#nowarn "40"

let rec readlines () =
     seq {
           let line = Console.ReadLine()
           if not (line.Equals("")) then
              yield line
              yield! readlines ()
}

[<EntryPoint>]
let main argv =
      let inSeq = readlines ()

      inSeq
      |> Seq.length
      |> printfn "%d lines read"

      // This will keep it alive enough to read your output
      Console.ReadKey() |> ignore
      0

Leave a comment

Filed under F#

The Sugar Coated Documentary

In May of this year, I came across an interesting documentary on Netflix. Then I recently heard about one of the people mentioned in the documentary, a dentist in San Fransisco in an NPR news story.

Even if you disagree with the documentary, at least it might make you think. Oh, and I did enjoy birthday cake several times this Summer. I am not a monk.

Leave a comment

Filed under Health

Nice F# List.fold example

Got this example from here.


open System
open System.Threading
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open System.IO
open Microsoft.VisualBasic.FileIO


let main argv =
   let data = [(Cats,4);
               (Dogs,5);
               (Mice,3);
               (Elephants,2)]

   let count = List.fold (fun acc (nm,x) acc+x) 0 data
   printfn "Total number of animals: %d" count


Even though I’ve used map and other functions in Clojure, I’ve forgotten the basics of an inline function. The value of 0 is assigned to nm, and x takes on the first row of data.

 

Leave a comment

Filed under F#