Thursday, December 20, 2018

Work

So, I had this big long rambling post about my work history and the bosses that I have had. I decided not to post that but to condense it down to this:

A leader can make your job enjoyable enough that you stay despite everything, or they can make you want to leave as quick as possible.

I've had both kinds... I'm fortunate enough that my current leader is awesome.

Sunday, June 3, 2018

Coding

I love to code. Its as simple as that. If I had a job where I couldn't code, I probably wouldn't stay in that job very long.

I don't especially care what the language is because I can figure it out (with my pal Google). I've coded in a lot of different languages. I'm sure there are more than this but these are the ones I can think of off the top of my head: Basic, Assembly, Pascal / Delphi, Today, Progress, Cobol, dBase, Hibol, C, C++, C#, VB, VBScript, VB.Net, Java, JavaScript, Perl, PowerShell, PHP, Various other "shell" batch languages

I loved doing Assembly when I was deep into it (many, many moons ago). The system was there for all to see and I was tweaking the heck out of it. I doubt that I would know where to begin on a 'modern' system.

I'm not sure that I have a favorite language. If I'm going to do something web based then I would probably choose PHP (with lots of JavaScript). If I'm going to do something Windows based then its probably going to be C#. If I just need a script then most likely it will be PowerShell or Bash (depending on the OS :)).

My advice to you, learn all you can and follow your passion. The more you know, the more valuable you are and the more hire-able you will be.

Thursday, January 11, 2018

Chrome in C#

Recently I got a new NAS and wanted to monitor the heath on a regular basis. So I wrote an app to log into the web admin portal and display the system status dashboard. I used the CefSharp toolkit found here: https://github.com/cefsharp/CefSharp

It was super easy to use. I just created a form then added the following code:

       
public ChromiumWebBrowser chromeBrowser;

CefSettings cefSettings = new CefSettings();
Cef.Initialize(cefSettings);

chromeBrowser = new ChromiumWebBrowser("INSERT_WEB_URL_HERE");

this.Controls.Add(chromeBrowser);

// fill the window minus the menu
chromeBrowser.Dock = DockStyle.None;
chromeBrowser.Top = menuStrip1.Height;
chromeBrowser.Height = this.ClientSize.Height - menuStrip1.Height;
chromeBrowser.Width = this.ClientSize.Width;
chromeBrowser.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
      
 

Then you can do things like this:

       
chromeBrowser.ExecuteScriptAsync("document.getElementById(\"ext-comp-1091\").click();"); // stats web menu item
      
 

Fun times.

Sunday, June 18, 2017

SharePoint jQuery generic call to get rest data

Lately I've been working with SharePoint a lot and creating functions to read data from lists and manipulate / display it to the user.  Below are two generic JS / jQuery functions that I created to do this.

I've explained the parameters so hopefully you will find it useful.

// inListSiteURL is the base URL of the SharePoint site... such as https://somespsite.somedomain.com or https://somespsite.somedoamin.com/someSubSite
// inListTitle is the title of the SharePoint list
// inHaveResultsFunction is the function to call when data is found
// inNoResultsFunciton is the function to call when no data is found
// inFilter is the filter to use... maybe something like "?$select=Title,URL&$top=100&$filter=Editor/Id%20eq%20123&$orderby=Title asc"... you can leave this blank if you want
// inFinalFunction is the function to call after all results
function spGetListData(inListSiteURL, inListTitle, inHaveResultsFunction, inNoResultsFunction, inFilter, inFinalFunction)
{
    try {
        var callURL = inListSiteURL + "/_api/web/lists/GetByTitle('" + inListTitle + "')/items" + inFilter;
        spGetRestDataCall(callURL, inHaveResultsFunction, inNoResultsFunction, null, inFinalFunction);
    } catch(err) {
        
    }
} // function spGetListData


// this function is a 'generic' ajax call used by the other functions to simplify the code
// inURL is the URL to the SharePoint list to retrieve data from
// inSuccessFunction is the function to call when data is returned
// inNoResultFunction is the function to call when no data is returned
// inErrorFunction is the function to call when an error is encountered
// inFinalFunction is the function to call when after all the data is processed
function spGetRestDataCall(inURL, inSuccessFunction, inNoResultFunction, inErrorFunction, inFinalFunction)
{
    var spRestContentType = "application/json;odata=verbose"; // you should not have to change this
    $.ajax({
        url: inURL,
        method: "GET",
        processData: false,  
        contentType: spRestContentType,
        headers: { "Accept": spRestContentType },
        success: function (data) {
            try {
                if (data.d.results.length == 0) {
                    if (inNoResultFunction !== null) {
                        inNoResultFunction();
                    }
                } else {
                    $.each(data.d.results, function(index, item){
                        inSuccessFunction(index,item);
                    });
                    if (inFinalFunction !== null) {
                        inFinalFunction();
                    }
                }
            } catch(err) {
                inSuccessFunction(data.d);
            }
        },
        error: function (data) {
            //console.log(JSON.stringify(data));
            if (inErrorFunction !== null) {
                inErrorFunction(data);
            }
        }
    });
} // function spGetRestDataCall

Friday, May 12, 2017

Psycho Chat

Years ago, a friend wrote an automated help chat program that the users would use to solve basic computer questions. He wrote it in Pascal (circa 1985). When I was running a BBS, he thought it would be cool to use his program to answer basic BBS questions, I agreed.

So I took his program, ran it through a Pascal to C converter and 'fixed' it and made a BBS door called Psycho Chat out of it. I hooked it to the Page Sysop feature of the BBS (circa 1992 running Wildcat!) and the transcripts were hilarious.

Years later (circa 2002), just for fun, I hand converted it to Delphi (which is based on Pascal... funny how the program came full circle). It worked OK but just wasn't the same.

On and off for the past 15 years I've been thinking of making it a web page using PHP and Ajax. My friend had the same idea yesterday so I decided it was time to actually do something about it. Took me a couple hours to hand convert the Delphi program to Javascript / jQuery / PHP but now its working. Still using the response files from the BBS.

It was a fun project and I don't know why I waited so long to do it.

This version doesn't record what is being said... hmmm... maybe I should add that just for fun :)

Sunday, March 26, 2017

Calculated Image

A billion years ago I found a one liner in a magazine and it made a pretty cool image. Recently I found it again and thought it would be cool to try it on a modern computer. Below is the algorithm I came up with. Just drop a Picture Box onto a form, add an X, Y and Decimal (from .2 to .9):
// Created by Gregg Buntin
private void DrawImage()
{
    int sizeX = Convert.ToInt32(tbX.Text); // this is the X (width) of the image
    int sizeY = Convert.ToInt32(tbY.Text); // this is the Y (height) of the image
    int halfX = sizeX / 2;
    int halfY = sizeY / 2;
    calculatedImage = new Bitmap(sizeX, sizeY);
    Color tempColor = new Color();
    double num = Convert.ToDouble(tbDec.Text); // This is where you plug in the Decimal value
    for (int Y = -(halfY); Y < 1; Y++)
    {
        int Y2 = Y * Y;
        for (int X = -(halfX); X < 1; X++)
        {
            tempColor = Color.White;
            double tempR = Math.Pow((Y2 + (X * X)), num);
            double R = (10000000 - tempR) / 2;
            int intR = Convert.ToInt32(R);
            double roundR = Math.Truncate(R);
            if (roundR != intR) tempColor = Color.Black;
            int X1 = X + halfX;
            int Y1 = Y + halfY;
            calculatedImage.SetPixel(X1, Y1, tempColor);
            calculatedImage.SetPixel(sizeX - 2 - X1, Y1, tempColor);
            calculatedImage.SetPixel(X1, sizeY - 2 - Y1, tempColor);
            calculatedImage.SetPixel(sizeX - 2 - X1, sizeY - 2 - Y1, tempColor);
        } // for X
    } // for Y
    pbImage.Image = calculatedImage;
} // method DrawImage

Wednesday, December 7, 2016

Cool AppleSoft Emulator

I've posted about this one before (7 years ago!) but I've been feeling nostalgic lately so I revisited it... The site is at http://www.calormen.com/Applesoft/ and is an AppleSoft Basic interpreter written in JavaScript. Joshua Bell did a great job with it. I've sent him several programs (4 recently) and he included them in his Samples list. He is a really great guy. You should try the emulator out... be sure to check my programs :)
Copyright Realm Laboratories, LLC