Thursday, April 28, 2011

JavaScript Web Workers Local Chrome : Enable via Flag / Parameter

If you are a JavaScript developer that is interested in writing multi-threaded applications with JavaScript, you may be looking into using Web Workers to accomplish this.  And, if you are using the Google Chrome browser for running and/or testing your web worker code, you may have run into what appears to be a problem with running web workers on your local machine. But, do not worry, there is a way to enable local Web Workers in Chrome Browser without too much difficulty.

Symptom
Web-Workers will appear not to work when using the Chrome browser to run local HTML / JavaScript that uses web workers. This same code works fine when hosted on a web server though. (this is the case through at least the Stable version 10 of Chrome Browser).
Solution / Fix Local Web Workers in Chrome
OK, so how to you get Web Workers to execute locally when using the Chrome browser? Well, currently there is a flag that you will have to pass to the browser on startup.  But, even that can look as though it did not work unless you have also closed down all instances of Chrome before launching the browser.  So, be sure to do this:
  1. Close any open instances of the Google Chrome web browser
  2. Launch the Google Chrome browser with the --allow-file-access-from-files flag; this will make your chrome.exe launch look like the following example (or similar):

    "C:\Users\UserNameHere\AppData\Local\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files

  3. NOTE: do not make this your default chrome execution setup unless you are willing to take the security risk associated with having that "allow-file-access-from-files" flag active; as the flag implies, it opens up some additional paths to file access that may ultimately provide a path to security exploits.  I personally was not worried, as I was running my JavaScript / HTML5 testing of Web Workers code within a virtual machine and not on my production desktop.  I always suggest using virtual machines for this type of thing.
Some Web Workers Example Code
This was quickly copied from Wikipedia's web-worker example (for using threads to calculate prime numbers), and very slightly modified to include a reminder of why the local Web Worker code may appear not to work in the Chrome Browser.

C:\WebWorker-ThreadTest\Prime-Webworker-Test.html
<!DOCTYPE HTML>
<html>
 <head>
  <title>Worker example: One-core computation</title>
 </head>
 <body>
  <p>The highest prime number discovered so far is: <output id="result"></output></p>
  <p>You must close ALL Chrome windows first...<br />
  Then, launch chrome from command-line with this flag to enable web-workers:<br />
  "C:\Users\UserNameHere\AppData\Local\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files</p>
  <script>
   var worker = new Worker('Prime-Webworker-Test.js');
   worker.onmessage = function (event) {
     document.getElementById('result').textContent = event.data;
   };
  </script>
 </body>
</html>


C:\WebWorker-ThreadTest\Prime-Webworker-Test.js 
(place in same directory as above HTML file)

var n = 1;
search: while (true) {
  n += 1;
  for (var i = 2; i <= Math.sqrt(n); i += 1)
    if (n % i == 0)
     continue search;
  // found a prime!
  postMessage(n);
}

You should be able to run the local Web Workers test using Chrome browser now...
Be sure to launch Google Chrome browser using the command-line parameter / flag specified earlier in this Blog.  Just open the HTML file (Prime-Webworker-Test.html) and if all is working properly, you should see a series of prime number displayed at the top of the web-page in quick succession.

Web workers offer a VERY BASIC means for implementing some multi-threaded code in JavaScript.  It is not anywhere near as powerful and flexible as a higher-level coding language or framework like Delphi or DotNet or Java may offer, but at least it provides a way to do some rudimentary multithreading.  Also, JavaScript web workers are not exactly "light weight" thread implementations, so be sure to take not of resource usage as you implement threading with this technique.

Webworkers are not implemented in all browsers, but they do exist in the only browsers that matter  -- is this an obvious slam on IE  :)

Wednesday, April 27, 2011

VariCAD 2011 : 2D & 3D CAD Software Update Release

If you are a CAD (computer-aided-design) hobbyist or professional, you will be pleased to know that VariCAD has just released another update to their very capable and affordable 2D (two dimensional) and 3D (three dimensional) CAD Software program.  I fall into the former group (hobbyist and self-declared "inventor"), and I really enjoy being able to create 3-dimensional models of my various "inventions" and ideas.

When I shopped around for *reasonably* priced CAD software with powerful 3D-modeling features, VariCAD was the one offering that really stood out (read my prior Blog where I review VariCAD and discuss my trials of competing free and affordable 3D CAD products) to me after evaluating quite a few competing CAD products — so I bought it.
2011-04-18 — VariCAD 2011 1.x RELEASE SUMMARY: this latest releae includes numerous improvements to the 2D drawing functionality portion of VariCAD. This latest VariCAD 2011 release contains rebuilt and significantly better DWG/DXF interface, new or changed 2D functions, better support of 2D NURBS objects (splines), significantly improved user interface and improved STEP input. Available for Linux and Windows platforms (32bit and 64bit also).

Pen and graph-paper can only take you so far when planning out even moderately complex engineering or product-design projects, and the time-savings and accuracy that is obtainable with software like VariCAD can easily make the price well worth the investment.

VariCAD Example : Real-Life Time/Cost Savings
One of my more recent VariCAD 3D-layout projects that saved me a TON of time was, of all things, designing an optimal heating and air-conditioning (HVAC) ductwork system for a planned new geothermal system install at my residence.  I started out taking measurements with a tape measure and then sketching some ideas on paper, but I was soon overwhelmed with overlapping duct trunk-lines that had all sorts of multi-dimensional constraints on their placement (especially due to immovable walls); it quickly became apparent that pencil and paper could not ensure success on this project — VariCAD to the rescue!

Geothermal Ductwork Planning in 3D

As the above VariCAD 3D scene rendering from one view/perspective demonstrates, this was a rather complex ducting plan to implement, and the color-coding of various trunk lines in VariCAD (for supply air and return air that would feed out and into the 6-ton WaterFurnace geothermal unit) saved the day and kept me from going insane as I tried to visualize how this would all work.  I also placed a couple gray slabs into the drawing to remind myself of where I was passing through immovable walls, and this really helped with the visualization process too.

This 3-D CAD software mockup of how the proposed geothermal ducting could be implemented gave me the confidence I needed to know that if the project moved forward, it would work as planned — this is a confidence I could not have otherwise had, as the scene was just too darn complex to visualize with simple hand-drawn orthographic sketches or *attempts* at 3D.  This model was created to-scale, and everything that worked in the CAD software would work in reality because of the accuracy the CAD software brought to the problem at hand.  The bottom line here is that a $600 piece of software avoided what could have been countless hours of expensive reworking of ductwork "on the fly" from a lack of proper planning.

So, if you have any desire to expand your abilities as a home-improvement expert or hobbyist, perhaps the latest VariCAD 2D/3D CAD software (which has free 30-day trial) may be for you also.  I found the software INCREDIBLY USEFUL as an individual that wants to ensure the best outcome for home-improvement projects, and I can only imagine how wonderful a tool like this would be to professional ductwork installers (especially where re-configuring existing ductworks for geothermal, etc. is happening).  I can see this being used as a marketing tool also, so customers can visualize what it is you (the contractor) brings to the table and plans to implement.

Geothermal ductwork-planning in 3D is just one of the many uses I have found for this software. VariCAD 2011 furthers my appreciation for the cost-savings and time-savings that design-automation software can offer, and I have many more projects in the works that I am and will be using VariCAD to perform 2D and 3D CAD layout for.  I find myself quickly going straight to the computer when I have ideas to "sketch out" now, thus bypassing paper/pen altogether.   Hopefully you find this software to be equally useful and valuable.

UPDATE (2013): I have continued to use VariCAD 2012 and VariCAD 2013 and love the product.  Additional features and enhancements have come along to make an already great product even better.  Give it a try, and if it just "clicks" with you, productivity is bound to follow.

Continue to read this Software Development and Technology Blog for computer programming articles (including useful free / OSS source-code and algorithms), software development insights, and technology Techniques, How-To's, Fixes, Reviews, and News — focused on Dart Language, SQL Server, Delphi, Nvidia CUDA, VMware, TypeScript, SVG, other technology tips and how-to's, plus my varied political and economic opinions.

Thursday, April 21, 2011

Politics of Green Energy : Propagating Ignorance via Ideology

Humans are hopelessly spiraling toward their own demise — thank politics for speeding the process!  For being the supposed smartest animals on the planet, we sure do everything in our power to prove our ability to ignore fact in favor of ideological beliefs and opinion.  Science and technological advancement is wonderful: as long is it does not surface data that challenges the merits of our individual pursuits — especially the pursuit of "profit".

I am so completely disgusted with the politics of green-energy (or should I say the politicization of green-energy, and the outright disregard for fact — a nice way of saying "lies") as propagated by proponents of existing, carbon-intensive, and ecologically destructive sources of energy.  As is with most ideologically-driven hyperbole, hypocrisy runs rampant throughout the "logic" employed to "defend" what should be nearly indefensible positions for the continued push to use fossil fuels while global CO2 levels soar in direct relation to the combustion of those fuels.

Let me begin by recognizing the fact that not ALL "right leaning" (Republican / conservative / etc) backers agree with the illegitimate position that humans are not responsible for climate change.  In fact, some very noteworthy Republicans, conservative business-leaders, and wealthy individuals are very adamant in their promotion of green energy and ending the human self-destruction that is occurring as a result of fossil-fuels consumption.  But,...

I just read this article about how Americans are split on what is causing global climate change; and, you perhaps you already guessed how they are split: right down political-party lines!  If you consider yourself a Republican (i.e., conservative) you are statistically almost certain to believe the rhetoric spewed by party leaders that push concepts proven utterly false... things like blaming "natural causes" for climate change.  Again, this is PROVEN false, PROVEN!  But, politics make proof become "proof"; science that does not reinforce a politically-motivated position is suddenly just "science"; and so on.

Never mind the fact (and transcripts that back it up from the Bush/Cheney era) that the Republican party's entire strategy for exploiting their political base (to keep carbon-intensive energy running full-steam ahead) was to simply create DOUBT.  It worked.  Many of their followers only needed the slightest suggestion of "doubt" that climate change was due to human activities; they now had what the party leadership desired most: a "position" to cling to regardless of all the true evidence and science to the contrary.  This self-engineered doubt is all they continue to need to reject the fact that human activity is plunging this world into a state of unprecedented CO2 buildup and associated climate change.

Never mind the fact we can use the carbon isotope-typing to analyze atmospheric CO2 concentrations and determine that the CO2 came directly and unequivocally from human activity and the burning of plant-sourced matter (i.e., coal, oil, natural gas) and NOT from things like volcanoes and other ridiculous explanations (whose CO2 emissions produce a different isotope signature).  All the proof just becomes "proof" when ignorance is reinforced via ideology.  It truly is a shame, as we will all pay the price for this ignorance regardless of our political affiliations.

Perhaps we should get to the root-cause of this politicization of climate-change and the creation of any alternative "theory" of climate-change: MONEY!  That's right... like every human activity that goes contrary to common-sense and proof that an activity is bad for us as a whole, money lies at the root of this discussion.  The foot soldiers (i.e., the political masses) that quickly render their backing (by way of votes) to those pushing a particular agenda that is contrary to scientific evidence will likely realize little, if any, economic gain by lending their support to those at the top.  But, there are certainly many individuals and corporations that stand to profit handsomely if we continue to ignore human-induced climate change and continue to embrace CO2-intensive energy sources.

There is a lobbying force (i.e., money) that is intent on keeping their carbon-based cash-cow pumping out not just more money but also more CO2, and they will do anything to continue to ensure they have the votes to protect them and their climate-altering activities; all courtesy of ideological splits among the populace.  Their hope is that you turn off your brain and embrace the ideological ignorance that continues to reign supreme — never mind the fact that we are creating what is likely to be irreversible damage to this planet we all live on.  Never mind that no amount of money will ever make up for the fact that we will have doomed the planet in the process.
 
Now, let us discuss some of that hypocrisy that always accompanies such ideology.  One of the first things we hear is that going green is "too expensive".   Sure, wind and solar and geothermal may appear relatively expensive compared to other energy sources when the cost of environmental-destruction is left out of the equation, but when included, green alternatives are VERY competitive, and they are increasingly becoming more efficient and more competitive at the same time CO2-producing energy is, and will continue to be, increasingly expensive if the true costs of CO2 emissions are considered in the equation.  Solar technology is rapidly evolving and becoming cheaper and more efficient; wind turbines are becoming larger, more efficient, and thus more competitive also.

And, when considering the true cost of burning fossil fuels and the cost (via environmental damage and alteration from CO2 and other toxic emissions), the worst CO2 offender is COAL burning power plants.  The coal industry knows this and knows they have to create yet another lie to sell the public and get the votes to keep their profits rolling in, so they have coined this "clean coal" concept as their solution.  Sounds great does it not?  "Clean" coal.  Sure.  Wonderful.  But, then there is the fact that there is NO SUCH THING and not a single coal-burning power plant is in existence that is not emitting CO2.  And, to capture CO2 from coal-burning is EXPENSIVE and it takes MORE energy (as much as 1/3 of the total fuel burnt generating power will go to power sequestration if we are to capture all the CO2 produced from the plants) and an insanely complex infrastructure to implement.  This WILL end up on your electric bill!  And, of all the insane and desperate acts that humans could undertake, "clean coal" (and similar carbon-capture schemes) ranks number one.  Investing in such a dead-end is not "investing"... it is flushing money; but, for as long as you are willing to flush it into the coffers of the coal-industry, they will willingly take it.

Next there is the "clean" natural gas crowd.  Sure, it produces 1/2 the CO2 emissions as coal burning, but where is that gas coming from and what emissions are involved in the acquisition of that "clean" natural gas?  Watch the movie Gasland for starters and you will soon understand that this is anything but a "clean" fuel... hydraulic fracturing technology is what is enabling this (lie known as) "clean" natural gas, and it is causing widespread release of hydrocarbons and chemicals into the air and groundwater.  But, money rules the world and the natural gas boom throughout the USA is producing enough cash to retain the number of votes they need to continue this toxic energy pursuit.

We do not have the resources to waste on existing dead (and deadly) technologies while the remainder of the world passes us by with renewables.  As we flush our money (or, should I say other people's money - since so much of our money is *debt*) down the drain on carbon-intensive energy production, we are flushing our future simultaneously.  The politics of energy production are making us waste valuable time and money on unsustainable carbon-based technologies when we could be truly investing (where spending our money will produce a return in the longer term and not just go, quite literally, up in smoke as we burn carbon-fuel sources instead).

Please consider the true cost of carbon-based energy sources in any comparison to green-energy that you make.  Take time to understand the science behind energy production (and associated emissions).  And, get the facts about how much power is hitting this planet every day just in the form of sunshine, which we CAN easily harness for our power needs.   There is an amazing abundance of alternative energy available to us; what is not available in abundance is the propagation of this fact and the associated facts about human activity causing global climate change and CO2 rise.   I sure hope humans can overcome political ideology before it is too late.