Yay!! edX started… wait, What?!?

So the edX Python course started 14 hours late…

Anyways, I’m going through it, and one of the first main loop concepts talks about while loops… And the 3rd programming exercise on while loops says that they provide the variable end, use a while loop to calculate the sum of all the integers leading up to end (meaning, if end = 6, we expect 21 [1 + 2 + 3 + 4 + 5 + 6])…

Well, of course I already know a better way to do this… I just blogged about this particular thing a few days ago when talking about Project Euler #1 so I went to use that answer, and of course, it didn’t like it (it was looking for a while statement), so I cheated and wrote:

while True:
    break;

print(end * (end + 1) / 2)

which solved it…

I posted on the site as well that I was disappointed with that particular exercise, as I would think that MIT would actually have an exercise that taught you the proper way to solve the problem (meaning there are lots of good valid reasons to use a while statement, as the prior exercises had done, I felt that they shouldn’t use one that had a better solution than the one they wanted)…

But hey… onwords and upwards!

Home Sweet Home – Motley Crue
Never B Flat, Sometimes B Sharp, Always B Natural

edX, CodeWars, and CriticalRoleRenamer

So, I was supposed to be starting a Python course through edX, but apparently it’s starting late (was supposed to start about 12 hours ago, so I was going to give my first thoughts after reading the syllabus and such, but alas)… so that sounds like something I’ll have to do in the future…

Yesterday I started with CodeWars and completed 11 exercises (codewars calls them Katas), although 2 of them were simple parts of the sign up process. I’m going to try to do at least 2-3 a week, when not focusing on my own projects.

Speaking of my own projects, over the weekend, I wrote my first Python program for personal use. As I’ve stated before, I’m a gamer, and I’ve been trying to watch this show called Critical Role, which involves a group of voice actors playing Dungeons & Dragons. It’s actually a good show to see the game in action… But I don’t have 3 hours an episode to sit their and watch… but what I do have is that time when I’m walking, and driving to work, etc…

So I used a program called ClipGrab and downloaded the episodes from YouTube, and converted them to mp3 files, and then put them on my phone, so that my podcast player (Pocket Casts) would see them. Now I can listen (as admittedly, there isn’t a great need to ‘watch’ the program) while I’m exercising, or driving, etc. Plus Pocket Cast lets me increase the speed and jumps sound pauses (silence in the conversation), so that 3 hour episode only takes me about 2 hours…

But I digress…

When being downloaded and converted, the youtube naming convention (which admittedly is probably just the name the uploader used) isn’t the most consistent, or friendly, especially when you have things like Plex or Kodi for media serving content… so I wrote a python program that grabbed the episode number and title from the file name, and renamed the file… Taking it from, for example, “Enter Vasselheim – Critical Role RPG Show: Episode 16.mp3” to “Critical Role – S01E16 – Enter Vasselheim.mp3”, which is a common naming convention. The neat thing was, by using regex (again, another thing I’m learning), I was able to grab the title, and then episode number, but with code, helped normalize them… because sometimes they used a pipe (|) instead of a hyphen to separate, sometimes they had the colon after show, and sometimes not, and sometimes they had the show title uppercased… But I was able to rename the whole thing (which literally took less than a second of time to run) so that the episode title was standard Capital Case, and based on thetvdb.com, had the season numbers properly meshed out…

While its a simple program, all in all, i’m rather proud of it… My next step will be using it for other shows I listen to! You can see it in its current form on my GitHub page!

Rocky Mountain Way – Joe Walsh
Never B Flat, Sometimes B Sharp, Always B Natural

Project Euler #1

So I’ve been threatening to do this basically since day 1…

To aid in my programming learning, I’m doing various programming puzzles… via Project Euler, Exercism.io, Coding Bat and others…

But I think another part of the learning process is explaining things, or sometimes at least why I did what I did…

So I want to discuss my solutions… Instead of boring you here with code, I’ll link my GitHub Gist, as well as my JSFiddle solutions.

First of all, the problem:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

Now, first, the key word here is under. But we’ll get to that in a second.

At first, this looks like it can be solved with a simple loop, and really, for this exact problem, it can be, with little concern about cost. However, what if this was changed to 1 million, or 10 million, or 100 million…

Well, on most modern-day computers, looping through 1 to 1,000,000 takes about 2 seconds… 1 to 10,000,000 takes about 20 seconds… while 1 to 100,000,000 takes over 3 minutes… while 2 seconds is not horrendous, 20 seconds is bad, and 200 seconds is down right insufferable – at least from today’s web standards…

The solution for this is simple, and usually overlooked… Its taking a simple equation 3 times and your done.

Wait, what?!

All this is looking for is the sum of all multiples of 3 under 1000 (so 3+6+9+12…+996+999) and the sum of all multiples of 5 under 1000 (important to note since 1000 is divisible by 5, if we use it, we’ll get the wrong result) (so 5+10+15+20…+990+995). Now, if you remember your high school math, there was this equation that allows you to get the sum off all the consecutive integers that made up a number… so, for example, the sum of the consecutive integers for 10 is 1+2+3+4+5+6+7+8+9+10=55. The formula is n(n+1)/2… or 10(11)/2 >> 110/2 = 55. So having that, all we have to do is realize that the sum of 3+6+9+12 (quick example) = 30 is the same as (1+2+3+4)*3 >> 10 * 3…

Now, if that’s the case, then the sum of consecutive multiples of three would be 3 * ((n/3)(n/3+1) / 2), or in this case, we know that 999 is the last, and 333 is 1/3 of that, so 3 * 333 * 334 / 2 = 166833, and the same would be true of for 5 (5 * 199 * 200 / 2 = 99500). So we would think, at first glance, that our answer is 266333. However, we’d be wrong!

Wait, what?!

Well, we forgot one thing. In using this equation, every multiple of 15 (3×5) is being added in twice… once for the 3 side of it, and once for the five side of it… so all we have to do is subtract out one of them… so 15 * 66 * 67 / 2 = 33165… Now, if we take 166833 + 99500 - 33165 = 233168, which would be the exact same value our loop gives us…

So if we did this to get the results for 100,000,000 instead of 1000, we’d get our solution in under 1/100th of a second, vs 3 1/3 minutes, and at way fewer CPU cycles, which could be very important for some algorithms you write!

So that is my first foray into Project Euler, and the programming puzzles!

Young and Innocent -Elefante
Never B Flat, Sometimes B Sharp, Always B Natural

PyCharm… and my regex learning…

So I installed PyCharm today… I know I’m a VIM user, and I could use vim to write my python code very easily, but I’ve learned, both from past experience (i.e. an older job where I wrote PHP via VIM) and my current experience (i.e. my current job where I write Javascript/HTML 5 via VisualStudio) that there are some features that an IDE provides that are incredibly useful.

For me, 2 of the most useful features are the debugger (being able to see my python results immediately, and having clues about bad pythonic form) and being able to jump around based on a function (meaning if i’m making a function call, in the code, I can highlight the function call itself, click a key, and jump to the definition of the function… very useful!

I’m sure there are lots of different ways VIM can do things as well, but so far, I’m happy with PyCharm and will continue to use it!

On a different note, I’m working on learning regex. Regex is one of those things that have popped up since I took programming in college, and has really only been something seen as very minor in the peripheral view of coding… But i’m realizing its usefulness more and more, so I started working on it…

My first big breakthrough was on my gaming program i’m working on… Of course, when making a RPG Game manager, you are going to need dice rolled, and I know that python has the randint function to simply give me a single random die roll, but I wanted to be able to handle all kinds of die situations… one of them was for rolling stats for an NPC… so I would pass in ‘6@4d6!1’ into the die roll parser… (which basically means roll 4d6, drop the lowest result, and do that 6 times – giving me all 6 individual results)

In my javascript version, I was using this complex set of ifs to loop through each character in the string, to determine if there was an @ symbol, etc… Then I learned about grouping in regex, and was able to use ‘(\d*)@*(\d+)[Dd](\d+)([\+\-\*/!\^]*)(\d*)’ to group everything I needed in 1 statement… now I had groups that had the values I needed instead of trying to parse individual characters from the string…

I’ve seen the light!

Whole Lotta Love – Led Zepplin
Never B Flat, Sometimes B Sharp, Always B Natural

How I installed Ubuntu-Mate 16.04.1

The post is a walkthrough on how I installed Ubuntu-Mate 16.04.1… It wasn’t a very difficult process, but for those who are new to Linux, it may prove useful to you…

First, I downloaded the .iso image from Ubuntu Mate. I downloaded the 64-bit version, but I’m also using it on my Raspberry Pi 2, so I’ve downloaded it for that as well… I download it via torrent, to not suck up the paid for bandwidth by Ubuntu, plus I leave it available for a few days seeding to help the community… I followed the instructions here to create a microSD card to install with… (or on in the case of the Raspberry Pi)…

For the computer installations, I just plugged it in to my USB drive, and booted my computer up, and once in the graphical environment, I chose to Install Ubuntu-Mate…

Now, before I get into the nitty-gritty of the install choices and selections, let me tell you about my PC. I am currently using a Dell Inspiron 530 (Built in June 2008 – so a ‘Vista’ Machine that is 8 years old). It’s an Intel Core 2 Quad (Q6600) @ 2.4Ghz, with 8GB of Ram (max I can install). I added to it a Gigabit ethernet card, as well as an nVidia GeForce GTX650 video card. I also installed 2 Crucial 240GB SSDs that I use as my root and home folders. There is also an external USB BluRay drive. I will eventually build a new PC, but this works well for now!

But I digress…

In the install process, I selected to Download Updates, and to Install 3rd Party software by default. I then set up my hard drives by selected Something Else, and then configured my first SSD (sda) with 2 partitions, sda1 which is an 8GB swap partitions, and then the rest of that drive as an XFS partition (sda2) that mounts as the root (/) folder. I made the second drive an single XFS partition (sdb1) that mounts as the home folder (/home). I then set the boot loader to sda. I note this, because I swap these every new install (which basically means, when I install 16.10 in a few months, I will make sdb the swap and root partitions, and sda the home partition.) I do this to alleviate wear and tear on a single drive, as I do way more writing data to the home drive, than I do to the root partition.

Next, I select New York as my time zone, and English as my keyboard and language options. I then name my computer (musicalcoder), my username (chris), my password (password… just kidding) and then wait for the system to finish setting up my computer. After that, I reboot.

The first thing I do after rebooting is to update the video drivers. This is highly important for me, as I’m using a SEIKI 39″ 4K TV as my monitor, and it sets at 3840×2160, and the fonts are almost illegible until the nVidia driver is installed. After the driver install and reboot, my monitor looks beautiful! I do this, so that I have 4 distinct portions of my screen, and with Ubuntu-Mate, I’m able to use Ctrl-Alt-NumPad 1/3/7/9 to automatically move a window to the four quadrants of the screen, ‘maximized’ for that size (meaning each window is 1280×1024)

After that, I do my customizing! When Welcome comes up after my reboot, I turn on the Subscribe to Updates, so my Software Boutique always has the latest available! I set my background (which I’ll describe in a new post someday), and change my preferences to use Mutiny (which is a take on Ubuntu), since I have such a large monitor, that is ‘widescreen’, I like having the ‘task bar/icon bar’ on the left side of the screen. I then run my updates and get the latest versions of all my internal software.

That’s basically it. I’ll keep a ‘My Linux Rig’ post updated with everything I install, software-wise, but this is the actual installation of Ubuntu-Mate.

Thanks for stopping by and spending a moment of your precious time reading my musings, I do greatly appreciate it! I hope you find it useful! Leave any comments if you have questions about why I do what I do, or suggestions of what you would do differently!

Inspiration: The Show Must Go On – Queen
Never B Flat, Sometimes B Sharp, Always B Natural

My Linux Rig… Master Edition!

One of the blogs I follow is My Linux Rig, and one of the things I’ve wanted to do was write down (for future reference) my linux set up, mainly so that I know, in future update installs (16.10 and beyond) how my computer is configured…

I’m currently using Ubuntu-Mate 16.04.1. You can read about how I installed said Linux Distro in my How I installed Ubuntu-Mate 16.04.1 post.

I am using the following software… (this is what I install that differs from the default installation) [I’m breaking this down into 2 sections… The first section are the normal repository programs I installed (which I will create a script to install for future reinstalls)] {Last Updated 11/25/2016}
Ubuntu Mate Repository (uses apt install)

  • ttf-mscorefonts-installer
  • vim
  • python3
  • python-pip
  • git
  • hplip-gui

3rd Party (either by DownLoading directly, using the Software Boutique, or adding a PPA to install)

  • Chrome (SB)
  • PyCharm (DL)
  • Clipgrab (PPA)

My goal here is as I add more software, I’ll create new posts explaining what I installed and why I chose it, and then updating this list. I’ll also add any tools/scripts I create here as well (and up to my git location (either github or my own hosted gitlab)) so that I’ll eventually simply have 1 place that has all of the software I use and scripts I run, so that should I ever update or change computers/distros, I know what I have installed!

Also…

I noticed I had been closing my posts with Until Next Time… and I was fine with that, until I noticed that John Somnez (simpleprogrammer.com) did the same, and I realized that is where I had gotten it from… Not that I mind doing that, and I’m sure he wouldn’t mind if I did the same (although maybe he would… I didn’t ask) but I figured I wanted to come up with my own… Also, I had realized that I had started to title my posts with a lyrics or a song title, but decided to not do that, as I wanted the post title to mean more to new visitors (as well as analytics and such for future concerns), so I decided that I’ll close my posts with a song title!!!

We Said Hello Goodbye – Phil Collins

Never B Flat, Sometimes B Sharp, Always B Natural

Why I’m blogging… and how you can too…

So I’ve mentioned a few times before (such as here and here), this blog is here today because I am taking John Somnez’s Blogging Course…

I’ve always known I should do this, and yet kept putting it off and off… I realize now how much further ahead I’d be if I had done this a year ago, or even 6 months ago… but I can’t change history, I can only move forward…

When I say this blog is here today because of John Somnez’s Simple Programmer blog, what I mean is that this email course I’m taking (more below) not only tells you why you should have a blog, and why you should do it now, but then actually tells you how, and for free (although – meaningfully, he also lets you know you are better off tying it to a paid hosting, because, especially when you are starting out, you don’t want to be tied to doing it all on your own, unless you really know what you are doing when it comes to it, and if you really did, you’d be doing it already)! That was really what kicked me in the right direction…

So hopefully, you’ll realize that you should be doing this (or something not totally unlike this) yourself! If you do, let me know in the comments below, because I’d love to come check your blog out, and comment on it as well!

If you want to take John’s free blogging course via email (it is 6 emails long, and you get 1 every few days), simply go to DevCareerBoost and sign up… follow along, and soon you will be on your way to being a better you, no matter what you have to share!

Until next time!

Never B Flat, Sometimes B Sharp, Always B Natural

How can I… #1 – Find a max value

So, one of the things I wanted to do was to help others with Python as I was learning… and I came across the following reddit in the learnpython subreddit…

If you follow the link, you can see my response… but basically someone was trying to go through an array of numbers (called a list in python) and come up with the max value (I know you can use the max method provided – but I think the exercise was to see how you’d write it)…

My answer, was the following:

def max_number(nums):
    largest = 0
    for num in nums:
        largest = num if num > largest else largest

    return largest

Which for me, was neat as it was one of the first times I used boolean expression from javascript in python (in javascript, it would have been largest = (num > largest) ? num : largest;) but even though its a simple exercise, I felt good that I came up with the pythonic solution relatively easy!

More to come… Until next time…

Never B Flat, Sometimes B Sharp, Always B Natural

And I’m gonna keep on loving you…

Lyrics from Keep on Loving You – REO Speedwagon 1980…

So, just dropping a quick line… I switched back to Ubuntu-Mate 16.04.1… from SolusOS really for a couple of reasons, none of which should stop you from trying it, but for me, it wasn’t quite ready…

I had issues with printing, and while i’m sure they will get the print driver installers fixed soon (I did update a bug report for an already existing ‘create print driver’ bug), I need to print today, and can’t really wait for it.

There are a few other projects that I want to use that they haven’t gotten finished yet (they are working on), but I wanted them available today…

So I went back to Ubuntu-Mate, and updated to 16.04.1 (and will jump to 16.10 to stay on top of the salient features).  So far I’m very happy with it.

I have my python environment (PyCharm) set up, and got my printer set up, and even got my FreeNAS box connected via NFS (maybe Monday’s how to story…)  But I wanted to update you on why I’m not using SolusOS right now… I’ll probably try again in the future, but for now I’m with Ubuntu-Mate…

Until next time…

Never B Flat, Sometimes B Sharp, Always B Natural

Are you ready… Are you ready for this?

The title is from Queen’s “Another One Bites the Dust”, from their Album “The Game”, released in 1980…

So today, I’m going to cover a couple of topics…

First of which, is my next blogging lesson, which covered consistency…  All I’m going to say, is that if you don’t have a blog, you should start writing one…  If you have no idea how, or want some advice, go to John Somnez’s Simple Programmer blog, and sign up (for FREE)… it’s worth it!

So in the spirit of consistency, I’ve decided, for now at least (meaning at least the next few months, but probably longer) to blog twice a week… Monday’s and Thursdays.

Second, my Linux journey.  I decided, as part of my learning process on linux, to try a new distribution. Last night, I installed SolusOS on my main machine. The install was fairly simple, and after updating and installing the provided nVidia graphics driver, it looks nice and clean on my 39″ 4K display (again, thank you John Somnez). After this blog post, I’ll go through and install PyCharm (the python IDE i’m using while learning Python). As I do more (and I’m planning on becoming a code contributor to them, as I get more comfortable), I will of course share my exploration with you…

Also, the fist project I’ll be coding in Python is my author finder… There are several ‘fan fiction’ sites where amateur authors write various stories… and some of these authors, I feel, are really good… so I want to make a python script that goes to these fan fiction sites, look up the author’s page, and let me know if there have been any new stories published by them since I last checked.  (Yes, I know about RSS – but some of these sights don’t allow RSS just for specific authors… I don’t care about every story that’s been published)  I’ll have a future post that covers this in more detail as I write it (maybe Monday’s)…

I’m also returning to gaming, and started running a social game (yes, Dungeons & Dragons 5e) with my friends.  I haven’t gamed/played since 2007 (right about when 4e came out), so I’m enjoying my return.  But as I design my homebrew world, I’ll be designing some personal tools to allow me to make running games simpler (or at least setting up the sessions simpler)…

Where do I find the time to do all this, you ask??? I stopped watching TV, pretty much altogether. Between Hulu / Netflix / Amazon / GooglePlay / straight out purchase, if I ever feel the need to ‘catch up’ on shows, I can… but I find by giving up TV, I have about an extra 20+ hours a week to read an hour a day, and do other things… (and honestly, during the summer hiatus when there are no new episodes coming out, I find that after a couple of weeks, I’m not missing them so this could be a permanent solution…)

Well, I think that is gonna do it for today…  so until next time…

Sometimes B Sharp, Never B Flat, Always B Natural