Friday, April 30, 2021

Moving Images on a Tkinter Canvas

The stock analysis and comparator app I made was somewhat quick, just a few hours over a weekend. And most of that was just trying different things to formulate the data I wanted to see and compare. The latest project, will take some time and I'm not expecting it to be easy. Really looking forward to learning more how to use Tkinter and other packages that can be used with it.

Purpose of the application: I currently work in a helpdesk for a medium sized company. How we keep track of equipment and the frequency of moving things to different locations brings rise to a glaring need. How do we know where everything is physically located? Of course we have software to keep track of inventory and in what department it is supposedly located. We can also know what switch something is ultimately patched in to. But how do we know the physical location of each device? APs generally have a web UI where you can be place each one on a map. One could have a diagram of what each drop is labeled and where it is in the room. But that could still be a somewhat unclear as to where a PC, printer, or other device is located. I wanted to develop a simple application that would show a floor plan and a user could drag and drop different icons to show where each device is. It's entirely possible this exists but I am coding this to learn, not necessarily to market an application. Although if I were to develop it enough I would not be opposed to monetizing it someday.

What I've done so far: The first thing I wanted to make sure I could do was to drag and drop an image in a window. I figured if I can just write something to make that one thing work, then I can move on to whatever next function I needed to make the vision complete. Tkinter is a basic library for Python so I figured I would just start there. Through searching a few things I found a decent YouTube video series from codemy.com. One of his videos showed how to drag and drop an image. An issue I found with the way it is coded is that it basically creates a brand new image every time it moves (at least that's how I am understanding it). While I realize the final solution I found might technically do the same thing, I still needed the image to be an object of my own creation. Then I could put all the objects in a list and serialize certain attributes of the object to save them (Pickle might just be my next post). It also moved the image to wherever was clicked. I needed it to work so that it would only move when that particular image was clicked. After a decent amount of searching I finally came across something that worked!




























The first few lines are part of the initialization of the object, but the two functions in the snippet of the code will actually drag the object only when clicked and stop moving it when the mouse button is released. I admittedly don't fully understand how it works quite yet.

I believe the canvas.tag_bind binds the actual object to the mouse event and runs the code. Although I don't exactly understand what tag_bind does, it does seem to work fine. I am satisfied with how this part turned out. I just wanted to make the one thing work. Then I wanted to be able to save the locations of the images (I wanted to try this without a database). Then I could make a floor plan/blueprint and put that on the canvas. Then I would work on saving that in it's own folder. Next I want to be able to delete a device(image) or move it to a different floor plan, etc. Stay tuned for more progress on this!

25 Words or Less: You cannot write a whole program at once. Break it down and focus on completing one function, then continue to the next.





Thursday, April 15, 2021

Personal Application

Most of what I've coded so far was to solve a problem. Such as an efficiency system or documentation system. I recently have gotten in to trading. I started getting into it before GME craziness, so it's not like that was what got me into it. I was just curious about how it worked. I also had ideas earlier in 2020 of a few companies that I thought would do well, such as Zoom, and lo-and-behold, they did well and I could have made a decent return. So after making a few investments, some good some bad, and listening to a few podcasts I decided to do more research. This let me to want to look into companies' financials and balance sheets to make better decisions on what would be a more profitable, or potentially safer, investment. But after looking at a few companies I wanted to be able to compare companies. After looking at some data, to really compare I would have to write everything down. Which would be fine but I wanted something that would be quicker and would display the information I felt was most important.

Import yfinance python library.

From what I've read this is not the most reliable, but it is good to get started. Also the principles it uses would transfer to a more robust/reliable API. At least as far as what I read up on it, I felt it would not be a waste to write a small program to parse some data. So I just made a simple cli application. You put in any number of tickers and it compares YOY earnings and really any other data that I would have it return. The data is presented in a way that I feel most comfortable reading.

All in all, I feel it was a good little project. I could add more and may in the future and expand it any number of ways. At the moment however, I'm satisfied with how it works. It got me enough data for me to decide to invest in a particular restaurant company. QSR anyone? (not financial advice, or whatever one is supposed to say)

I'll have to see if I want to revisit this and make it more dynamic in the future, but I think it's good for now.

25 Words or Less: Simple and small programs can return important and profitable data.

Tuesday, April 6, 2021

Looking at Something From a Different Angle

As I thought about this post, I feel like I've written something to this effect before. Struggling with an issue when there is a very simple solution right in front of my face. Then finally seeing the more simple solution and implementing it. It does actually feel good in the end and that's what I will write about today.

I am developing a personal efficiency program. I enter certain activities and they have point values. I also put how many minutes I spend on each activity. Then when I look back I can see if I have been productive with my time and can make adjustments accordingly. I know it's impossible to reach, but 100% efficiency is the dream! I don't factor in my job or sleep, or even eating and such. But, things like watching TV is generally not efficient. Coding or studying Hindi on the other hand...

I designed it so that there is a database table for "ActivityTypes" and "ActivityEntries" I actually do. The problem is: what if an activity type is no longer valid and needs removed? Then I would have to have the program go through all entries that include that activity type and remove data from the column for an activity type on that row. Then before I knew it I was going down a rabbit hole of creating a new activity type of "Deleted Activity" and then using that to enter into the Activity Type column in the Entries table for when an Activity Type was deleted. That was just causing some confusion in my brain.

At last I had an epiphany of sorts. Why not just add a column in the Activity Type table for whether or not the activity type is valid/still in use or not? Then if an Entry had an activity type that was not valid it would just display a message letting the user know that the data might be inaccurate. That was very easy to implement. Then I just have 'activate' and 'deactivate' toggles if an Activity Type needs removed. It also makes it very easy to make an activity valid again. Data integrity is also there so that if something is deleted by mistake it can easily be undone.

Do you remember the scene in Big Hero 6 where Tadashi holds Hiro upside-down so he can get a new perspective and stimulate an idea? That's somewhat how I felt. Looking at the problem one way was not leading to progress. But doing something a completely new way gives just the inspiration needed to accomplish what was needed.

I know there will be bigger problems in the future. Ones that will require a different function or library to implement to solve a problem. If I keep in mind that there might just be a simple solution outside of my field of vision, I have to remember to lean back, or upside down perhaps, to find the obvious and easy solution.

25 Words or Less: Take a step back and try to see a problem from another angle. The solution might just be easier than you think.

Tuesday, March 30, 2021

Excel Is a Bane of Humankind

Excel is used by thousands, if not millions, of people every day and in all industries. It is a useful tool for what it is. The problem as I write this, I suppose, is not so much Excel itself but rather how it is used. Users expect it to be dependable. As they should. It's developed by one of the biggest companies in the world. But it should be used for what it is intended to be, a spreadsheet. What is Excel not?

A DATABASE!!!

Just to be clear. I understand it's not feasible for most companies to write a program for every nuanced situation. But when you have an enormous, and I mean ENORMOUS, spreadsheet that does calculations, uses macros made by the last person who had the job, and is needed for an absolutely integral cog in the function of your business, Excel is not what you need. You need a specialized program to handle that amount of data reliably. I've seen so many times where a macro gets corrupted, a file is corrupted, 32-bit version of office can't handle the processes needing done, etc. (Why programs still use 32-bit architecture is beyond me, but I guess companies have a financial limit on what they can realistically keep up to date.)

I've made a few simple web applications that handle a decent amount of data. I've used SQLite and PostgreSQL depending on the situation and they both work better than an Excel spreadsheet. I can customize it the way I need it and it is reliable. Of course, a database can be corrupted. But that's why you use a backup. (And I don't mean a person that doesn't know how to code making an Access program that runs like garbage.)

Again, while I realize that a niche application is not practical in every situation. For reliable data integrity and something that anyone can sit down and use, it is going to be best to have an application that stores data in a real database rather than an Excel spreadsheet. This may be just a rant posting, but it gives me impetus to keep coding. The fact that there is bad or misused software out there than can be improved upon. I will do what I can to make the world a better place by helping to rid the world (or at least myself) of the snare that is an Excel "database"

25 Words or Less: If you care about your data, do not use Excel to store it. Use a real database!

Monday, March 22, 2021

New Beginnings (again)

 I feel like I need to start this again. I know no one would really read this but I need a way to document things I learn. I have gotten into some coding again. I started making a documentation system last year and got to a point where I could try uploading it to AWS but had to put that on pause. Been a very busy since the last post. Started a helpdesk job at a different company. Took a trip to The Netherlands. Trying to learn Hindi. Busy getting everyone working from home at my job due to Covid. I developed a board game to a point that I'm somewhat happy with it. The game will just need a few more tweaks and play testing with those changes and maybe it can go to market someday. When the pandemic comes to an end I might be able to take it to some shops for people to play.

Just last week I started on an efficiency application to track how productive I am being. And thus why I want to start back at keeping track this way. Here is a problem I was having yesterday and how I resolved it.

I have a Flask application and on the one page I want to do an AJAX request. The AJAX request seemed to work as there were no errors. However, the page would always reload when clicking submit, so maybe the AJAX request wasn't going through. Through testing I found out that since the data was in a form, the form was being submitted to the backend before the AJAX request would ever be made. I removed the form tags and just used input fields with individual ids. The AJAX request would then send the data in those two fields to the backend.

I feel there is a better way to implement this as I believe form data can be sent through an AJAX request, but that might be for another day as this setup seems like it will work for this use case.

25 words or less: Having input fields not inside form tags can potentially make AJAX requests simpler.

Sunday, September 10, 2017

Programming to Tech Support

So it's been awhile now but things have been busy. I knew I needed a real job as I am in a serious relationship and have some different goals in life. Thus I got away from programming because in my area I don't think there are many, if any, opportunities for a programmer or software/web developer. So I needed a new angle.

A buddy of mine works for an IT company and I was talking to him about what I can do. He suggested I get A+ certified for a job in IT. Thus began a new journey. In April I ordered Mike Meyers A+ certification prep book. It is for the 901 and 902 tests to become A+ certified. I read all 1200+ pages and scheduled the 901 exam. In June I passed the 901 test! It felt amazing to accomplish that and know the previous few months of time spent studying did not end in vain.

I began more heavily studying for the 902 exam when my girlfriend's brother got a call from a previous employer. He asked if he knew anyone that might be looking for a job and knew IT related things. He gave him my name Monday and that Thursday I had an interview. The interview went well and by the end of July I started my new job as an IT support specialist.

The first two weeks turned my brain to mush. The programming knowledge over the past 1.5 years did not help as much as I had hoped. I feel that studying for the A+ exam did. Six months ago I would not have known anything about terms such as DHCP, DNS, or Active Directory. I had absolutely no clue how laser printers work or why printers need such specific drivers to function with a computer. Why aren't they just plug and play like a mouse or a USB flash drive?! Well now I know and it makes total sense. Kind of. I don't know why companies can't standardize most print related drivers so they are more easily plug and play. Maybe there's something I'm not getting...

Anyway I suppose this programming blog may take a hiatus. So far I think I like programming better than IT. But like I said, there's not much opportunity for that in my area and I don't plan on moving in the near future. So tech support it is!

I do like my job, I just have to get better at it. I've just replaced my programming podcasts with IT related ones. I'm going to start a new blog based on things I've learned. Maybe I'll start on it next week. I'm going to see what Wix has to offer. So starting next week I will have a new blog focusing on operating systems, computer hardware, printers, networking, and general troubleshooting. Now that I'm actually in the industry it should prove to be a rewarding experience. Maybe next week it will have some real content. Check it out!

https://mimicoctopus5.wixsite.com/mysite

25 words or less: Changing fields. Check out my new site. Hope to have some content by next week!

Tuesday, January 10, 2017

New Year, New Start

It has been much too long since I've written anything. I listened to a podcast that suggested to wait until you have something worthwhile before posting/blogging anything. To be honest I haven't been programming the way I'd like to the past two months. The biggest reason is I was helping turn this:











into this:

















So I was quite preoccupied, but for good reasons! Although not code related I learned some HVAC and electrical related skills. I also met someone who wrote code used in HVAC systems. All kinds of tech jobs in non "tech" fields. I would argue though almost all things are technology, just not computer technology and refering to things as "tech" could more accurately be described as incorporating and using computer technology into already existing technology. But that is a conversation that would not lead to any real benefit to anyone.

So now it is a new year and I have some new motivation to dive into code! (Not entirely unrelated to entering into a promising relationship. Got to start taking some things a little more seriously.) I revisited my scheduling app and decided to add a new section so the user could place a parts order, check the status of orders, and keep everything easily accessible as to what part it was, what job it is for, what store it was ordered for, and who ordered the part. As well as dates as to when it was ordered and if it had been placed and closed out. You can see a sample of this part of the app on my YouTube channel. That was somewhat during the recent remodel refered to earlier. So now with the new year I've decided to focus more on web development. I think I like that more so than other kinds of programming, at least right now. Over the course of my learning backend to frontend development (full-stack right?) I kept hearing and reading about a certain Javascript tool. Since it kept being referenced so often I decided I should look into this...

React
Building tremendously versatile web components with Javascript. I used Codecademy's course to learn some basics. One nice thing is they referenced an article at the end that helped you install it on your local machine. Then I went through Treehouse's course on React basics. That was very nice too as it walked me through a basic React app.

My overall opinion, both courses were equally good. They both explained things very clearly. I will give one advantage to Treehouse for this one as it was easier to see where to place each file as far as in the root directory or otherwise. I think they all would go in the root directory and the rest of it goes in the nodes folder, but I didn't realize it at the time nor am I knowledgeable enough right now to know for certain.

My biggest problem with both courses is they don't start you off on your own machine. The format of Codecademy understandably does not lend itself to using it on your own computer. Treehouse on the other hand has what they call workspace. I think I have expressed my view of it here before but suffice it to say I don't particularly care for that format. First they should explain how to set it up on my local machine, then how to use it. Workspace is definitely not a real-world environment. I'll give them the benefit of the doubt that there are so many IDE's, configurations, etc. that it would be too much to make videos for every scenario one could have at home. However I am pleased they do have a workshop that shows what to do to be able to use React on one's local setup. (I only wish they linked to that before the React course) That may be the basis for my next post, the steps to setup React/Webpack/Babel with the Terminal on my computer so I can make my own apps with React. Then I will have it for future reference when I code my own React apps.

So essentially I learned a new way to use Javascript by learning React. I'm excited to say there is much more to come! I have a Raspberry Pi 3 being delivered tomorrow and I signed up for two courses on Udemy to help me learn more Python! Very excited! It's gonna be a good year.

25 words or less: There are plenty of resources. Take advantage of as many as you can!