Python Lists

Time to write my second program in Python. This one will need to hold a bit of data. So I decide to use an array. Ooops. Python does not seem to have an array. But they do have lists. All right. Set a variable name equal to a comma separate list in brackets. Then I have a list.

The list is accessed with a zero-based index in brackets. You can create an empty list with just brackets. Then you can add items using the append() function. The list items do not need to be the same type. But you cannot access an entry in the list that was not created yet. That would cause an error.

I also need some random number generation. I import the random package for help with that. Then I can use the randrange() function which takes the upper and lower bounds of the range for the random integer that is returned.

Next up I am going to learn how to create a function in Python.

Invent With Python

I have been interest in learning the Python programming language for a while. My college had offered a class to teach you Python. But I have not seen the class offered in the last two years or so. Finally I have figured it is time to take matters into my own hands and learn the language by myself.

To help with this, I got a copy of the book Invent Your Own Computer Games with Python. I call it Invent with Python for short. I read through the book over the last month or two. I took a lot of notes. But I did not work through any exercises. Bad move. When I sat down to write my first program, I was clueless.

Now it is time to really learn this language. I did complete my first program with the help of Google. My plan is to write the games that were covered in the book. But I will write them on my own without looking at the source code in the book.

My company is sponsoring a Python hackathon in less than two weeks. Time to really get up to speed so I can complete. All right. I can use the input() function to grab data from the user. That returns a string. Need to convert it to a numeric value using int() before comparing to other integers. I can also use the print() function to do my output.

This is going to be a long ride.

WordPress Carousel

I am taking a college class on WordPress. Have not been really doing any coding in the class. So I am not having a whole lot of fun. I planned out my semester project web site. The initial page was going to have an image slider on it. I figured I would use a Carousel plugin for WordPress. Easier said than done.

I don't know how many plugins I tried. It was at least five. Maybe closer to ten. Lots of them were duds. Yes they were free. But I figured that a carousel was a common item these days. Many times the plugin would not display a single image. Others would display an image or two, but they would not move.

Finally I found Tiny Carousel Horizontal Slider Plus, also known as tchsp. I will admit that I initially had some trouble getting my images into this carousel. Once I did though, the magic happened. Thank you Gopi.

I uploaded a bunch of images to my gallery. However I had trouble getting them to work with tchsp, which requires that you enter the image URL. Turns out if you edit the image in your gallery, there is a File URL in gray over on the right hand side of the screen.

I sure hope the rest of my site will not be as much pain as the carousel was.

Brute Force PHP

I have long since finished my PHP class. Did a simple game earlier this year where I saved the state of the player to my online MySQL database. Now I am teaming up with a friend to write another database application - The Fan Fiction Database.

The minimum viable product is going to only have three fields to display, each of which you can query against. My code is doing a brute force analysis of the combinations of entries the user can make. I have an "if statement" for each combination of inputs. They each produce a custom SQL to execute.

I did do some good stuff in my PHP. It posts back to itself, so I only have one PHP source file. It also detects weird conditions like the database is missing, or there are no matches for your query. I will post the actual user interface in a little while after my partner does her part.

PHP Promotion


I am two weeks into my PHP Programming college course. I am writing small PHP code snippets in my HTML files now. To run the code on my machine, I decided to install WAMP. This gave me automatic installations of Apache, MySQL, PHP, and so on.

To start with, I am just dropping HTML files with PHP code into the root Apache web server. That way I can access them via localhost using my browser. As soon as I started making changes to my PHP code to fix bugs, I found some annoying behavior. I click refresh in Internet Explorer. However the browser just shows the results from the old PHP code.

I eventually found a work around. I could click the Back button in IE, then the Forward button, and finally Refresh would work. That was just too many steps to see the latest output from my new code. I was using Internet Explorer 9. But I doubt that version had anything to do with the problem.

I emailed my instructor. He told me to see him after class. Doh. There he walked me through some settings to jiggle in IE. Specifically I chose Internet Options from the Tools menu in IE. Then I clicked the Settings button under the Browsing History group. There I clicked the radio button that said "Every time I visit the web page" under the "Check for new versions of stored pages" label.

Turns out the default value of "Automatically" does not check for new versions of stored pages. I found this to be a weird location for such an option. But I am just glad that every time I click Refresh, IE actually does refresh my browser with a new run of my PHP code.

JavaScript Library Performance Penalty


Just checked out a deck by Nicholas C Zakas. He shares his insight in making modern web pages load fast. Apparently this is not rocket science. These days a lot of JavaScript library code is downloaded before the page finishes loading. Not all of that code is required up front. You should just download what you absolutely need on page load. Then grab other JavaScript library code on demand. Why didn't I think of that LOL?

Luckily I do not depend on heavy JavaScript libraries in my own code. Heck. I sometimes don't even use jQuery. Yes that is a recipe for pain. But sometimes you got to roll with just your own code. Makes for a quick page load time. You are in full control.

Making JavaScript Fast

The good folks over at Mozilla have posted many tips on how to make JavaScript fast in Firefox. Many of these ideas can speed up JavaScript on any browser. One interesting point was to avoid a lot of local storage calls. Otherwise your main thread gets blocked slowing everything down. That makes sense. Instead you should access a cache of local storage data that is held in memory. Nice.