As of this writing I moved on from this host and am moving to this more modern and secure location. http://www.chaddotson.dev
Misc
Jack Daniels 2016 Barrel Tree in Lynchburg, TN
July 8, 2016 Lightning
These are the first lightning photos in several months. It was a good electrical storm but the lightning wasn’t so photogenic.
Saving Console Messages in JavaScript
Have you ever encountered a situation where it would be beneficial to save whatever is written to the console across browser sessions? If you have, you know there are not many solutions. I recently decided that localStorage would be a good candidate to implement a solution to this problem with.
logsaver.js
logsaver.js is a lightweight, simple log preservation script. It utilizes the flexibility of JavaScript to replace the default console.log function with a new, customized one. Along with writing messages to the original console.log, this custom console.log also writes messages to the specified localStorage key.
- To start saving console.log messages, call startSavingLog().
- To stop saving console.log messages, call stopSavingLog().
- To clear saved console.log messages, call clearSavedLog().
- To completely remove the localStorage key used by logsaver, call removeSavedLog().
For more information on options and how to use them, checkout the readme.
While you can copy the source below, I strongly recommend grabbing the latest from github here: logsaver.js.
Notes:
- It doesn’t handle objects well. Results in [Object object] appearing in the localStorage key value. This is because localStorage is limited to strings.
- It is possible to exceed the maximum space allocated to you in localStorage. For desktop browsers, Chrome and Firefox have a 10 MB limit, while Safari and IE both have a 5 MB limit. These number differs for mobile browsers. More details. In this event, logsaver.js will stop trying to save the log and display additional error messages in the console.
v0.1.0 Source
/*
logsaver.js v0.1.0
https://github.com/chaddotson/logsaver/
(c) 2016 Chad Dotson
logsaver.js may be freely distributed under the GNUv3 license.
*/
(function(root) {
'use strict';
var _root = root;
var _localStorageKeyForLog = "console.log.saved";
var _includeTimestamp = false;
var _originalLog;
function _isEnabled() {
return _originalLog !== undefined;
}
function _zeroPad(str) {
str = str + ""; // force it to be a string.
return ((str.length < 2) ? "0" + str : str);
}
function _formatDate() {
return this.getFullYear() + "/" + _zeroPad(this.getMonth()) + "/" + _zeroPad(this.getDay()) + " - " + _zeroPad(this.getHours()) + ":" + _zeroPad(this.getMinutes()) + ":" + _zeroPad(this.getSeconds());
}
_root.clearSavedLog = function () {
if(localStorage[_localStorageKeyForLog]) {
localStorage[_localStorageKeyForLog] = "";
return true;
}
return false;
};
_root.removeSavedLog = function () {
if(localStorage[_localStorageKeyForLog] !== undefined) {
localStorage.removeItem(_localStorageKeyForLog);
return true;
}
return false;
};
_root.stopSavingLog = function () {
if(!_isEnabled()) {
console.log("Not currently saving console.log to localStorage.");
return false;
}
console.log = _originalLog;
_originalLog = undefined;
console.log("No longer saving console.log to localStorage.");
return true;
};
_root.startSavingLog = function (options) {
options = options || {};
if(_isEnabled()) {
_originalLog.call(console, "Already saving console.log. localStorage Key:" + _localStorageKeyForLog);
return false;
}
_localStorageKeyForLog = options.keyForLocalStorage || _localStorageKeyForLog;
var timestampFormatter = options.timestampFormatter || _formatDate;
_originalLog = console.log;
console.log = function(){
_originalLog.apply(console, arguments);
var formattedTimestamp = timestampFormatter.apply(new Date());
var message = "\n "+ formattedTimestamp + " :: " + Array.prototype.join.call(arguments, ", ");
try {
if(!localStorage[_localStorageKeyForLog]) {
localStorage[_localStorageKeyForLog] = "";
}
localStorage[_localStorageKeyForLog] += message;
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
_originalLog.apply(console, arguments.splice(0, 0, "SAVE FAILED - LOCAL STORAGE QUOTA EXCEEDED"));
} else {
_originalLog.apply(console, arguments.splice(0, 0, "SAVE FAILED"));
}
}
}
_originalLog.call(console, "Now saving console.log to localStorage Key:" + _localStorageKeyForLog);
return true;
};
})(this);
Decisions in 1 Pomodori
All programmers suffer from analysis paralysis at some point in their career. The trick is bringing it to a swift conclusion. Try this to move forward next time. Give yourself 1 pomorodi (25 minutes) to analyze the problem. After that make a decision and go with it. Whatever falls out is whatever falls out. At least you were not over-analyzing the problem and getting nowhere.
Node.js vs Python vs PyPy – A Simple Performance Comparison – Updated


Some History
This is a followup to my original post: Node.js vs Python vs PyPy – A Simple Performance Comparison. This article corrects a discrepancy caused by a slight difference in the JavaScript implementation which skewed the Node.js results.
The Algorithm
As stated in the previous article, I’ve attempted to implement the same single-thread, brute force, recursive algorithm in many different languages. There is nothing overly special about this algorithm and I’ve made no attempts to optimize it.
The Findings
Node is fast, very fast. It easily outperforms any of the other implementations I’ve included in the puzzle’s repository. As you can see by the included charts, the performance difference between Node.js and out-of-the-box Python is very significant and the difference between it and PyPy while less pronounced is significant.
Special Notes
- I’ve placed my source on GitHub at the following url: https://github.com/chaddotson/puzzles. It now contains functional N-Queens puzzle implementations in JavaScript, Python, Lua, Scala, and Ruby. There is also a version in Rust, but that needs to be updated to the latest syntax before it can be run again.
- This is just with one type of algorithm, the best solution might and probably does change depending on what type of application you are researching. For webserver performance, Node.js is slightly better than PyPy running Tornado.
- This algorithm is a simple brute force algorithm, there are many faster and better ones out there.
- See the original article for the Node.js vs Python vs PyPy – A Simple Performance Comparison for more details memory performance.
The Flood of Social Media Posts – Whats Wrong, How To Mitigate It, How To Fix It
What’s Wrong
Since its creation, social media has taken off at an exponential rate. Each day more and more people are creating accounts and contributing to the feed. Facebook is the service most readily adopted, mainly because of the people already on it. In the case of Facebook, lets say that the typical user has 200-300 friends and lets say that just a quarter of those (50 of 200) are enthusiastic posters (2-3 posts/day). That equates to somewhere north of at least 100 posts per day then add to that the posts from your other friends. Lets make a guess of an overall total of 200 posts/day on just that one social media outlet. Facebook’s solution to the inundation of posts is the top posts vs recent posts feature.
Skip to the services that I think are the most susceptible to inundating users with content: Twitter and Pinterest. As a user of Twitter, it seems that I have trouble following over 40 people. Once upon a time I followed near 90 people and found that useful posts actually got buried in the noise. Pinterest on the other hand seems to violate all that is good with respect to UI design; it is way to busy and your eyes don’t follow any particular lines. Liberal use of pinterest’s follow feature can unintentionally muddy the content you see.
Tips On Dealing With It
I think the only way to fix usage of Twitter is to limit the number of people you follow. Pick high quality, low post rate users. This will improve the overall quality of content you get. For Pinterest, limit the number of users or boards you follow.
How To Fix It
How do you fix being inundated with content? Facebook is certainly trying to fix it via their “Top Posts” feature. The top posts feature attempts to make guesses about what you want to see based on your interests, what you’ve looked at in the past, and probably other metrics (and controversial stuff such as a recent study). Even though I don’t care for their current top posts feature I believe Facebook is on the right track. It all boils down to the ability to listen to everything but only pay attention to what your interested in, even when you may not 100% know yourself.
I think the ultimate “Top Posts” algorithm would take into account the following:
- What you’ve looked at in the past. (Given)
- Users would be given preferred tags based on what they view.
- It would tag each post and each would receive an initial ranking based on the types of posts the user normally make.
- The initial ranking score given to a user’s posts is a function of how well their posts have done in the past.
- Each post’s rank is updated in each of its tags as people view them based on their rank in the tag category.
Up Next: I may decide to make a post discussing a theory of how people leave one service and adopt another.
The Early Days of Flight
This post started from a comment I made on facebook about the “Volocopter” story on CNN. At the time my comment was “Why does this look like something from the early days of flight?” That it turns out is a very good question and an even better follow-up, “Aren’t we in the early days of [motorized, human] flight?”About 50,000 years ago, humans reached what is called behavioral modernity[1], “the point at which Homo sapiens began to demonstrate an ability to use complex symbolic thought and express cultural creativity”[2]. I think that is the reference point I will use for this post. Am I leaving something out? You bet, a heck of a lot in fact. Another reference point I considered using was the control of fire by homo-erectus 400,000 years ago[3]. I ultimately decided on using the data of behavioral modernity because even after tens of thousands of years separating, those humans are us both anatomically and behaviorally. We’ll use this timeline of “modern humanity” throughout this post.
So back to the topic of the post: “Aren’t we in the early days of [motorized, human] flight?” I believe the answer is a very resounding “yes.” If we think about history of boat/shipbuilding, I believe can get a feeling for how new it is.
Let us compare two examples of what humans have created at the endpoint’s of “modern humanity.” At between 9,523 and 10,053 years old the Pesse Canoe is thought to be the world’s oldest boat[3]. The Pesse Canoe is a simple, dugout canoe discovered in the Netherlands. Fast-forward approximately 10,000 years to the USS Gerald R. Ford (CVN-78) slated to launch in 2015[4] which will be the most advanced ship built by human-kind at the time of its launch. We, all to often find ourselves bounded by the technological achievements since the beginning of the space race, but that’s 10,000 years of well-earned technological achievements. I’m sure that somewhere here there is a Moore’s Law of human ability (I say ability because I don’t feel intelligence nor ingenuity to be the right word). That ability is based on what knowledge we have gained up to that point in time.
So now that we’ve talked human technological advances in boat/ship building, let us think about what brought us here, human flight. Rudimentary usage of the science (understood or not) behind flight have been understood for anywhere between 2,000 and 2,500 years[6] but it wasn’t until Leonardo da Vinci’s drawings in the late 1400’s that humanity really started showing an understanding of the concepts behind flight. For the most part, Leonardo’s best flight related discoveries were because he studied and tried to copy nature. While successful attempts in winged human flight have been made as far back as the first millennium AD, it was 1903 when the Wright Brothers (credited) finally achieved winged, motorized flight. In the 110 years since we have constructed advanced aircraft such as the Airbus A380.
As it turns out, there are a lot of significant inventions marking the timeline of human creations. So much so I believe it is necessary to add “when a technology becomes useful” as a simplifying assumption to my statement. Under that premise, our current capability in shipbuilding is based on 10,000 years of progressive technological advances and while our current capability in motorized flight is based on the culmination of thousands of years of technological advancement, its only been 110 years since we put it all together. So, the answer is yes, we are in the early days of motorized, human flight.
Disclaimer: I am a computer scientist not a writer or history scholar. This post is a collection of what I believe and what I’ve put together from the internet.
References:
- “Behavioral modernity.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (8 November 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/Behavioral_modernity
- “Human.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (26 November 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/Human
- “Control of fire by early humans.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (24 November 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/Control_of_fire_by_early_humans
- “Pesse canoe.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (27 February 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/Pesse_canoe
- “USS Gerald R. Ford (CVN-78).” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (22 February 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/USS_Gerald_R._Ford_%28CVN-78%29
- “History of aviation.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (24 February 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/History_of_aviation
- “Early flying machines.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., date last updated (27 February 2013). Web. Date accessed (27 November 2013). http://en.wikipedia.org/wiki/Early_flying_machines



