Tuesday, May 12, 2020

Python: Learning by starting with the basics.

Just a simple mind exercise in learning a language.  Created a console Hangman game that uses a word api with a hint command that fills in the first available blank.

hangman.py

Guess a Letter:hint
------
|     |
|     0
|    /|\
|    /
t y p h u _ e _ 
Wrong Guesses:lmaio
Guess a Letter:s
------
|     |
|     0
|    /|\
|    /
t y p h u s e s 
Wrong Guesses:lmaio
stay of execution

Friday, May 8, 2020

Oracle: Capitalizing and removing underscores from a column name

Oracle table names are all caps with underscores.  So if you're consuming them from something like all_tab_columns, this quick little function makes them a little prettier. 

select initcap(replace(lower('SOME_COLUMN_NAME'),'_',' ')) from dual;

Wednesday, May 6, 2020

VBA: A little function to Capitalize and Split a String

Here's a subroutine for converting a range of strings into a space separated Capitalization (i.e.) "FOO_BAR" becomes "Foo Bar"


Sub Capitalization_Split()
'Declaring variables
Dim Cell As Range
Dim Source As Range
Dim Capitalized As String
Dim Humps As Variant
Dim Hump As String
Dim i As Long
'Initializing source range
Set Source = Application.Selection
'Looping through each cell in the source range
For Each Cell In Source
    Capitalized = ""
    Hump = Cell.Value
    Humps = Split(Hump, "_")
    For i = LBound(Humps, 1) To UBound(Humps, 1)
        Hump = UCase(Left(Humps(i), 1)) & LCase(Right(Humps(i), Len(Humps(i)) - 1))
        Capitalized = Capitalized & Hump & " "
    Next
    Cell.Value = Capitalized 

Next
End Sub

Tuesday, May 5, 2020

GoLang: Issues Installing Delv Analysis Tool

I've recently just started setting up my development environment to play around with GO.  My editor of choice is Eclipse as it 1) suits my development efforts, 2) It's pretty much free,  though I did opt to pay for CodeMix which has a very reasonable price of $29 per year as opposed to the competition.

I mostly use windows and the initial setup went fairly well except I was getting an error that all the analysis tools were not there.  I was able to "Go Get" some of the ones that were missing, but dlv just wouldn't install in that manner.  So I ended up checking out the https://github.com/go-delve/ repo, performing a go build and then manually copying over repo to my $GOPATH/pkg/mod/github.com/ folder, put the compiled dlv.exe into the $GOPATH/bin folder and then launched Eclipse.   No more warnings of analytic tools being missing.

No off to do something other than the obligatory "Hello World".

Thursday, March 5, 2020

Why Lucee is Better Than ColdFusion #1

Lucee's Query of Queries is better than Adobe.  Try this little snippet on Lucee 5 and then CF2018 or earlier


<cfscript>
       myQuery=QueryNew("Country,Capital City,Amount##","varchar,varchar,numeric");
       /*Add array values in column*/
       myAreaValues=ArrayNew(1);
       myAreaValues[1]=100000;
       myAreaValues[2]=50000;
       myQuery.addColumn("Area","integer",myAreaValues);
       WriteDump(myQuery);
</cfscript>

Sunday, February 9, 2020

XSLT with carriage returns and line breaks

I needed to translate carriage returns and line feeds to <BR/> elements in an XSLT process.  Sometimes you get hung up how you normally use functions and then hit a language wall that you think should work,

In this case, the solution was to iterate over the selection and output the elements with an appended tag.

<tr><td><xsl:for-each select="tokenize(customerinfo/@comments, '&#xD;&#xA;')">
                <xsl:value-of select="." /><br/>
</xsl:for-each></td></tr> 

Thursday, August 15, 2019

ColdFusion: Pretty Printing JSON with Google's gson

Here's a simple example on how to pretty print JSON with ColdFusion.

Install or load Google's gson.jar file by building it from the git repo https://github.com/google/gson or download the latest jar 



<cfscript>
variables.myJSON = {"ugly":"put in some ugly/compressed json here"};
variables.objJSON = CreateObject("java","com.google.gson.GsonBuilder").setPrettyPrinting().create();
variables.objParser= CreateObject("java","com.google.gson.JsonParser");
variables.jsonElement =  variables.objParser.parse(variables.myJSON);
variables.result = variables.objJSON.toJson(variables.jsonElement);
WriteOutput("<textarea cols='80' rows='20'>#variables.result#</textarea>");
</cfscript>