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" that 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 precomiled 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.