Frustrated

Frustrated

So I built this JavaScript basic calculator a month or two ago.  I have to admit there was a good bit of “reverse engineering” involved but I am still improving it…or so that was the plan.  Between working full-time nights in a non tech related field to support the family, looking for a job IN a tech related field and even  my daughter’s spring break, I haven’t had much time to work on it until today.  That’s when it hit me.  I’ve forgotten things.  Parts that came easy when I was able to work daily on coding became more cumbersome.  Not having the time to spend coding has caused me to forget some of what I’d learned. I’ve still be able to listen to podcasts every night.  I’ve even been working on things related to getting a job like Agile development, Scrum, SASS, RESTful APIs, web services, and more.  But, I haven’t been actively coding.

Now, I can’t say that I’d forgotten everything.  The basics of html, css and javascript are still in my brain somewhere. I just need to find out where.  But, how?  Do I go back to the basics and start learning from scratch again?  That seems like a lot of wasted time as I still know most of the material.  I went back to the basic algorithm scripting problems. I can still reverse a string with split(), reverse() and join().  I can check a string for palindromes by making everything lowercase, getting rid of any punctuation, then loop through the string comparing the first and last letters as I go. Great!  Got that down.

What about Intermediate scripting? I can sum all prime numbers using % (modulus). I can flatten a nested array and I can convert a string to “spinal” case.  I can even validate telephone numbers with regular expressions (which I kind of covered in a previous blog post).

So, what’s wrong?  The obvious answer is to spend more time coding, building, and making things.  Listening to podcasts and courses from Lynda are great but they’re only part of the picture.  I have a limited amount of time in the day and I need to schedule dedicated time to just building a specific project.  I’ve had a tendency to take online classes and it’s mostly stuff I know or can figure out.  These kinds of things give me an immediate reward because I can do them in a reasonable amount of time and I get positive reinforcement right away. I feel good when I solve a problem but in the long run, I’m not getting much further along in putting everything together.

I am going to pick one project like building a tic-tac-toe or simon style game and spend at least one scheduled hour daily working on it.  At night, I’ll still listen to podcasts but when I get computer time it will be to complete one project and not rely on as much “reverse engineering” as I did with the calculator.  I’ll keep you all updated on my progress.  Thanks for reading!

(Now, what editor do I use?  Brackets? Visual Studio? ….)

 

“If at first you don’t succeed; call it version 1.0”

Reset

2017-01-24-1-copy

 

For those of you hoping for part 2 of the Regular Expression tutorial, I apologize.  I’ve spent the last couple of weeks thinking and this blog has gotten off track from my original intent.  The title is “Adventures of a Coding Noob”, not “Teaching the Coding Noob”. It was supposed to be more about the perils and pitfalls, the successes and elation of what I’ve been learning and not really so much about the nuts and bolts of coding.  I’m sorry if anyone was trying to learn how to code from me but I would rather talk about “how I learn” more than “how to do”.   I hope you’ll stay with me through this reset and I hope you’ll enjoy the new (eg. original) focus!

Ok, with that in mind….

I have been experiencing a major frustration with the teaching site Lynda recently.  I’ve been going through their courses on things like Git, Bootstrap, Angular, and Node.  The tutorials themselves are fine but when I download the tools, I find the Lynda courses are often several versions behind the current downloads.  Sometimes these are minor differences and sometimes, there are MAJOR changes.  Files aren’t available, user interfaces are completely different and sometimes things don’t even seem to work the same!  I have enjoyed the great educational content on things that don’t change much but I’m finding that just going through the documentation on the web has been much more useful. For bootstrap, I downloaded a tool called Prepros and trying to correlate all the files from the Lynda lesson with with was actually available now was getting too cumbersome.  I was wasting more time looking for files than actually creating.

Solution…if you want to learn a tool, I’m finding it’s best to just go with the documentation and samples available directly from the authors.  It would be nearly impossible for any educational website to keep up with the nearly infinite changes occurring daily!  Lynda is great for learning the overarching ideas but for the detail work, they can’t be expected to change their tutorials with every single update!

Also, in my “Adventure” I’ve ramped up the job search, applying to several companies over the last couple of weeks.  So if you have ANY helpful encouragement, hints or leads I would love to hear from you. Check out my Linked-In at https://www.linkedin.com/in/donaldgallagher/ and feel free to forward it to all your friends who may be hiring!

I’m not sure what my next post will be about but please keep following and stay tuned to the next chapter of “Adventures of a Coding Noob!”

 

"Debugging is twice as hard as writing the code in the first place. Therefore, if
 you write the code as cleverly as possible, you are, by definition, 
not smart enough to debug it."

- Brian W. Kernighan.

 

 

Express Regularly!

Part 1

One recent lesson involved Regular Expressions or RegEx.  RegEx allows you to quickly scan over text for different properties.  Regular Expressions almost seem like an entire language by itself and is does exist in more than just JavaScript.  The idea has actually been around since the 1950s and you can find it languages like Python and Perl.

Here’s a real quick overview of the basic concepts…

The first, simplest match would be just a character.  Like A,b,z, or 3.  We mark the beginning and end of the RegEx with the forward slash /.  So, say I was looking for the letter “a” so I would use /a/ to look for it.

regex1

Cool, so  /a/ matches the “a” in the middle of “cat”…now what?

If we want to look for a range of characters, we can use the “-” to define a range.  If we want to check for a three letter word that starts with “c” we can define the first character with /c/ and the remaining three with ranges [a-z][a-z].

regex2

(By the way, the “g” at the end just turns on the “global” feature.  If this were off, it would match the very first word and stop.  This just lets us check the whole list at once.)

Here we match the “c” in “cat” but not the “b” in “bat” and the “c” in “car”.  As long as the last two characters are in the range “a” through “z”, it will match.

You can use the same method to match numbers, BUT…there is one little thing you have to remember.  When using RegEx with numbers, you’re actually looking for the numbers as a text character and not as actual numbers!  If you set up a range like 1 through 10 you’re not actually looking for the numbers 1 to 10.  You’re looking for the characters 1 through 1 and 0!  For example if you search on the range of 1-10 you’ll match all the 1’s and all the 0’s.  You can see below how this matches up to different numbers.

regex3

Just remember, you’re searching for the characters, not the numbers!

So, in Code Camp, the first problem to solve with Regular Expressions was to validate US telephone numbers. We’re looking for something that looks like 555-555-5555 or (555)555-5555.  A number like 52-55-8888 should give us an incorrect response.

Using what we know about ranges and how numbers are considered characters, we can first start looking at each number to check if it’s in the right format. (We’re going to ignore the dashes and braces for right now, we’ll address that a little later.)  At first glance, it looks like we have to set up a search for every number individually.  You might be thinking of something like

regex4

This method works to look for sets of three numbers in a row but there has to be a better way, right?

Thankfully, yes.  There are shorthand characters we can use instead of typing out every number!  For numbers, we can use the “Digit” shorthand character “\d”. We can use “\d” as shorthand for [1234567890]. This will save us a TON of typing! Now, the RegEx looks something like this.

regex5

See how we were able to replace [1234567890] with just a “\d”?  There is also another shortcut we can use here that will (believe it or not) make it even better!  We don’t even have to use “\d” three times!  We can just do it once and then specify we want to repeat it how ever many times we want!

regex6

We just use the “\d” and then the “{3}” tells it to look for the digits three more times!

This seems like a good place to stop for the moment.  In my next post, we’ll put all this together to check those US Telephone Numbers!  Thanks for reading!

“My software never has bugs. It just develops random features.”-Unknown

 

 

But That’s Not What My Code Looks Like…

code-copy

After finishing one of my latest algorithm challenges on Free Code Camp, I decided to search the internet for other people’s solutions.  I know that there are multiple ways of solving each problem, each with their own benefits and problems.  But, I had expected to find at least one other person who did it the way I did!  My code does exactly what was asked but in a completely different way than other solutions.

The one I looked up involved DNA Pairing.  Here’s the problem:

  1. The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
  2. Base pairs are a pair of AT and CG. Match the missing element to the provided character.
  3. Return the provided character as the first element in each array.
  4. For example, for the input GCG, return [[“G”, “C”], [“C”,”G”],[“G”, “C”]]
  5. The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.

To me, the simplest way was to just step through the string one letter at a time and use conditional if’s to just add the correct base pair to an array.  There are only 4 possible combinations so I didn’t think I needed to make anything that could be scaled up.  (I know this would get really bogged down with hundreds of possible combinations) but I was only dealing with 4.

Here’s my code for the solution (you can copy it on Github).

dna-code

Then, there’s what other people  came up with…

other-answer-1

from Rafase282 or a similar solution from DenKozlov

other-answer-2

The closest one to my code is the first from Rafase282.  Where he used push to add items to an array, I already had the i counter going so just used that to directly write to each index of the array as I stepped through.

The second solution from DenKozlov goes to the extra step of splitting the string into an array then, looks at each character in that array and pushing the necessary character into that array.  Personally, I feel this takes extra steps and memory that aren’t really necessary.  I would say that Den’s code looks cool but mine is just a functional without all the conversions and pushing.

Rafase282’s code I think is more scalable than mine but the problem involved only 4 options and since DNA doesn’t change, my answer is still effective.

So, as I am still learning to code, I believe my code was just as good as the others out there even though it didn’t do conversions, or use functions.  As I said before, there are many paths to the solution.  As long as the code works, the end user doesn’t really care what the guts look like.  As I become a more proficient coder, my code will get more elegant but, I believe that right now my solutions are just as good as other methods.

When you’re learning, I wouldn’t worry too much about what other people are doing.  If you can solve the problem with what you know, do it!  You’ll eventually learn other ways. Some are good, some add extra unnecessary steps. The most important thing right now is to get functional code, no matter what it looks like!

Good luck and thanks for reading!

“For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much—the wheel, New York, wars and so on—whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man—for precisely the same reasons.”
Douglas Adams, The Hitchhiker’s Guide to the Galaxy

 

 

 

 

 

 

Side Project

arduinoy

I took a little side project this week, working with my daughter to program a rainbow!  After watching Coding 101, I ordered an Ardunio  clone and a Pixel Stick  because I just had to try it for myself…I mean my daughter loves rainbows and I thought this was an excellent chance to teach her some simple projects…

I borrowed code that the people from Coding 101 so nicely provided and with a few modifications, we were up and running very quickly!  She loved the rainbow effect and some of the other effects like “scanner”.  It was a simple, quick project that will hopefully give her some experience she wouldn’t otherwise get!

Now, on to Code Camp progress!

I have been having so much fun doing the algorithm challenges that I have been putting off doing my Development Projects.  I know, I’ve got to get building but those challenges are just like little puzzles begging to get solved!  This is where the self-motivation comes in when you’re doing an online course.  If I had gone to a traditional boot camp, I doubt they would have allowed me to continue without doing projects.  This week, I will buckle down and get some of those projects done!  I promise.  (Well, maybe just one more puzzle.)

For anyone interested or if you’re going through Code Camp yourself, I’ve posted most of my algorithm solutions on Github at My-Code-Camp-Projects. They are named after each challenge and include a description  of the challenge.  I hope this helps some of you out as you’re learning to code too!

Thanks for reading and have a great week!

“For a moment, nothing happened. Then, after a second or so, nothing continued to happen.”  – Hitchhiker’s Guide to the Galaxy

 

 

 

Algo-what?

 

 

Algorithm copy

Algorithms!  If you’re a noob like me or just non-techie you might be wondering what an algorithm is.  Well, it’s just a fancy word for the process of doing something.  If I asked you to find an algorithm to find a record in a sorted list, you might not have any idea where to start. But, if I asked you to find a folder for someone named “Jones” in a filing cabinet, you’ll probably go to about the middle of the drawer, find someone named “Miller”. Well, that’s kind of close to Jones so you’ll probably backtrack some folders to the end of the J’s when suddenly, you’re close enough to go folder by folder to find YOUR Jones. Easy right? Well, that was just an algorithm you came up with! Now, all you have to do it tell the computer how to do the same thing.  That’s where the language comes in.  Instinctively, you can do most all of the problems, if you just try to think of how you would solve a real-world case then worry about the computer part later!

The part of the code above is where I had to decide if a word, or sentence is a palindrome or not. (read the same backwards and forwards like “eye” !)

My first step was to turn everything lowercase with the statement  str=str.toLowerCase(); 

Kinda cool, huh? One line and the whole thing is lowercase!

Then, I needed to get rid of certain non-alphabetic or numeric characters.  I’m sure this isn’t the best method (and this will be really embarrassing later) but I kind of took a Hammer of Thor approach and just did an “if” listing everything I wanted to get rid of….

if (str[place] !==” ” && str[place] !== “,” && str[place] !== “.” && str[place] !==”_” && str[place] !==”-” && str[place] !==”\\” && str[place] !==”/” && str[place] !==”:” && str[place] !==”(” && str[place] !==”)”){
workStr[workPlace]=str[place];

This takes out spaces, commas, periods,dashes, and anything else they didn’t want included. Upon further reflection, all they want included are alpha and numeric characters.  It probably would have been better to approach the problem that way. But, it worked and if I understand customers correctly, working  is near the top of their list of things they want software to do! (There are also things like accuracy and speed but working definately has to be at least in the top ten!)

I love solving algorithms and could probably go on into the night. But, since we have to stop somewhere, now is as good a place as any.  Thanks for reading and we’ll see you next time!

 

 

 In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. – Hitchhikers Guide to the Galaxy

 

 

Watch Your Language…

tp9 copy

Java, JavaScript, C++, C#, Ruby, Python, Elixir, CoffeeScript, HTML, ECMAScript, dBase and a quick Wikipedia search yields about 1000 more …Aaargh!  Where do you focus?  How do you pick what to learn?

I have listened to literally hundreds of podcasts on different languages. If you want to get a web application up and running in no time and you don’t care about how all the stuff “under the hood” works, I think Ruby on Rails in the way to go.  It seems easy, it does most of the programming for you, and you can get functional apps up in a very short time.  (I even heard of someone creating a Twitter type app in only 5 minutes with Rails!)

Listening to MIT OpenCourseware, their focus is primarily on Python. They have some great introductory classes as well as more advanced algorithms but these are more geared for the computer science people. They don’t have much focus on actually building the front end stuff.

I would love to say there was some big philosophical reason I chose to start with JavaScript but it was more a function of what was available.  Although there are great resources for pretty much every language, the code camp I landed at focuses on what’s called Full Stack development.  That means I’m learning how to create the front with JavaScript, there’s a Data Visualization part and the back end with MongoDB, node.js and express.js.

Also, it seems like most of the jobs in my area are looking for full stack developers with JavaScript.  I am having a great time learning to code but getting paid would be really nice too!

I have, so far, completed  216 sections and am almost done with the basic JavaScript part of the camp then the next section includes “basic algorithm scripting”. But, more on that next time!  Also, I’ll talk about getting over the rough spots.  I know there will be areas that might take a little more time to sink in but what do you do to get over them?

Again, thanks for reading and have a great week!

 

“Ow! My brains!”
Douglas Adams, The Hitchhiker’s Guide to the Galaxy