{"id":2127,"date":"2014-02-06T20:31:39","date_gmt":"2014-02-06T20:31:39","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=2127"},"modified":"2014-02-06T20:34:07","modified_gmt":"2014-02-06T20:34:07","slug":"node-boilerplate-web-dev-week-jan-2014-1","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/node-boilerplate-web-dev-week-jan-2014-1\/","title":{"rendered":"Node, RegEx &#038; JS | Week #1"},"content":{"rendered":"<h3>Hackathon Starter &#8211;\u00a0A boilerplate for <strong>Node.js<\/strong> web applications.<\/h3>\n<p>This framework \/ skeleton project really got me thinking about developing actual websites in Node again. I originally starting learning Node with the intention of producing great web-based apps on a JavaScript code-base. But time went by and I really didn&#8217;t relish the fact that I&#8217;d have to migrate all of the login systems, structure, forms and account management details that I had created in other languages.<\/p>\n<p>This boilerplate seems to offer just about everything I&#8217;d need to get a solid website framework in place. My original plan was to continue reading about the Express framework, but I&#8217;m now considering just installing the Hackathon Starter boilerplate and studying the code to see if I can &#8220;hack&#8221; my way into creating a basic Node.js website.<\/p>\n<p><a href=\"https:\/\/github.com\/sahat\/hackathon-starter\">https:\/\/github.com\/sahat\/hackathon-starter<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Avoiding anonymous JavaScript functions<\/h3>\n<p>Todd Motto argues that there is no good reason to use an anonymous function in JavaScript, and that might actually be a bad practice. I agree with almost every argument, except this one: They create messier \/ unclear code.<\/p>\n<p>I would have qualified that with &#8220;They can&#8221; create messier \/ unclear code. Let&#8217;s take a simple jQuery event handler for example:<\/p>\n<div>\n<pre><code>$('button').on('click', function() {\r\n    this.hide();\r\n});\r\n<\/code><\/pre>\n<\/div>\n<p>It would be difficult to argue that a &#8220;named&#8221; function would make any kind of sense in this scenario. There isn&#8217;t any real need to create a reusable function simply to hide an element.<\/p>\n<p>For the most part though, I do agree with Mr. Motto. The urge to create anonymous functions should be resisted in all but the simplest cases.<\/p>\n<p><a href=\"http:\/\/toddmotto.com\/avoiding-anonymous-javascript-functions\/\">http:\/\/toddmotto.com\/avoiding-anonymous-javascript-functions\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>What I learned about RegEx this week<\/h3>\n<p>Non-capturing groups are really handy when you need to include words or phrases in your regular expression, but don&#8217;t want them as part of your result. Where you might normally use:<\/p>\n<p>^([0-9]+)\\s(dogs|cats)<\/p>\n<p>In this case, you might only care about the number, but the second group will be including in your results, even though you only wanted to match against it.<\/p>\n<p>To prevent this, just precede it with a ?:<\/p>\n<p>^([0-9]+)\\s(?:dogs|cats)<\/p>\n<p>This will cause your group to go &#8220;un-captured&#8221; and not appear in the results.<\/p>\n<p>&nbsp;<\/p>\n<h3>The most ridiculously easy way to introduce a loading spinner to your site<\/h3>\n<p>I was creating a reporting tool for a client this week and some of the reports were taking upwards of 20 seconds to load. I thought a loading spinner might make sense, but didn&#8217;t really want to deal with flushing output and all that.<\/p>\n<p>I used jQuery to capture the click event on any navigation item that loads a new report. Then simply displayed a CSS spinner at that point, before the click event bubbled up to the browser to load the page.<\/p>\n<pre>$('nav a').click(function() {\r\n    \/\/ load your CSS spinner of choice\r\n    $('section').html('&lt;div class=\"spinner\"&gt;&lt;\/div&gt;');\r\n\r\n    \/\/ after this, the event will bubble up to the browser to load the page\r\n});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Web Dev week number one brings Node.js news, reasons to avoid anonymous JavaScript functions, a RegEx tip and really quick way to introduce a CSS loading spinner to your site.<\/p>\n","protected":false},"author":1,"featured_media":2133,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[276],"tags":[235,86,277,124,115],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2127"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=2127"}],"version-history":[{"count":7,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2127\/revisions"}],"predecessor-version":[{"id":2136,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/2127\/revisions\/2136"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media\/2133"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=2127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=2127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=2127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}