justinlillico.com

Nov 24, 2017

Learning JavaScript

I know what you're thinking... Clearly, I should also be learning how to use software like Adobe Illustrator and not rely so heavily on MS Paint. But hey, I know it and have been using it for years, seems to do most things I need it to! So this week I have been getting well stuck into developing this website. They gave me the task of creating a method of arranging thumbnails by date, views and type. This proved to be just the level of challenge I needed. After sitting in front of my computer for nearly two days researching the things I could do using the JQuery library and vanilla JavaScript, I built a few functions to take care of the job. php echo "var js_views_dates = ["; for ($i = 0; $i < sizeof($articles_info); $i++) { echo " [ " . $articles_info[$i][6] . ", " . strtotime($articles_info[$i][7]) . "] ,"; } echo "];"; ? First, I converted the existing array containing the views and dates I needed to know into a JavaScript array. I found a few ways to do this but they were all to complex for me at this level so I came up with this method on my own. Basically just writes the JS on the fly by echoing strings. Pretty simple, but effective. I won't bore you with the event listeners. I used Jquery for those. Let's skip to the functions I called AFTER the document was ready... //Get the elements. parent = document.getElementById("article_box").children; //Here, we combine the object in its original form along with the views and date gathered from the php. //0 : views //1 : dates for (var i = 0; i < js_views_dates.length; i++){ js_article_info[i] = [parent[i], js_views_dates[i][0], js_views_dates[i][1]]; } //This preserves the original order of the articles original_order = js_article_info.slice(); So here I get the elements, attach them to the views and dates I got before and save the list as it currently is. I use this when the user chooses to reset from custom arrangements. function setupOrder(original_array, order_by, high_low){ //This is a sort function that arranges the array by the first dimention, in numeric lowest to highest order original_array.sort(function(a, b){ if (a[order_by] === b[order_by]) { return 0; } else { return (a[order_by] < b[order_by]) ? -1 : 1; } }); if(high_low){ original_array.reverse(); } So I learned what the sort() function did and how to get it to do my bidding. I feel like this is a function I may end up taking advantage of a lot. This is called when the user chooses the arrangement they want. It sets the order of the list based on an integer value representing their choice. function updateArticles(order){ //This while loop simply removes the contents of the parent div by ID. while (document.getElementById("article_box").hasChildNodes()) { document.getElementById("article_box").removeChild(document.getElementById("article_box").lastChild); } //This for loop appends the objects from start to finish of the new array. for (var i = 0; i < order.length; i++){ document.getElementById("article_box").appendChild(order[i][0]); } } Finally, this function is called after setupOrder() to update the elements on the page based on the new information. Once I had these functions built, the rest of the logic was only a line or two in the event listeners. I feel like it was efficient, although I'm sure there are many other methods and this is far from the most efficient.

Nov 19, 2017

Back to basics

So since my last post, I have begun working as a volunteer. The Arduino project is on hiatus. As it happens, it is considerably difficult to acquire paid work when you are but a meagre, inexperienced web developer. And by inexperienced, I mean I don't have any idea how to build websites. I get the concepts and the word JavaScript doesn't leave me thinking about some kind of dialogue for a coffee cup but as I am rapidly learning, this is not enough. I have been graciously afforded an opportunity to get some hands-on experience, even after I admitted I was slowly drowning in alien code. The website I am working on is not being built from the ground up, but my understanding of it is. I am forced to study everything: from where every bit bounces about to what the CSS colour code for deep cyan is. This way I learn its function. Luckily for me, when it comes to problem solving, I can't sleep until I get it. Seriously, I've been known to avoid eating'nearly dying as a consequence'in order to just fix that one little problem' But I suppose that's a common attribute for coders. We love the punishment. I am a precious little snowflake though. I like to stare at these riddles for so long that the symbols that represent math and logic slowly become stripped of their meaning. Some people like football, I like brain melting. What of it? Anyway, I learn this way. As a wise man (aka Turk from the hit television series Scrubs) once said: learn by doing. I find it works best for me. So, while I may be at school, have no experience, thirty years old and currently exchanging precious hours of my life for money carving up deceased beasts, I have this tenacious drive on my side. If you are a potential employer reading this, please don't be deterred. I am actually quite professional.

Oct 10, 2017

Arduino Meltdown

So today I blew up my arduino. I have been working on a project that involves regulating the temperature inside a refridgerater using the built in compressor and a small heater. You guys will hear all about it in the portfolio section when it is finished. Seriously, I've been recording the whole thing. Anyway, today I was trying to wire in these new relays I got from the job and ended up absent mindedly letting the end of a wire bridge a component on the Ardunio board and it started smoking at me. So that's a thing that happened, I'll soon have another one so never fear!

← Previous Next → Page 11 of 12