July 24th, 2008
Yesterday I was greatly distraught when my MacBook Pro’s superdrive would not accept blank DVD-Rs. When I inserted a blank DVD-R it spun around for a bit, sped up, slowed down, stopped, then spit it back out at me with no error message. It read DVDs, burned CDs, and read CDs fine; but I could not get it to accept a blank DVD-R! I searched around and found information about the MacBook superdrive update which killed alot of people’s optical drives. I couldn’t remember if i installed the update or not, so I was fairly worried because I did not want to drop $400 to fix something which an Apple update broke.
I tried a bunch of tricks to try to get my beloved superdrive to work, but to no avail. Finally while searching around on google someone suggested to get a CD cleaner. I went to Staples and picked one up for $10, put it into my optical drive, and bam it burns DVD-Rs again! I’m guessing the firmware update made the optical drive more sensitive to dust. If your having trouble with your MacBook’s optical drive I suggest grabbing one of these CD drive cleaners and trying your luck before resorting to bringing your computer back to the Apple store.
Posted in General | No Comments »
April 14th, 2008
Although TextMate comes with a built in CSS validation command it would sometimes fail for me depending on where I was working from (some locations have proxy software on the main router). I rewrote the command in the style of the PHP-HTML validator I posted earlier. You can add more validation options using -F. I’ve only used this script on CSS only files, it might not work on inline CSS in HTML documents.
#!/usr/bin/env ruby -wKU
scope = STDIN.read
scope.gsub!(/< \/?style.*?>/, ”)
open(‘|curl -sF file=@-\;type=text/css -F lang=en http://jigsaw.w3.org/css-validator/validator’, ‘r+’) do |io|
io < < scope
io.close_write
while io.gets
$_.gsub!(/<\/title>/, ‘\&<base href="http://jigsaw.w3.org/css-validator/">’)
print $_
end
end
Posted in General | No Comments »
March 27th, 2008
It is impossible to validate local PHP files via the built in W3C validation that the TextMate HTML bundle provides because it does not parse the PHP code in the PHP document. I’ve modified the default validation script to retrieve the file using OS X’s built in apache server (the script assumes you have your files in the ~/Sites directory) so it will work for not only PHP, but any apache-interpreted language. I’ve added the ss option to the W3C validator, you can add/remove any validation options to the curl command as you see fit.
#!/usr/bin/env ruby -wKU
STDOUT.sync = true
page = `echo $TM_FILEPATH | sed “s|.*/$USER/Sites/|http://localhost/~$USER/|” | xargs curl -s`
open(‘|curl -sF uploaded_file=@-\;type=text/html -F ss=1 http://validator.w3.org/check’, ‘r+’) do |io|
io < < page; io.close_write
while io.gets
$_.gsub!(/<\/title>/, ‘\&<base href="http://validator.w3.org/">’)
puts $_
end
end
Hope everyone had a blessed and happy easter!
Posted in General | No Comments »
July 28th, 2007
I’ve seen some pretty horrible code in my days of coding, but nothing beats this:
_global.
checkEmail =
function(e) {
function checkChars
(s, i, l
) {
while (i < l &&
“_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789″.
indexOf(s.
charAt(i
)) != -
1)
{
i = ++i;
} // end while
return (i
);
}
function checkFirstLevelDomainChars(s, i, l)
{
while (i < l && “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”.indexOf(s.charAt(j)) != -1)
{
i = ++i;
} // end while
return (i == l);
} // End of the function
var _loc1;
var j;
var _loc2 = e.length;
var _loc4 = false;
_loc1 = checkChars(e, 0, _loc2);
if (checkChars(e, 0, _loc2) == 0)
{
return (-1);
} // end if
j = _loc1;
while (_loc1 < _loc2 && e.charAt(_loc1) == “.”)
{
++_loc1;
if ((j = checkChars(e, _loc1, _loc2)) == _loc1)
{
return (-2);
} // end if
_loc1 = j;
} // end while
if (e.charAt(_loc1) != “@”)
{
return (-3);
} // end if
do
{
_loc1 = j + 1;
j = checkChars(e, _loc1, _loc2);
if (j == _loc1)
{
return (-4);
}
else if (j == e.length)
{
j = j - _loc1;
if (_loc4 && j >= 2 && checkFirstLevelDomainChars(e, _loc1, _loc2))
{
return (1);
}
else
{
return (-5);
} // end else if
} // end else if
_loc4 = e.charAt(j) == “.”;
} while (_loc1 < _loc2 && _loc4)
return (-6);
};
I’m really not sure what that programmer what smoking when he created that mess; and I really don’t want to know. It felt really good removing 65 lines of code and replacing it with this though:
_global.checkEmail = function(email) { return email.length != 0 && email.indexOf(“@”) != -1 && email.indexOf(“.”) != -1; }
Posted in Software | 3 Comments »
June 6th, 2007
In most of my flash projects I have a prototype file I include into the project. It contains additions to core objects such as Object, MovieClip, etc. Well, today I found out that some Macromedia components (ComboBox was the one I was having trouble with) don’t like additional methods to be defined on certain classes (Object was the one I found that ComboBox was having issues with); they fail to continue to work with additional methods defined.
However, there is a workaround: ASSetPropFlags. Simply hide all additional methods with this line of code:
ASSetPropFlags(Object.prototype, null, 1);
I can’t wait until AS3 can be used all the time.
Posted in Flash | 1 Comment »
May 29th, 2007
I’ve always wanted to attach a movieclip to the stage with a class other than MovieClip without having to use swfmill or the ide to create a movieclip with linkageID + custom class. Well that day is finally here! I found a nice snippet of code on the net and modified it a bit to act more like attachMovie (ability to specify an initOb). The result? createClassMovieClip:s
/*
Description: A function used for creating empty movie clips with subclass association.
Parameters:
c:Function - The class to associate with the the empty movie clip.
name:String - The instance name for the empty movie clip.
depth:Number - The depth for the empty movie clip.
initOb:Object - Optional, object to copy properties from
Returns:
MovieClip - A reference to the newly created movie clip.
*/
MovieClip.prototype.createClassMovieClip = function(c:Function, name:String, depth:Number, initOb:Object) : MovieClip {
var mc:MovieClip = this.createEmptyMovieClip(name, depth);
mc.__proto__ = c.prototype;
mc.constructor = c;
if(initOb) {
for(var prop in initOb) {
mc[prop] = initOb[prop];
}
}
c.call(mc);
return mc;
}
Use it just like attachMovie except you specify a class for the first parameter, eg:
createClassMovieClip(CustomClass, “new_clip”, getNextHighestDepth(), {_x:10, _y:10, something:function(){this.something = 10;}})
Pretty slick!
Snipplr
Snipplr is a neat site I came across a couple months ago but forgot to post about. It a nicely designed web-2.0-ish site that allows you to post and view code snippets for various different languages (Cocoa, PHP, HTML, CSS, etc). It even has cloudtags and TextMate integration! I’ve been posting some smaller snippets on that site instead of the source code page, so go and check it out.
In the same vein, Code Beach was recently launched. Code Beach is basically the same idea as Snipplr, except it is focused solely on Cocoa based code snippets. It’s nice to see more of these code sharing sites cropping up, they save alot of time!
Posted in General | No Comments »