So glad this blog is being phased out…

Upgraded the theme just now and the right bar is gone. Can’t be arsed to figure out what went wrong since the new site is going up either tonight or tomorrow, so shrug your shoulders with me and pretend it’s still there.

Posted in Uncategorized | Leave a comment

Disqus problems, quirks, annoyances, and skepticisms

Disqus: http://disqus.com/ is a managed comment application to essentially take all the work out of handling comments on your website, by having a universal standards approach to handling authentication, moderation, posting and reading.  Its very feature rich and enticing to use since its very easy to setup and install.

Having seen Disqus used in the jQuery API for comments and other developers I hold in high regard, I felt reasonably sure it could become a standard engine every site would use for comments. After using it during my development phase of the new Tab Developer blog, I’m not so sure. There are stability and performance problems that exist which violate the strict cleanliness and efficiency standards I’ve set for the new site. Since I would like to roll out the new blog tonight, I’m going to be keeping Disqus, but will definitely be phasing out in the next release ( 2 weeks ).

The major issues are:

  • Remote resources are loaded outside of my control.  When something goes wrong on their end, the perception becomes something wrong with my site.  This is not an isolated fault of Disqus, but one that affects all managed applications.
  • To the first point, it appears things go wrong often with Disqus.  In the time I’ve been developing, I’ve had issues with # of comments being displayed inaccurately, failure to receive comments, styles not being rendered ( as if the stylesheet was never downloaded ), and an unexpected and unannounced change in layout that affected the implementation ( note: you can revert back… still annoying ).
  • Graceful degradation is non-existent.  With a server side custom approach I can be assured that if someone does not have Javascript enabled or if for some reason a browser does not render the Javascript due to either a parsing error or network blip, that not only will the comments still be visible, but the comment count next to the entries will be accurate as well.  With Disqus everything is loaded via Javascript, so I will have a generic “View comments” link and an annoying “Enable javascript to see comments”.  This is fine for probably most cases, but I prefer to call the shots with my site and I want comments visible with or without Javascript.
  • My last issue with Disqus lies with performance.  On a basic blog entry page, my assests/content/rendering all that jazz ends at ~200ms.  Then I start to see Disqus’s loader and all its assets getting pulled in.  That accounts for 2.8 seconds.  3 seconds total to finish loading a basic page with hardly any content and cached resources, is unacceptable by my standards.

As I finish my cappuccino, I’ll finish with a few thoughts.  Disqus will most likely work well with reasonable expectations and non-insistent perfectionism.  It is still in early stages and has plenty of time to iron network issues, performance, bugs, etc.  I could also potentially use a server side caching mechanism to handle almost all my complaints above – which I haven’t ruled out investigating – but that becomes one more thing to maintain and at that point I might as well just use Django’s built in comment engine.

Were my points valid or irrelevant? Let me know what your thoughts are on Disqus.

Posted in Technology | Leave a comment

AnOrdinaryThing moving to new blog…

Currently working on a new blog which will be available at http://tabdeveloper.com/. There are three phases of the new site and the first will be launching at the end of this upcoming week. I won’t be redirecting anordinarything.com until the second release which isn’t scheduled for two more weeks.

What you can expect are significantly more frequent and higher quality posts, as well as a new layout and design. It will also be utilizing HTML5 and the Django web framework.

Posted in Uncategorized | Leave a comment

javascript document.forms performance versus document.getElementsByTagName(“forms”)

In an online argument about which was the “better” option for efficiency between document.forms or document.images against document.getElementsByTagName(“form”) or document.getElementsByTagName(“img”), I was in the opinion that the latter was faster than the former. Even though it would appear that the former should be faster. The logic behind this was that the DOM level 2 syntax of document.forms would go straight to a collection, while the document.getElementsByTagName would have to query the DOM and traverse the structure to locate each element.

Through my testing using the benchmark below I found my results to be rather mixed. I’m going to compile a table of my results with my system specifications and create a proper follow up. Any suggestions please drop me a comment.

        if(typeof console === "undefined") {
            console = window;
            console.log = window.alert;
        }
        var NUM = 1000, NEST = 10;
        window.onload = function() {
 
            var body = document.getElementsByTagName("body")[0];
            //var body = document.body;
 
            var image, form;
            for(var n=0; n<NUM; n++) {
 
                // Generated nested divs and return the most inner div
                var nested = (function() {
                    var newDiv, prevDiv;
                    for(var i=0; i<NEST; i++) {
                        newDiv = document.createElement("div");
                        newDiv.setAttribute("id", i+"-"+n);
                        if(typeof prevDiv !== "undefined") {
                            prevDiv.appendChild(newDiv);
                            prevDiv = newDiv;
                        }
                        else {
                            body.appendChild(newDiv);
                            prevDiv = newDiv;
                        }
                    }
 
                    return document.getElementById((NEST-1)+"-"+n)
                })();
 
 
                image = document.createElement("img");
                image.setAttribute("src", ""); // Use an image from your own server or make sure you have caching enabled!
                nested.appendChild(image);
 
                form = document.createElement("form");
                nested.appendChild(form);
            }
 
            benchmark();
        };
 
        // Perform the benchmark
        function benchmark() {
            var start = +new Date(); // start of test
 
            // Find images and forms
            var images = document.getElementsByTagName("img");
            var forms = document.getElementsByTagName("form");
 
            console.log("Test concluded took: " + (+new Date()-start) + "ms");
        }
Posted in Technology | Leave a comment

Increasing Javascript Array Sorting Performance

Alright its early in the morning here and I’ve been working all day… specifically on a project that has ~19k objects loaded from a webservice call into an array. On top of that monstrosity, they need to be sorted on a given property that has a numerical value. This was doable through a custom Array.sort method, it was simple to write and achieved the results I was looking for. It was, however, dreadfully slow. On the CEO’s box IE 7 would constantly have a fit throwing the infamous “Script is running slow, continue running scripts?” dialog. The code looked something like this:

	largeList.sort(sortCode);
	// Sort the potential list
	var sortCode = function(a, b) {	
		return (a["obj"].someProp < b["obj"].someProp);
	};

At a glance this looks reasonably efficient. With 18,836 objects in the list, it took 6,516.887ms in 189,578 calls. Nearly 190k calls just to sort, not to mention nearly 7 seconds of processing on a reasonably fast dual core virtual machine!

Being a self taught coder and skipping out on CS theory in college, I missed out on sorting algorithm lessons. After talking with some CS majors and help from Wikipedia, I decided on using the Merge Sort Algorithm. Implementing it was straight forward enough. A little more code, but the results were impressive.

	var sort = function(array) {
		var len = array.length;
		if(len < 2) { 
			return array;
		}
		var pivot = Math.ceil(len/2);
		return merge(sort(array.slice(0,pivot)), sort(array.slice(pivot)));
	};
 
	var merge = function(left, right) {
		var result = [];
		while((left.length > 0) && (right.length > 0)) {
			if(left[0]["obj"].someProp > right[0]["obj"].someProp) {
				result.push(left.shift());
			}
			else {
				result.push(right.shift());
			}
		}
 
		result = result.concat(left, right);
		return result;
	};
 
	var largeList = sort(largeList);

By replacing the code with the above, the sorting only takes 66,601 calls, and executes in…. 1,393.083ms, very impressive!

I do not take full credit for the source above, inspiration came from the Wikipedia psuedo code found here: http://en.wikipedia.org/wiki/Merge and a working Javascript implementation here: http://en.literateprograms.org/Merge_sort_%28JavaScript%29

I will, however, take full credit for making my version the most efficient sorting implementation I’ve seen so far. If you have any suggestions, questions, tips, etc. You know the drill post in the comments!

Update:
I found a way to cut back even more on processing time. By swapping the Array.shift (which recreates the array each time) I instead changed the code to run a counter and managed entries that way.

Posted in Technology | 1 Comment

Lua code complete to identify Tor exit nodes

I’ve been working on what I call TorBlock for a while now in an effort to understand the Lua language and the luasocket library better. Tor is a system that allows end users to use other users networks to anonymize their traffic. While there are several legitimate reasons for using Tor, it is safe to say that most website owners do not want visitors using Tor to access their server. This could be for several reasons, specifically to hinder hacking attempts.

Below is the Lua source code as it stands. I am working on both a lighttpd module and an apache module to embed the Lua logic into. I will also work on something for IIS, but that will require more research in how filtering works internally.

#!/usr/bin/lua
io = require("io");
http = require("socket.http");
ltn12 = require("ltn12");
 
-- Function to reverse ip octets
function ReverseIPOctets(_ip)
    local octets = {}; 
    string.gsub(_ip .. ".", "([%d]*)[%.]", function(_s)
	table.insert(octets,_s);
    end);
    return octets[4] .. "." .. octets[3] .. "." .. octets[2] .. "." .. octets[1];
end
 
-- Get the current WAN address for this machine
function GetPublicFacingIP()
    local html = {};
    local request = http.request {
	url = "http://checkip.dyndns.org/",
	sink = ltn12.sink.table(html)
    };
    html = tostring(table.concat(html));
    local ip = "";
    for match in string.gmatch(html, "([%d]+)([%.]*)") do
	ip = ip .. match .. ".";
    end
 
    return ip;
end
 
-- Test for actual node
function TestExitNode()
    local socket = require("socket");
    local addr = ReverseIPOctets(arg[1]) .. "." .. "80" .. "." ..
        GetPublicFacingIP() .. "ip-port.exitlist.torproject.org";
 
    if socket.dns.toip(addr) == nil then
	print("false");
    else
	print("true");
    end
end
 
 
-- Get argument IP
if #arg ~= 1 then
    print("Too many or too few arguments.");
    os.exit();
end
 
TestExitNode();

If you wanted to test the code using PHP, you could write something like this:

<?php
 
    // Get ip
    $ip = $_SERVER["REMOTE_ADDR"];
 
    // Echo the result
    echo shell_exec("lua TorBlock.lua " . $ip);
 
?>
Posted in Technology | Leave a comment

New Project Idea: Scraping with PHP 5.3.0

Here is a quick example I whipped up using the latest official build of PHP (5.3.0), to scrape content from the New York Times website. I have a good feeling my content management system could put this to use, or any system for that matter… Concerns about caching will be handled by the system. Changes to the New York Times website will have to be updated manually.

I’m thinking of extending this to become more dynamic. This is just the initial code to show how easy it is to power the project. I’m picturing an application that fetches a URL of your choice, regardless if its dynamic or not, so long as it dumps HTML. Then using a similar technique to Firebug… et al, locate the proper element id, position in the dom, etc. to accurately identify it and then display the content separate, unhindered by external CSS.

scrape.php as it stands vanilla… generic.

<?php
	/* 	This experiment is trying to find the top ten most popular articles based on email
		volume from the New York Times.
	*/
 
	// Obtain the New York Times HTML, they are currently using HTML 4 Transitional
	$html = file_get_contents("http://www.nytimes.com/");
 
	// Store it as a DOMDocument
	$document = new DOMDocument();
	@$document->loadHTML($html);
 
	// Save the element
	$element = $document->getElementById("mostEmailed");
 
	// Retrieve the innerHTML
	$innerHTML = function($element) {
		// Create a new temporary document to store the element
		$document = new DOMDocument();    
		$document->appendChild($document->importNode($element,true));
 
		// Return the rendered HTML
		return $document->saveHTML();
	};
 
	// Print out the inner HTML
	echo $innerHTML($element);
?>
Posted in Technology | Leave a comment

Git and getdropbox.com [and komodo ide]

I’ve been a fan of getdropbox.com since they first released a beta client. It is exceptional software and I highly recommend anyone that is still in school or has multiple machines (or friends) to install. Briefly: It allows you to share files with others, yourself and the getdropbox servers (your files remain private and encrypted). The implications of this are phenomenal, it generates photo galleries for you and has a public folder with excellent explorer/finder/linux wm integration.

So I’ve been a fan of getdropbox.com which allows me to synchronize all my files across all my machines to some encrypted remote storage, that’s cool, but I can’t really do any thing with it “programming wise”. This is where git comes in as a local repository; that when updated synchronizes not only the files, but the git source control as well.

I now program completely hassle free on my macbook and desktop and feel safe with git that has cross platform ide integration with Komodo IDE. Another piece of software I highly recommend.

You can find the stuff I talk about at the following links:
GetDropBox – http://www.getdropbox.com/
Git – http://git-scm.com/
Komodo IDE – http://www.activestate.com/komodo/

Posted in Technology | 1 Comment

Two new technologies worth mentioning.

There are two new technologies I use that are worth mentioning that they have received significant updates.
Firefox 3.5 has been released (this is probably old news for most).
http://mozilla.com/firefox/

I am currently running FireFox 3.5 on my Arch Linux box and its working fantastic.  Much faster all around.

PHP 5.3 has been released (be excited!).
http://php.net/

I plan on rewriting a lot of applications I’m currently working on with the intentions of utilizing the new namespaces and true lamda functions (with closures).

Posted in Technology | Leave a comment

From Linux to Windows and back again…

I’ve been a long time Windows user (see Windows 3.1) and previously had never used Linux until giving Gentoo and try and thinking it was absolute garbage.  So I tried out Ubuntu 7.10 and found it to be great.  After a while, I decided to give Windows another try.  I went with Vista 64bit and found it to work exactly as I wanted an operating system to function.  I foolishly upgraded to Windows 7 and experienced nothing but grief.

BUT TIM IT’S JUST A BETA JUST GIVE MICROSOFT TIME… BLAH BLAH BLAH

Sorry guys, but the intent of the Windows RC is to give the public a good perception of the final product, iron out bugs and ship out.  They aren’t going to be revamping the entire UI before RTM.  I couldn’t get it to look or function the way I envision my desktop to look.

So to get to the point of this post.  I’ve moved over to Arch Linux for my desktop.  I’ve been using the distro for a while as my web server and having the most up-to-date packages, is how I like to roll.  It works fantastic as a desktop operating system as well.  The Arch Linux wiki and irc channel are both very helpful resources, and I’ve gotten mostly everything the way I like it.

Here is a screenshot to my current desktop:

Arch Linux Desktop

Well there is still room for improvement, and on the bright side, ActiveState’s Komodo Edit now launches almost instantly instead of having the delay as experienced on Windows and OS X.  Good stuff!

Posted in Technology | Leave a comment