Link Checking Module - 1st attempt
March 19th, 2008 by Aaron
So I wrote some code the other day. It sat in my code repository and I never tested it. I was pretty certain it was going to be some good code, though.
A few weeks later I came back to it and looked through it - and laughed!! Anyone figure out where ALL the holes are in this code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | <?php class linkChecker { protected $_links = array(); protected $_sites = array(); public function __construct() { } public function addSite($site) { if (in_array($site, $this->_sites)) { throw new linkException("Site already in list"); } $this->_sites[] = $site; } public function processSites() { foreach ($this->_sites as $site) { $this->_processLinks($site); } } protected function _processLinks($url) { $this->_addLink($url, $url); $d = new DomDocument; @$d->loadHTMLFile($url); foreach ($d->getElementsByTagName('a') as $link) { $this->_addLink($link->getAttribute('href'), $url); } unset($d); } protected function _addLink($link, $url) { $l = new checkableLink($link, $url); if (!isset($this->_links[$l->url])) { $this->_checkLink($l); $this->_links[$l->url] = $l; } unset($l); } protected function _checkLink(checkableLink &$checkableLink) { $d = new DomDocument; $d->loadHTMLFile($checkableLink->url) or $checkableLink->valid = false; } } class checkableLink { public $host = null; public $url = null; public $checked = false; public $valid = true; public function __construct($link = null, $url = null) { if (stripos($link, '/') === 0) { $this->url = $url . $link; } else { $this->url = $url; } } } class linkException extends exception {} ?> |
Spell Checking in Eclipse PDT
July 9th, 2007 by Aaron
Although I’d like to pretend that my side jobs always are pure programming, but alas, not the case. There are times when the users send word docs to me and I have to convert them to html. Now, even these word docs might have spelling mistakes - but thats just not ‘acceptable’ to them - I should correct those issues too! Whats up with that? But anyway, I now have a good plugin to do spellchecking in eclipse - that won’t break on code (well not sorta…). This supports spell checking as you type, language specific options, and more. At any rate, lets check out eclipse’s built in spelling feature, and then see why this plugin I found is better: Continue reading Spell Checking in Eclipse PDT
When to be OOP - and how much… Lesson Learned!
June 25th, 2007 by Aaron
I just finished reading a snippet of a book about design patterns - of which Strategy, Adapter, Decorator and others were discussed. It got me to thinking about my design patterns that I used in JEMDiary - and what I’ll be using in this project.
The trouble comes when you start trying to figure out how implicit and explicit your OO design should become - for example, do you create a new object and rely on it to bring in its own db connection (and tightly couple it) or provide more public methods for it to explicitly create itself, passing in a db connection that hits an interfaced class instead. Do you use the many strategy type patterns and keep a more loose architecture, or be more specific to yoru project and make it possibly more private (and more efficient)?
Well here is what I’m going to do…
Continue reading When to be OOP - and how much… Lesson Learned!
Planning for application development
June 17th, 2007 by Aaron
In my “younger years” in the coding world, I’d have an idea like I have right now with the website monitoring project - and immediately start coding. I’d get the framework done, implement a feature or two, and then finally start thinking about my requirements. Predictably, the code would turn into an unmaintainable mountain of crap - and I’d be wasting more time rewriting and refactoring than I wanted. For this project, I decided to take steps against this happening.
Continue reading Planning for application development
Website Monitoring Project
June 12th, 2007 by Aaron
Recently, while working at (”the triangle”), I came across a project that I had to research. This project’s definition included finding an up-time monitoring system for our websites as well as a dead link finding feature. So, after doing about 8 hours worth of searching, I didn’t find anything that met our needs. There were tons of dead link finders that could be ran on demand off your desktop platform, but very few that could be scheduled and ran remotely. Additionally, it was hard to find any remote uptime monitoring systems that allowed the flexibility I was looking for - the ability to check for website up - to not give false positives, and to remotely test functionality (kind of like a remote unit test).
Personally, lately my webhost just upgraded something, and now all of my PDO updates are also crashing. I wanted to write a system that would determine what happened and what may fail on shared hosting as well… I think it would be something that you could install with a api-key on your hosting to remotely watch for changes.
With all of this in mind, a new project spawned in my mind. This project will help fuel my new development, allow me to join the open source community officially, and also hopefully help fund some of 102 Degrees’ bills. I came up with the ‘Website Monitoring Project’. I don’t have an official title for it yet… but we will soon! Let me tell you about all the things I need to consider for this project.
Continue reading Website Monitoring Project
