July 28, 2010 at 4:30 pm · Filed under Programming
The world of Time Tracking and Project Management is a vast one. For small businesses like ours, there are seemingly endless time tracking solutions and a good number of project management answers. I spent nearly two weeks evaluating options in my spare time, so hopefully this data will help save you some time.
Read the rest of this entry »
June 17, 2010 at 12:59 pm · Filed under Programming
Dustin Diaz wrote a nice, efficient version of getElementByClassName(), which searches HTML elements and retrieves all the items with a given CSS class specified.
Of course, if you use a lib like extjs, jQuery, et al, then you have no need of this. But if you’re trying to hack out a greasemonkey script or insert some minimalist code, here it is.
And here it is, for my own archives:
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
} |
Here’s another alternative I found on Glazblog, using xpath to search the document:
document.getElementByClassName = function(needle) {
var xpathResult = document.evaluate('//*[@class = needle]', document, null, 0, null);
var outArray = new Array();
while ((outArray[outArray.length] = xpathResult.iterateNext())) {
}
return outArray;
} |
I don’t really know which is more efficient, though I suspect the xpath search could be taxing in very large documents. I’m positive, based on IE’s fake implementation of key/value pairs in the DOM, that they both suck in IE, even if you specify a specific tag type to search. Obviously, providing a node makes the regular expression search faster, by virtue of having less content to parse.
May 29, 2010 at 12:24 pm · Filed under Programming
Today I was unable to start Apache using a new install of XAMPP. A quick netstat -o in cmd showed something was blocking port 80.
After about an hour of searching, I discovered that port 80 was in use by Skype. No kidding. There is an advanced setting in skype to “Use port 80 and 443 as alternate incoming connections.” If this is checked (which it is by default) then a service is started on port 80 that blocks Apache. Ungh for bad ideas and even worse defaults.
April 27, 2010 at 7:06 am · Filed under Programming
Here is a great little tut on getting started in Bash. I’d recommend it to anyone trying to hack their way into a shell script.
Here is a quick script for sending an email:
#!/bin/bash
# Subject of email
SUBJECT="Test email with attachment from a bash script"
# Where to send it
TO_ADDRESS="your@email.com"
# Where the attachment is
ATTACHMENT_FILE="/tmp/attachment.txt"
# For fun, let's put something into the attachment
echo "This goes into the file." > $ATTACHMENT_FILE
echo "This appends to the file." >> $ATTACHMENT_FILE
# send the message
/bin/mail -s "$SUBJECT" "$TO_ADDRESS" < $ATTACHMENT_FILE |
March 30, 2010 at 8:24 am · Filed under Programming
Great color scheme program for creating themes and complimentary designs:
http://colorschemedesigner.com/
February 17, 2010 at 7:18 am · Filed under Programming
Today I needed to manually remove a service from windows. I found this command line approach, which worked great for me. Be sure to use the service name and not the display name:
You can find the service name by going to Control Panel -> Administrative Tools -> Services, right click the service and choose properties, the service name is shown there.
February 9, 2010 at 1:35 pm · Filed under Programming
http://www.sitepoint.com/blogs/2010/02/09/debug-php-firebug-firephp/
February 4, 2010 at 9:14 am · Filed under Programming
Undeniable proof that the internet is held together by duct tape and chewing gum. No wonder wireless carriers need a 6500% markup on text messaging. Quoted from chess.com:
A few years ago I pulled a late-night session trying to debug a server at PacBell. The code looked fine, but every night the server would reboot and it was my job to figure out why. As I’m sitting there, testing the server at 1AM, in walks the janitor, UNPLUGS THE SERVER to plug in the vacuum, vacuums the room, then plugs the server back in. Case closed, I went home.
January 10, 2010 at 5:59 pm · Filed under Programming
Today I wrote a class to iterate words in a string. One challenge was finding my way backwards in a string. Specifically, given a starting position inside the string, I wanted to find the previous “word” and return it. However, since this needs to work localized (not just a-z), and the definition of a “word” is configurable, it was no simple matter of looking back for the previous space character.
So here is what I came up with; a method that finds the next or previous word given a starting position in the string:
/**
* Abstracted method for finding the next/prev word. This method assumes that
* $pos is greater than zero and less than the length of $text (check before calling)
*
* @param string $text the string of text to find next/prev word in
* @param int $pos the position of first character in current word
* @param string $wordPattern the regex definition of a word without any matching parens
* @param string $reverse looks backward instead of forward (finds last word in string)
* @return mixed false if no more words or array( "the word matched with junk", "the word only")
*/
private static function nextWordMatch($text, $pos, $wordPattern, $reverse = false) {
// we get the substring of text, starting at the current position
if( $reverse ) {
// in this case, we look at everything before $pos; we reverse it so that
// we can run a simple regex on it rather than trying to deal with craziness
// of looking backwards in string
$text = substr($text, 0, $pos-1);
}
else {
// in this case, we look at everything after $pos
$text = substr($text, $pos);
}
// we escape the preg character just in case
// we add in two sets of match parens, one for the word and one for the whole match
// when looking backwards, we need to look from the end rather than the start
$wordPattern = str_replace('@', '\\@', $wordPattern);
$pattern = "(({$wordPattern})".self::NON_WORD_CHARS.")";
if( $reverse ) { $pattern = "@{$pattern}\$@"; }
else { $pattern = "@^{$pattern}@"; }
// perform the match now and figure out what to do with it
preg_match($pattern, $text, $matches);
if( count($matches) < 3 ) { // remember that the first match is the raw text, so we add one
// we didn't find any words, so return false
return false;
}
// strip off the raw text, leaving our two matches
return array_slice($matches, 1);
} |
Here is the default value for $wordPattern and the constant NON_WORD_CHARS used in the example:
private $wordPattern = '\b[\w]+(?:[-\']\w+)*\b';
const NON_WORD_CHARS = '\W*'; |
November 3, 2009 at 12:11 pm · Filed under Programming
A great Photoshop site with free brushes, effects, actions, and tutorials for the graphics enthusiast. Check it out: Photoshop Tutorials
Next entries »