Monday, March 4, 2024

Libraries in Programming

So I got a technical job and don't want to talk too much about it because everything is ~*PrOpRiEtArY*~ and I want to respect that. So far they've been good to me, but I hope at some point I can learn an acceptable way to continue to blog about tech in a specific way. I'm referring to my job as "data choreography" for now and maybe someday will be able to expand on how those systems work.


IN THE MEANTIME.

I've always heard about "libraries" which are used for programming languages. To myself I think: "Holy sh*t, there are already so many instruction manuals to look through, how could I possibly go through a whole library?"

Like with most things I'm afraid of, it doesn't seem to be too horrible. 

Library (programming) definition: a collection of precompiled routines that a program can use.

So say you're working with Python and want to download a library for it. You download Python if you don't already have it, then you download  a library, Pandas, for instance. It comes with an easy enough Pandas Instruction Manual just like anything else. Being good at this programming stuff if all about reading the instruction manual, then having the guts to experiment. And, I guess, also finding the time to do such things. Another little library example, Apache Arrow. This and the more famous NumPy are downloaded to get data types for Pandas.

Then you use these things to make instant charts, like the one below:


Pretty neat, and I never really understood what a "library" was for and what it would be used for.

Wednesday, February 7, 2024

Python Change Maker (And Federal Tax Maker)

Today I was hit with this beauty in Python, and I'd like to go through the solution step by step:

"Given a dollar amount as a floating-point number, print out the smallest number (count) of coins and bills needed to make that amount.

The amount must be < $100.

Output should be printed, not returned.

Examples:

$1.05

1x $1 bill

1x nickel


$0.41

1x quarter

1x dime

1x nickel

1x penny"


This question is a class trap in control flow and will test how a person understands what the computer is doing step by step.

At first I started pedantically, thinking I was clever by starting with larger coins and working my way down:

quarters fire off at 25, 50, 75

dimes fire off at 10 20 30 35 40 45 50 60 70 80 90

nickels fire off at 5 15 25 35 45 55 65 75 85 95

hundredths place from 1-4 and 6-9 receive pennies 

(I'm so rusty at math I had to Google "hundredths place" lol)



Then I got a little frustrated, thinking about how I couldn't wrap my head around moving up in a direction. This is kind of how the thought process worked:

When able to / by 50, do that save quotient = bills

when able to / by 10, do that, save quotient = bills

"When the amount is 80 dollars and we've comitted to giving the 50. The amount 80 is greater than or equal to 50 and less than 100, then you only owe 30 dollars."


There's always a trick to coding and even in math, especially when it comes to "thinking backwards." Once you've unlocked that the secret to this problem is






subtraction



then there's no going back, and the rest, honestly, is pretty smooth. Or at least that's how it feels for me and my learning process. In layperson language, it's something like:

for each denomination, from highest to lowest:

     calculate how many of this denomination to give

     print out (or store to print later) that quantity

     subtract the change given from amount



As it looks in code:

def make_change(amount):

     if amount >= 100:

          raise Exception("YOU CAN'T DO THAT")

     if amount >= 50:

          print(f"{amount//50} Fifty")

          amount -= 50

     if amount > 19.99:

          print(f"{amount//20} Twenty")

          amount -= 20 * (amount//20)

      if amount > 9.99:

          print(f"{amount//10} Ten")

          amount -= 10 * (amount//10)

      if amount > 4.99:

          print(f"{amount//5} Five")

          amount -= 5 * (amount//5)

      if amount > 0.99:

          print(f"{amount//1} One")

          amount -= 1 * (amount//1)

make_change(36.41)

"""This will give the user one of each, and I used to love that at a cash register.


***Then you have figured it out, hurray, you're feeling good. But now you notice it's a long piece of code and it's just doing the same thing over and over. For each denomination you're applying the same rules, the only thing that's changing is the amount and denomination. You can start representing these things by iterating with your i count placeholder as shown below:

def make_change2(amount):

     denoms = [50, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01]

     names = ["fifty", "twenty", "ten", "five", "one", "quarter", "dime", "nickel", "penny"]

         for i in range(0, len(denoms) - 1):

             if amount >= denoms[ i ]:

             qty = amount // denoms[ i ]

             print( f"{qty} {names[i]}" )

             amount -= denoms[ i ] * qty

make_change2(36.41)





Finally, another example using the IRS Federal Taxes, because this code makes the floor and tax rates easy to change:

def calc_tax(pay):

    rates = [0.37, 0.35, 0.32, 0.24, 0.22, 0.12, 0.1]

    floors = [578126, 231251, 182101, 95376, 44726, 11001, 0]

    tax = 0

    

    for i in range(0, len(rates)):

        if pay >= floors[ i ]: 

            tax = tax + (pay - floors[ i ]) * rates [ i ]

            pay = floors[i] - 1

            print(f"pay = {pay} floor = {floors[ i ]} rate = {rates[ i ]} tax = {tax}")

    return tax

        

calc_tax(100000)   

Friday, January 12, 2024

Hexademical

 I want to blog about something I've been really fascinated with since nearly the beginning of my life, but still don't understand today:

Hexadecimal!

The hope is that I'll blog today and laugh about it in some years when I actually know what I'm talking about. When i was a kid, I used a gameshark device for the Playstation one to mess with the data that was already in videogames. Final Fantasy tactics, in particular, taught me something really important regarding database structures and I didn't even realize it at the time, or maybe the nature of bytes (again, I'm still figuring it out). A user would reach into the container for characters and modify each slot. Ramza, the main character, was represented by 00, 01, 02, for his three sprite forms. Delita was 04, 05, 06 until you reached 09, Dycedarg. At 09, the next sequence would be 0A (the 11th character) while 0C (the 13th slot) held one of my favorite princess characters (haha). 0F was the 15th character.

The number 10 would represent the #16th character, then 20 # 32, and 30 #48, and if you're lucky enough to understand a bit about hexadecimal, this is significant (but I certainly won't go on and say more without learning a little more myslef). What a cool tool though.


I'm currently really struggling with databases and needed to figure out an outlet after finding something heartwarming (at least for me), so here we go.

I've been trying to bulk insert data into a table using SQL Server Management Studio 19. It is a mess. I used Mockaroo to create data and have no idea why the .csv files are so horrible, but from the forums I'm reading that's pretty standard.

The last two days of my life have been errors, currently:

    Msg 4879, Level 16, State 1, Line 161

    Bulk load failed due to invalid column value in CSV data file C:\tmp\Campaign.csv in row 2, column 6.

BULK INSERT Campaign
FROM 'C:\tmp\Campaign.csv'
WITH (
    FORMAT = 'CSV',
    DATAFILETYPE = 'char',
    FIELDTERMINATOR =',',
    ROWTERMINATOR = '0x0a',
    FIRSTROW = 2 
);
GO

Insert hexadecimal again where you may have expected a \n to reprent the end of a row. I referenced the ROWTERMINATOR and found out something kind of worked from the Microsoft manual--they don't really explain why, but it works. I of course referenced the table:

ASCII Table

And I like their description better than anything I'd come up with, so here's this:


"ASCII was actually designed for use with teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in ASCII format, all this means is they want 'plain' text with no formatting such as tabs, bold or underscoring - the raw format that any computer can understand. This is usually so they can easily import the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as 'text only'"

Pretty neat, and refencing the "LF" (you'll see this on your VS code indicating how line breaks work!) was a pretty chance occurence. Now I have to figure out why SSMS is trying to read my clearly empty sixth column in my Campaign sheet, but whatever. You should see the Talend portion; it's a total wreck. I think I hate Java and don't even have the merit yet to say so, but if it ends up working somehow, I'll update that too.

>' See ya!

Thursday, January 4, 2024

Notes on SQL

Quick note today-- I'm wrapping up on an SQL / ETL bootcamp and wanted to mention on my coding journey that I think others will understand.

A hurdle I've had to get over is that immediate panic when something goes wrong. I fall prey to wanting to be perfect all the time. I'm using a tutorial from Alex the Analyst in the example--he's amazing, but from a pedagogical point of view doesn't quite foster strong foundational learning--best to use the manual and learn something yourself though. Alex can't do that for you, and almost nobody can do that for you.


So without the right questions to ask, do you even know how to get out of this mess? You probably do. But I did not and didn't know the prompt to ask ChatGPT, nobody to ask, and needed to sift through the SQL manual again, exactly how people learning new technology have to figure things out. It was the USE [database] portion that was missing, and everything else turned out to be just fine without my panic.


This kind of dumb, level one thing happens to me regularly. Sometimes 2 months into a new language I'll forget the simplest step, and review all my Youtubers only to realize they don't have the answer covered.

So this post is about learning to use user manuals. Making sure that you go through at least some of it on your own, and make sure you foster some of that curiosity and self-exploration as if you are an explorer.

Also one last funny thing. Small assignment for class to create a database diagram example. Love this kind of design thing, hate that I don't know of a program that makes it easy to both visualize AND customize the work, so I just draw it with a free program and then customize it with Paint (lol, I know, it'll get better).


>'
Okay, see ya!




Monday, January 1, 2024

Happy New Year! Working with Godot, Considering the Value of Low-Definition Sprites

I have been thinking long and hard about what kind of style my terrible first game should be in, and I've decided to draw it in chibi pixels, just like my old sprites from RPG Maker.


Some friends have commented, "He's so cute!" Which I actually really appreciate so much that it's changed the direction from where I thought I might go with this platformer. There's something psychologically magical about poor graphics which forces the player to fill in any gaps and imagine what the objects and characters would look like if they were life-sized. I haven't decided whether or not I'd include full scale character portraits as they leave less to the imagination:

Also, drawing this gal took me like 4 hours. It's a lot to consider while DALL-E or Microsoft Design may churn something like this out in mere moments!

As for coding this time, I've realized that Godot includes quite a lot of built-in scripts for designing a game. I'm working with 2D graphics at the moment, and I find it neat that they've implemented jump physics and gravity into the script templates. You can see from the screencap below that Godot provides the developer with speed and jump velocity.




That's all for today. I'm meeting with my friends later today to discus different mechanics in games; we've been refining our ideas to think of what would be an interesting game to start out with and what would be required to implement that.




Friday, December 29, 2023

Humble RPG Maker 2000 Beginnings

When I was a kid (about 17 or 18 years old) I spent an entire school year and that summer "creating" a game for my friend Katie. This was about 2006. I used RPG Maker 2000 and paint to throw together scripts, animation, physics, and many hand-drawn assets to work up something of a starter RPG. I didn't realize at the time that I was working with event commands, variables, control flow, placeholder commands, and plugins to make this game work. I always wanted to major in computer science, but I never quite realized that life could be for me. I never knew that I was already getting the fundamentals of control flow down. For instance, in RPG Maker, the developer might check if a player has a certain item before allowing a door to open, or in as written in a pseudo-code example:

FUNCTION keyCheck():
    IF Golden_Key EQUALS 1 THEN
        RETURN True
    ELSE
        RETURN False

I also wouldn't realize it at the time, but this gave me a sense of purpose. I would transcend time in such a way that a week would go by and I'd barely notice it. I'd be thinking instead that I hadn't made enough progress on the game and that this was ultimately a waste of time that could never amount to anything. The writing was surely so cheesy and probably cringe to look at the logistics again, but I don't have to worry about that because I'll never know . . .

Some years later, I saved everything to a flash drive USB and mailed it to Katie who was living in New York City at the time. Just by fate, my computer crashed and burned before I had the chance to back up anything and I hadn't quite become aware of servers or cloud storage (which was well on its way to taking over everything). Because of the way mail worked / didn't work at her old Bushwick neighborhood, she never received the flash drive, and it was lost for good.

Or so I thought.

Flash forward to 2023, where I've been playing videogames online with Katie and two other friends about every Sunday since covid began. We've all been teaching ourselves the Godot engine, which has me feeling very nostalgic for these days I've described. I am both wishful thinking that I could go back to 2006 and encourage my younger self to go after what matters, and also happy that I've had enough life experience to make something that would make a bigger impact. 

I've also been taking coding bootcamps, some better than others. I learn more and more about databases, backing things up, and obviously trying out some AI models, and it's helped me realize the power of having secure data and what that can actually mean for soemone. 

I'm a minimalist who still has enough childike wonder to believe in "energy," so I take a lot of joy in throwing stuff out and burning old stuff, including uploading things to servers and throwing the physical objects away. I burned up flash drive after flash drive, finally coming across an old terrabyte I'd saved years ago that I'd held onto despite thinking it was broken.

It just needed a new cord. 👺

I believe that "fate" and maybe that same energy brought me to do this, maybe you're a mature person believe in "real" things and just find this to be a dumb coincidence. Either way, it turns out the old dusty terrabyte drive contained my old sprites, pieces of the original game, and so many of the other resources and code I'd thrown together.

It's like I have another chance, and got all my time back.

Some highlights / lowlights I'll post below. Maybe I'll make this a regular thing to stay humble, maybe it's meant to be a one-off. I'm excited for this new journey, and want to use my eventual success story as a template to show how someone can leap from point A to point B with a little time and dedication. Something like, "It's never too late, even in 2024 when people are automating processes and not replacing those lost jobs with anything where someone can make a living and people are nearly destitute according to Linkedin not being employed for over a year damndowecareatallaboutotherpeopledoesanyofthismattershouldtherobotsjustwinalready.."

Some old facesets below. I believe the first may have been an edit of an original Squaresoft character if someone feels impelled to help identify(?) who it is. I loved the art style, and I vaguely remember thinking the original character looked like a lady, so I used it as a template to edit and create the others:


My best friend had this wonderful exotic shorthair cat named By'Tor. You know I had to include him:


 
(used Asesprite to show you how he looked walking around in RPG Maker)



Apparently the blank pink tiles in front of the gray arrow tiles (near the equipment room) triggers a scene that takes the player into a battle scene, something of the colosseum archetype.

 


The writing, as expected: horrible. 

If you can see the dialogue message (console.log("I had a little help training)), I am refering to the training in the colesseum that literally happens DIRECTLY before this scene. The reader does not need a reminder, and why would a knight character admit vulnerability so soon? Ugh, terrible, terrible writing. 

But some interesting switches, events, and placeholder commands to pull up the stored name of each character with the ¥ n[1] (representing the character in placeholder 1). I don't know why the Japanese Yen sign was used, but I bet it stands out as obvious non-text in the same way we use something like %n or $var as placeholders today. I'm not going to pretend to understand Japanese code at just getting my grip on English coding.

Anyway, sometime this weekend I plan to post an update on my progress with Godot, noting the way things have changed over the course of 17 years, and in what ways things have remained the same, along with setting some future goals for 2024.

Merry Xmeth, hope you had a Hannukah, keep enjoying your Kwanzaa, "let me know in the comments" if any other cool thing happens this time of year, and feliz año nuevo en 2024!






Saturday, November 18, 2023

From Word Blogging to STEM Blogging!

 I haven't been here in a long time!


After totally uphauling my life (when my aunt gossips about me, she calls it "going through life changes" LOL),  I've decided to start coding. 

Now, about six months after the decision to leave my Project Management position with a local security company, I've decided to record some of the interesting bits of coding. I believe I only just now have the confidence to start talking about it. It's a slow, grueling journey, but other coders are as supportive as their jobs alot them time to be. 

The older I get the more precious (and easily forgotten) all the details become. So why not b l o g?

I'll still be writing about alligators and crocs (duh, I just went to the Everglades y'all) but I'll also be dropping in to actively blog about my coding journey. I've been doing this programming stuff in a box for about six months and didn't realize I'd get serious enough to need to blog about this, but that's how life goes, isn't it?

More soon. "Stay alive, till then."

>'