Birthday Wishes [Mine]

Some people my age want a sports car, but can you really enjoy racing down Mass Ave in a Prius? Besides, I work closely with my municipality’s police and fire departments. Drag racing would make things difficult.

Some people my age, want to do something like climb a mountain. I do not think my cardiologist would approve, and I would like to live long enough to complain about old age.

No, other than a new pair of sneakers for the gym, I want a facsimile of The IBM Model-M keyboard. It’s the sound it makes, safer than roaring up Mass Ave, and less expensive in court cases and speeding fines.

Leave a comment

Filed under Technology

Creating an all-in-one .Net Executable

I discovered a nice utility that accompanies Visual Studio; at least it is in Visual Studio 2015. It is called ilmerge. It specific purposes is to fold an executable along with any dependent DLLs into a new executable that requires no external dependencies. You might need this for those time when you want a single executable on, say, a remote system.

Here is a command that binds two .Net libraries, one a distributed Microsoft API and the other is part of my program.


ilmerge /log:ilmerge.log `
/lib:C:\Windows\Microsoft.NET\Framework\v4.0.30319 `
/target:winexe /targetplatform:v4 `
/out:FreeBytesC.exe `
/ndebug FreeBytes.exe `
FreeBytes.exe FSharp.Core.dll VolLib.dll

Leave a comment

Filed under .Net Languages, F#

FreeBytes.exe (Disk Checker) Revisited

The library and application have been updated to be a little more flexible and take a parameter, so that the minimum free space does not have to be hard-coded into the program.

Here is VolLib, an F# library:

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

type DiskFreeLevels =
           | DRIVE_OFF_LINE = -1L
           | GB1   = 1000000000L
           | GB5   = 5000000000L
           | GB10  = 10000000000L
           | GB20  = 20000000000L

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

  let drive_list () =
    DriveInfo.GetDrives()

  // Takes a string representation of a drive, and pulls out its free space.
  let free_space drive =
      let di = DriveInfo(drive)
      if di.IsReady then
int64(di.AvailableFreeSpace)
      else
int64(-1)

      // Just convert bytes to gigabytes.
      let cvt_bytes_to_gb (in_bytes:int64) =
        int64(truncate((float(int64(in_bytes)) / float(1024L)
/ float(1024L)) / float(1024L)))

        let DRIVE_OFF_LINE = int64(-1)
        let GB1     = cvt_bytes_to_gb(int64(DiskFreeLevels.GB1))
        let GB5     = cvt_bytes_to_gb(int64(DiskFreeLevels.GB5))
        let GB10    = cvt_bytes_to_gb(int64(DiskFreeLevels.GB10))
        let GB20    = cvt_bytes_to_gb(int64(DiskFreeLevels.GB20))
// This is a pipeline function that takes a drive letter (string) and
// returns the free GB from a DriveInfo structure.
         let cvt_drive_to_free_gb drive =
             let fs = free_space drive
             if fs > DRIVE_OFF_LINE then
                free_space drive |> cvt_bytes_to_gb
             else
                int64(-1)

             let cvt_gb_arg_to_int (arg:string) =
                 let numeric_arg = arg.Substring(2, arg.Length - 4)
                 int64(numeric_arg)

and the main application


(*
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 Microsoft.VisualBasic.FileIO
open System.Collections.Generic

open Toa.volLib // local library

let send_email msg =
 use msg =
 new MailMessage ("dbadmin@somewhere.sometown.us",
@"dbadmin@town.arlington.ma.us", @"Disk Space Report\n",
   msg )
use client = new SmtpClient(@"webmail.somewhere.sometown.us")
client.DeliveryMethod <- SmtpDeliveryMethod.Network
  client.Credentials <-
new System.Net.NetworkCredential("dbadmin", "xxxxxx")
  client.Send msg

let match_head = "--"
let match_tail  = "GB"

let contains_match_constants (arg:string) =
    if arg.StartsWith match_head && arg.EndsWith match_tail then
       true
    else
       false

let parse_min_gb_arg arg =
    if contains_match_constants arg then
       cvt_gb_arg_to_int arg
    else
       volLib.GB1

let no_disk = int64(-1)

[<EntryPoint>]
let main argv =
    let min_gb =
    if argv.Length > 0 then
       parse_min_gb_arg argv.[0]
    else
       volLib.GB1

    let local_drive_list = drive_list ()

    let check_file = "free_bytes_check.txt"
    let system_name = System.Environment.MachineName
    let system_drive = Path.GetPathRoot(Environment.SystemDirectory)

    let display_info = new List<string>()
    display_info.Add("System name " + system_name + "\n")

    let drive_list_len = local_drive_list.Length

    for idx = 0 to (drive_list_len - 1) do
        let drive_name = (Seq.item idx local_drive_list).Name
        let free_gb = cvt_drive_to_free_gb drive_name
        let display_row = "Volume: " + drive_name + "\n" + "Free Space: " +
free_gb.ToString() + "GB\n"
        display_info.Add(display_row)

    let curr_time = DateTime.Now

    let gb_c = cvt_drive_to_free_gb system_drive
    let gb_d = cvt_drive_to_free_gb "D:\\"

    let gbs = display_info |> String.concat("\n")

    if not (File.Exists check_file) then
       use swH = new StreamWriter(check_file, true)
       swH.WriteLine(curr_time.ToString())
       send_email gbs
    else
       let fAccessDate = File.GetLastAccessTime(check_file)
       let update_stamp = curr_time.Subtract(fAccessDate).Duration() <
TimeSpan.FromDays(7.0)

    if not(update_stamp) then
       File.WriteAllText(check_file.ToString(), String.Empty)
       use swH = new StreamWriter(check_file, true)
           swH.WriteLine(curr_time.ToString())
       send_email gbs

    if gb_c < min_gb || ((gb_d > no_disk) && gb_d < volLib.GB20) then
       printfn "Disk free space is below thresholds; send out warning email."
       send_email gbs
    else
       printfn "Disk free space is at or above thresholds. "
printfn "All is well, at least for now."</pre>
<pre>    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 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#

A Quarter Century

No one is really quite sure the day I — Pookie the Cockatiel — was hatched. So, after careful investigation, it was determined that Columbus Day October 12 was probably my hatch date. Today, I am 25 years old, not bad.

Let me just say it is difficult work to train humans to communicate with us. Primarily for survival reasons, we birds do not reveal a lot. But, Dad and Mrs. H. have gotten reasonable marks for figuring me out.

Doing what I always do, inspecting.

Dad left his dresser messy just for my birthday.

2 Comments

Filed under Bird Stories, General

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