Tag: Python

Yes, I would be Honored to Bring about the Apocalypse

By: Danny Geisz | February 3, 2020

Project: #Life


Greetings, Celestials! And, I suppose, hello to the rest of you intent on reading my blog. Goodness me, I can’t keep away the readers. It’s honestly a problem. I’m getting too big too fast.

Now then, right to the matter at hand: the bringing about of the apocalypse. A more accurate title to this post probably would have been: “Today I Learned Tensorflow.” But nobody cares about Tensorflow. Everyone cares about the apocalypse. And we both know that the only reason I created this blog in the first place is to fill the void in my life created by a lack of meaningful relationships with a mass following of faceless, digitalized human beings. Heck, maybe I should start taking to a chatbot. I think if that should ever happen, I would be contractually obligated by life itself to finally visit a therapist.

What is Tensorflow? Even some of you non-CS nerds probably know what I’m talking about. To put it in brutally technical terms, Tensorflow is the tool that computers will use to gain consciousness and take over the world. In less technical language, Tensorflow is a programming library that (you guessed it!) Google put together to facilitate the creation of a variety of neural networks. I’m guessing nearly all of you are at least peripherally aware of the term “Machine Learning.” Neural networks are basically the hottest thing right now in Machine Learning (and honestly in Computer Science as a whole), and Tensorflow is a good way to put them together. Goodness, now I’m just being repetitive. Am I high?

Anywhoooooo, Tensorflow is basically a gauntlet of power, and I myself, Daniel P. Geisz now yield this power (its literally free, open-source software. I just downloaded it). So what then is all this talk about me starting the apocalypse?

Well, faithful readers, for many moons now have I been deeply enamored with the idea of a piece of software that can itself write code. If chatbots can speak to us so well that we can’t even tell they aren’t human, it must be pretty easy to train a neural net to write code, right?

Wrong. Even though language and our ability to communicate is one of the central aspects of humanity separating us from animals, writing a chatbot is almost the “Hello World” of recurrent neural networks. Programming, however, is a much more complicated endeavor. If you’re programming a chatbot, you can essentially just feed it text from reddit or twitter, and eventually it will learn which words should go next to one another in response to a piece of text from an external (human) source. Easy peasy, lemon squeasy. If you want to teach the computer how to code, you have to provide it examples of code. But even then, we can already see the issues that might crop up. For one thing, I would imagine that a piece of autocoding software would probably be taking some form of a command from a human being. If it were otherwise, we’d basically be spelling out the destruction of humanity by the robotic hand. So then, in order to train the system, you have a large database of code with precise documentation about what the code is trying to accomplish. This is all well and good (it isn’t) but 99.9% of all programmers have this nasty habit of not documenting their code. So then, on github, we have a gigantic, gigantic source of example code, but there’s no way to tell the neural net what the code actually means.

Hold on. I feel like I’m rambling. This is dangerous. One could make a very strong argument that every single thing I’ve put on XFA thus far is me rambling, and to that I humbly urge you to frack off. However, I very much value my sizable following of digital humans, so I feel I should be more direct.

*Deep breath in, deep breath out*. Ok we’re good to go.

Why do I want a computer that can program itself? I suppose that’s the fundamental point I ought to address. And to that, I can provide a very clear answer. It would be deeply, deeply dope (you’re welcome, Joey) if I could tell the computer to write me an application, and it would just do it. Writing software takes a tremendous amount of time, and as I have learned from the Orchid project, it is a conceptual and organizational nightmare. Now usually, conceptually and organizationally nightmaric projects are my idea of a fun Friday night, but they are really incredibly time consuming.

Many, many people may disagree with me, but I think one of the most interesting things that humans do is propagate complexity. Compared to the rest of the universe, we’re really quite good at it. However, it’s really quite exiting to image what humankind will produce in the next 30 years at our breakneck speed of innovation. What’s really quite amazing about human beings, however, is our ability to generate new ideas. The implementation of these ideas is really just the time-consuming part. This is by no means a new idea, but if we can minimize implementation time and maximize our creativity, we can do cooler stuff. I suppose you can call that Geisz’s law. My back-subconscious is actively trying to come up with counterexamples. Bad dog, subconscious. Let forward-conscious have this one.

Gracious me, I’m losing steam. Holy cow, wait! I just wrote 2 ¾ pages in 35 minutes! By Jove, that a new record! I have contented myself with a 3 page per hour pace, but I just blew that out of the water! I guess I normally put more thought into the words I write. It’ll be interesting to see what I wrote this time. Amazing what happens when you practice something. Maybe I’ll take the AP Lang test again for fun. How I loved mercilessly tearing apart various authors in those rhetorical analyses.

As a closing note, in the immortal words of Harrison Kinsley, “Programming is a superpower.” I recognize that a large portion of the word probably considers programming to be a field that is too difficult to learn, but it really isn’t. Then again, I did spend most of high school trying to convince my peers that Physics isn’t difficult to learn (which it is, btw). Regardless, if you think your life could do with some spicing up, consider learning python. That’s all for now. Be sure to ring the bell. It really helps out the channel. Also if you have the means, consider donating to my patreon. It really means the world to me. Also, I’m happy to announce we just reached 2.3k subs. I can’t thank you all enough for your support. Hugs and kisses. I’m out.

Quasi-Documentation Story for XFA Genesis

By: Danny Geisz | January 18, 2020

Project: XFA Genesis


Just as a brief warning, this post is going to be quite technical. I imagine this content might be dry for those of you who aren't computer science-ically inclined. For those of you who are computer science-ically inclined, I can only hope this will be useful, but know the following content is mostly for my own benefit. If you're looking to be entertained, I suggest hitting the next/previous buttons on the bottom of the screen.

Now then, I have largely finished the architecture for the XFA site. I think it is very likely that I will build more web apps in the future, so I’m going to write what I like to call a documentation story for this project. The “Quasi” prefix is there because the last time I wrote a documentation story it was incredibly long and detailed, and here I’m only really going to include important points from the project. This is going to be in mostly chronological order with respect to when I completed the various parts of the project. I should also note that this is also mostly for my benefit, and this shouldn’t be taken as a comprehensive guide.

Django:

There are five main parts of a Django web app (when you’re using Django templates): Models, Views, Urls, Templates, and Settings. I will go over each in order.

  1. Models: Models are the Django python abstraction for entries in a database. They are really quite straightforward once you get the hang of it. To figure out how they work, it’s easiest to look at examples. If you want a field in a model to be optional, be sure to include null and blank kwarg options. Make sure to run manage.py makemigrations and manage.py migrate when you create or edit a model.
  2. Views: This is how Django handles Url requests. Basically, you use Django’s database API to get necessary data, and then you create a context object containing information necessary to render a specific page, and then render a page using information from the context object and a template.
  3. Urls: Django provides a way to create beautiful Urls. Writing Urls.py is quite straightforward, but two things are worth noting. You can include urls from different files throughout the project by using the “include” function. This is very easy. You can also create Urls that contain contextual information that is sent to Views in the form of kwargs.
  4. Templates: Django provides a wonderfully easy way to make dynamic templates that render to HTML using context passed in from a particular view function or class. I will talk about two features. You can use {% block %} to create template blocks that can be included in other template files. This is a very useful functionality if you have various features of a web app that appear on each page (like the header, footer). Django allows you to use namespaced Urls in templates, which means that if something changes with the urls of a project, you don’t have to change the hrefs of all the anchor tags. This is quite good. You can also call functions of different objects from within templates.
  5. Settings. This file obviously contains the settings of the project, but a couple things are worth noting. You should use a config json file or environment variables to store sensitive information about the project. This is also where you can include a list of other Django compatible web apps.

HTML / CSS:

This is really only my second web dev project, so I learned a great deal about HTML/ CSS in this project. I’m going to include points that I find valuable. Some of these are quite basic.

  • Use divs to organize everything.
  • Use position: absolute if you know exactly where you want the element to be located.
  • If you use position: absolute, make sure the parent element has its position set to relative.
  • Margins are everything. Never forget.
  • To specify where something should be, margin, height, width and padding. Never forget.
  • The order of margin and padding is top, right, bottom, left.
  • Make sure to be mindful of cross-browser support.
  • To make a transparent linear gradient not look grey on mobile, use rgba, and make the “a” value 0.01.
  • Keep making websites and keep learning.

Materialize CSS:

I used the Materialize CSS framework for some of the CSS heavy lifting. Here are some important things to be done with Materialize:

  • Use center-align for alignment. This is so very wonderful.
  • Use container to put content in the middle of the screen. This is also so very wonderful.
  • Use Rows and columns for positioning objects. A very good feature.
  • The “hide-on-small-and-down” and other hide/show classes are incredibly useful for making webpages look good on mobile.

Deployment:

This was very daunting, but thanks to Corey Schafer, everything is up and working. This was my process for getting the XFA site up on the interweb.

  1. Make a Linode account.
  2. Create a new Linode Server. Mine runs Ubuntu 19.10. In retrospect I probably should have used Ubuntu 18.04 because its LTS, but hopefully that doesn’t bite me in the butt too hard.
  3. On the server, create a new user with sudo privileges. Honestly for the next couple steps, the best way to relearn is to just rewatch Corey Schafer’s videos until you understand everything completely.
  4. Set up SSH for passwordless authentication.
  5. Install ufw (uncomplicated firewall).
  6. Install and set up an Apache2 server. I’m a bit fan of Apache because it’s configuration files are pretty straightforward.
  7. Use git to transfer files from local to server (more details below).
  8. Configure Apache to work with the Django wsgi.
  9. Allow http traffic from the firewall.
  10. Buy a domain from a domain registry and set its namespace records according to Linode’s instructions.
  11. Use Linode to configure RDNS for your domain, and in your settings.py make sure you include your domain in the list of allowed hosts. More details in Schafer’s vid.
  12. Your website should be up and running by now, but it won’t be secure.
  13. Use let’s encrypt and certbot to make the site secure. These instructions are on Let’s Encrypt’s website.
  14. Add a section in the firewall configuration to redirect traffic from the non-www to the www site. This was causing some issues.

Setting up Git: This is super important because it allows you to develop on your local machine and easily push changes to the server. I will redirect you to this link which has much more information about this. Somethings to note about this process. Include your settings.py and your db.sqlite3 database in the .gitignore because you will have different settings for your live Django app than for your local Django app. It is also best practice for the server to have its own database. I used PostgreSQL for my live server. It’s super easy to setup and configure with Django, and Django migrations worked just as well for the Postgres as they did for Sqlite.

I think that just about covers everything. There are, of course, a ton of other nitty gritty details to figure out, but that’s how any software project goes. Once again, I’m mostly writing this as a way for me to remember the main steps for building a web app with Django. Perhaps this may be of some use to the rest of you.

Corey Schafer is the Love of my Frikin Life

By: Danny Geisz | January 15, 2020

Project: XFA Genesis


I did despair, my friends. I had sunk low into the darkness. I thought all was lost. I thought that all the work I had done on the XFA site was for naught. I thought…it’s almost too difficult to write. I thought I would have to…*gags*. I thought I would have to build my website with WordPress. Wow, that was hard to say. Allow me to explain.

Yesterday, I had finished the first version of the XFA site. I happily, giddily even, danced over to the BlueHost website and almost mindlessly bought a 3 YEAR shared hosting plan. Up until that point, like the good lil programmer I am, whenever I had run into an issue, I waltzed on over to StackOverflow to figure out what I was doing wrong. After I looked at the BlueHost interface, I thought to myself, “self, I have no idea how to deploy a website on a shared server, I should probably bop on over to StackOverflow.” But then, to my overwhelming horror, the internet absolutely failed me. As much as I looked into the revolting bowels of the interweb, I couldn’t find a single (applicable) tutorial about how to deploy a Django web app on a BlueHost server.

Ya boi was all like, “what the flippin’ heck?” In my confusion, I did a bit more research into general Django deployment practices, and it was there that I found the truth. It turns out that it is SUPER, SUPER, SUPER, SUPER overkill to use Django to build a blog site, which is precisely what I had done. Because it is SUPER, SUPER, SUPER, SUPER overkill to build and deploy a blog with Django, no one really ever does it. And because no one ever does it, there’s no one to make a tutorial for how to do it. And thus, the internet community failed me.

It was in that moment that I reached a nadir. I very, very angstily arose from my computer perch, vented to my brother, and then took a walk outside in the cold, cold Colorado air.

I decided that the only reasonable way to deal with this situation was to be brutally honest with myself. I know that I have no experience with server programming. You don’t either, so stop judging me. I knew that I might be able to get Django to work on BlueHost, but it would likely require a knowledge of Apache that I don’t possess, and several long heart-to-hearts with the Support Team of BlueHost. As a quick aside, the Support Team of BlueHost is hands down the best customer service with which I have ever interacted. Let be the first to tell you: if you are building a WordPress site, or a static web page, look no further than BlueHost. They’ll be the Obi-wan to your Qui-gon Jin.

And that is when I began to despair. BlueHost is super good at building and deploying WordPress sites, so there I was with my 3 year subscription, thinking I would have to sell my soul to the abusive mistress that is WordPress.

But then, when all hope was lost, a single beam of light shone through the dark stormy chaos that is the world-wide web. I was desperately flinging myself at every forum I could find, desperately searching for answers I never hoped I would find, when Reddit in all of its glory deposited a single comment into my lap that would come to fundamentally change the entire course of my afternoon.

The comment said something like, “…check out Corey Schafer’s tutorial on Django Deployment. He probably will have something that can help.” While to the untrained eye, this comment may have appeared as an emotionless recommendation for an online tutorial, I saw it for what it truly was: a supernatural sign of hope, where no hope could be found. Blessed readers, I will have you know that I did go to Corey Schafer’s website in an almost delirious fervor, and I found his tutorial on Django Deployment.

I’ll leave out the juicy, juicy details associated with the process of setting up SSH keys, configuring apache, and massaging linux, but I am here to tell you that as I sit here tonight, you yourself can go to exfizzassist.com, and there you will find the XFA site. I know, I know. I can hear your whoops and hollers from across the bounds of space and time itself. The XFA site is comfortably siting on a Linode Server somewhere in Fremont, California.

But I think the true moral of this story is not that the XFA site is finally up. The really, truly fundamental take away from this post is that Corey Schafer is a sexy, sexy beast. For all you girls out there trying to find a strong, yet sensitive man, you’ve got your priorities all wrong. There is really nothing more animalistically sexy than a man who can battle a Linux web server and emerge the victor. To be perfectly honest, I have absolutely no idea if Corey Schafer is romantically involved with anyone. But by the hammer of Thor, if he’s not, then citizens of the world, hop on over to that hunk of man-meat!

Ugh. It’s 11:30pm. Last night I got like 5 hours of sleep, so I told myself that I would be in bed by 11 tonight. Well, that didn’t happen. Anyway, I best be off. However, one more quick thing. If you do happen to be looking for tutorials on Python, Corey Schafer is your man. Don’t go to pythonprogramming.net (I love you Harrison, but Corey is better). Don’t ask questions and go directly to Corey Schafer’s YouTube channel. Peace.