Helps you easily turn any javascript code into a bookmarklet and post on your blog:
http://tools.w3clubs.com/bookmaker/
Archive for the 'tools' Category
Bookmarklet maker tool
Saturday, May 10th, 2008YSlow performance extension for Firebug
Wednesday, July 25th, 2007Steve Souders, performance architect at Yahoo, announced today the public release of YSlow.
What's YSlow?
It's an extension to Firebug (yes, correct, Firebug, not Firefox) that helps with performance optimization efforts. It scores your page on the scale A to F, based on compliance with Yahoo's performance rules. It's a tool that has been used internally at Yahoo and is now released to the world.
The score
Here's how YSlow scores Yahoo's homepage, gives it an A with 93 points out of 100

You can see on the screenshot how YSlow is just another panel within Firebug, and when you select the panel it gives you a few features. The main one is Performance (shown on the screenshot).
You get a list of 13 things YSlow has evaluated (they are based on the performance rule) and if you don't get an A, there is an arrow that gives you more explanations why. Every one of the 13 items on the list is linked to online documentation of the rule so you can figure out right then what could be improved.
Other features
Besides Performance, there's also the Stats tab which gives you comparison of how your page size for visitors coming with an empty cache vs the ones that have previously visited the page.

The other tab is Components which lists every component on the page along with some information, relevant to performance, such as if the component as gzipped, what was the ETag if any, component size and expiration date.

In the tools section you'll find a nice surprise - integration with the JSLint tool, the unforgiving JavaScript verifier by Douglas Crockford.
The score (revisited)
OK, I'm sure you'll find the tool invaluable, but you may frown upon the score. Well, the scoring system is made so that it suits Yahoo's purposes, but you can modify it so that it fits your specific needs. In order to customize the points system you can go about:config in Firebug and search for yslow. There you can specify points for the score. In addition to that you can find the file called yslowcontext.js in your Firefox extensions folder (should be somewhere in Documents and Settings/Application Data/Mozilla/extensions/steve@yahoo/, path abbreviated), if you can't find it, just search for it. In this file, there is an array that defines the weight of each of the 13 rules in the overall score, so you can tweak that as well. To find the array, search for lintweights
Have fun!
And happy performance tunning!
Links
csssprites.com update
Sunday, July 22nd, 2007Added:
- generation of a GIF sprite in addition to the PNG
- small client-side only check if at least two files are updated
- link to a Yahoo search for "css sprites"
- note begging people not to upload huge files
Only the first thing is a feature, the other three are to raise awareness on what the CSS sprites technique is about. Hopefully it will help people stop uploading 20-30 megs of images in order to create a sprite.
PHP/Javascript dev tools for TextPad
Monday, July 16th, 2007Here are some convenient tools I've added to my TextPad editor, hope you'll like 'em.
TextPad tools
Stuff can easily be added to TextPad's Tools menu, like I did, shown on the screenshot.

In order to do so, you go Configure -> Preferences. Then select Tools on the tree to the left, then Add. You can add a DOS command, an application or a help file (.hlp or .chm)
The first three tools on the picture above come out-of-the-box, the other 4 I've added myself. Let me show you what I did.
Tool #1 - PHP lint (a.k.a. syntax check)
So I'm editing a PHP file and I want to syntax check it from the editor. Good. PHP on the command line comes with the -l option (this is lowercase L) which does just that. For example if you run this from your command prompt, it will check the file test.php for syntax errors:
C:\php> php -l test.php
So for tool #1 I just did - Configure-Preferences-Tools-Add-DOS command, then typed:
php –l $File
In Textpad apparently $File refers to the current file being edited. So now I can edit a file, press CTRL+4 and syntax check the file. Neat.
Tool #2 - PHP help
This is exactly the same idea as the previous tool. I use PHP command line option --rf which gives you help information. For example try getting help with the str_replace() function:
C:php>php --rf str_replace
The result is
Function [ <internal> public function str_replace ] {
- Parameters [4] {
Parameter #0 [ <required> $search ]
Parameter #1 [ <required> $replace ]
Parameter #2 [ <required> $subject ]
Parameter #3 [ <optional> &$replace_count ]
}
}
Adding this functionality to textpad is very similar to tool #1, only this time the command is:
php --rf $SelWord
$SelWord is the currently selected word in textpad (just placing the cursor somewhere in the word is enough)
Tool #3 - PHP Manual
Sometimes the help above is not enough and you want to hit the manual on php.net. Here's the next tool. You go:
Configure-Preferences-Tools-Add-Program and you find your firefox.exe, like
C:\Program Files\Mozilla Firefox\firefox.exe
Now, in order to edit a tool you created in TextPad, you need to expand the Tools node of the Preferences tree and click the tool you need, as shown on the screenshot:
In this screen, you need to type this in the Parameters field:
http://php.net/$SelWord
Tool #4 - JS Lint
JSLint is a tool for checking JavaScript code, it also can be run on the command line in Windows, using cscript. So if your jslint.js is in C:\, you can have tool #4 another DOS command:
cscript C:jslint.js <$File
Hope you like it
Or maybe add these simple tools to your text editor of choice.
Last thing
One little thing I didn't mention - it's a bit of a challenge to figure out how to rename a tool once created. Basically on the list of tools (next to the Add button), just click, right click, double-click or simultaneously click left and right mouse buttons. One of these will work eventually
Two bookmarklets for debugging in IE
Tuesday, February 20th, 2007Here are two bookmarklets that could make your life easier when trying to figure out why in IE a page behave as wrong as it behaves. For Firefox we have Firebug, so none of this is necessary. For IE we have also Firebug lite (see my post), but you need some setup before you can use it. With this thing here you can mess up any page you see on the web, not only yours
Bookmarklet 1 - Eval() textarea
I saw this bookmarklet here and it's beautiful. When you start it, it puts a textarea at the bottom of your page and you can type javascript in it, then eval()-uate it. Perfect! Only … it doesn't work in frames. So I did the same thing but when you have frames (works without frames as well). The way mine works is - you first select some text in a frame, then you click the bookmarklet. A new textarea, ready to execute javascript will be placed in this frame (or iframe) that you selected. Also in this case when you type document.something, it refers to the document in the frame, not the frameset.
If you don't select any text and click the bookmarklet, it will place the textarea in the topmost document, so it will work for frame-free pages as well.
So here's the bookmarklet.
And here's a page where you can test.
Bookmarklet 2 - dump anything
After having my beautiful textarea, I wanted to be able to dump variables, like print_r() or var_dump() but for Javascript. I googled and I found this little script. All I did then is to make it a bookmarklet. How it works? You select the bookmarklet, it gives you a prompt, where you type whatever you want to dump, like document.location for example. Then it shows you an alert with all properties of this thing you typed. (Don't try to dump document though, or something else that recurses, because the script won't handle the recursion and will freeze).
Install it from here:
While this second bookmarklet will most likely work in FF as well, you don't need it, you have firebug!
User stylesheet in IE
Saturday, January 20th, 2007Let's say you want to quickly try out some small stylesheet changes, but you don't want to (or prefer not to, or for some reason temporarily you just can't) modify your application's CSS file(s). In FF it's easy - you have Firebug and you can play with styles until blue in the face. And in case you do get blue in the face and start making so many changes that you get lost, you can create a new clean and tidy CSS file, place it on your hard drive and use Web Developer extension to load it (Menu CSS->Add User Style Sheet). With WebDev Extension you can also Edit CSS right there, although unfortunatelly it's not always working when you have frames.
OK, there are options for Firefox. But how about IE?
In IE you have IE Developer Toolbar, definitelly helpful, but you can only modify element styles, not the stylesheet rules. So? A tiny little bookmarklet to the rescue!
My bookmarklet assumes you have a file called C:\user.css and loads this stylesheet on demand in your page, in every frame, just in case you use frames. Simple, yet useful, I hope. Here's the (readable) code:
javascript: var css_file = prompt('Which CSS file you want to load today?','c:/user.css'); function addcss(w) { var html_doc = w.document.getElementsByTagName('head')[0]; var css = w.document.createElement('link'); css.setAttribute('rel', 'stylesheet'); css.setAttribute('type', 'text/css'); css.setAttribute('href', css_file); html_doc.appendChild(css); } var errors = 0; function checkFrames(w) { if(w.frames && w.frames.length>0){ for(var i=0;i<w.frames.length;i++){ var fr=w.frames[i]; try { addcss(fr); } catch (e) { errors++; } checkFrames(fr); } } } checkFrames(window); addcss(window); if (errors > 0) { alert('Could not access ' + errors + ' frame(s)'); }
To install and play around
Right-click this link and add it to your favourites:
Have in mind that this is IE-only (tested IE7). I don't think FF will allow you to access files on your local drive like this. But for FF you have the tools to do this anyway.
Another option to load local stylesheets in IE is to use the user CSS capability built in the browser, you can find it under Tools/Internet Options/Accessibility, but this will load your user CSS first (as opposed to last as the case is with my bookmarklet), so the "real" style definitions will overwrite yours, unless you always use !important and the "real" styles don't.
Thanks!
Have fun with the custom CSS and let me know how you find it.
Firebug console for IE
Wednesday, December 6th, 2006Update: A better version of what I was trying to do is here. It works around the cross-domain permission problems in IE by not loading a page in the frame, but putting there the actual content.
Firebug - no words to describe how cool it is, really. After the recent new release (1.0. beta) the number of features is overwhelming. I for one can't live anymore without it, seriously.
One of the things I noticed on the website is the ability to use the Firebug console in other browsers than Firefox. I don't know if this existed before version 1.0 but if it did, it was the best kept secret. I am so addicted to the console in Firefox, I use it all the time to tweak a few things here and there when I'm working on a page. Recently I was looking for something similar for IE, but couldn't find it. Lo and behold, it was right under my nose.
So, here's the page that describes how to use Firebug in IE (and others). Basically you unzip the Firebug Lite files somewhere on your server and then you include firebug.js in your pages. But why stop there? And isn't it possible to avoid including this script on every page (and forgetting to remove once you're done, or removing it prematurelly since a page, just like a painting, is never really finished). Bookmarklets to the rescue!
I wanted to host the Firebug files on my hard-drive and then use a javascript dynamic include to load firebug.js via a bookmarklet. This way I would be able to load the firebug console every time I want it, on any page. Unfortunatelly IE's security policy won't allow it. Then?
Solution
The solution I came up with is:
- you copy the Firebug Lite files somewhere on your server
- you call a bookmarklet that will load firebug.js
- you hit F12 and you have a console!
This procedure has to be repeated for every domain you're working on, because of the security policy that won't allow cross-domain frame scripting. You can have one copy for your http://localhost and one for every domain. To ease the creation of bookmarklets that load firebug.js, I came up with a Firebug bookmarklet generator.
In action
- I copied Firebug Lite files (get the .zip) on this server (phpied.com), they are here.
- I (and you can try the same) generate a bookmarklet, using the bookmarklet tool
- Add the generated bookmarklet to the favorites
- Go to any page on phpied.com
- Click the new favorite
- Hit F12 to show/hide the console
Here's how (a readable version of) the generated code looks like:
javascript:(function(){ var firebug_js = document.createElement('script'); firebug_js.setAttribute('type', 'text/javascript'); firebug_js.src = 'http%3A//www.phpied.com/files/firebug/firebug.js'; document.getElementsByTagName('head')[0].appendChild(firebug_js); firebug_js.onreadystatechange = function () { if (firebug_js.readyState == 'complete') { console.open() } } })()
Minor improvement to the console
The Firebug Lite console executes the code you type, but doesn't show it again when you use the up/down arrows, the way it does in Firefox. So I added this feature (copying from myself), you can replace the firebug.js you download with my version.
Not sold yet?
Here's a screenshot of the console in action, I used it to change my photo on the homepage.
Go ahead, please
I strongly encourage everyone to try this out. Firebug is a beautiful thing and using even a bit of it in IE is great.
JSON renderer for Text_Highlight
Friday, October 27th, 2006Text_Highlighter is one of my favourite PEAR packages, seems like I'm addicted to highlighting source code. After adding BB code and simple HTML renderers and an ABAP code syntax definition, today I played with adding a JSON renderer. Useful in case you want to get highlighted source code in your new shiny AJAX app.
Array renderer
After I did the JSON renderer, I said, OK, what if I want to tweak the JSON output just a bit (or the output from any renderer for that matter)? Add more options? Nah, I had a better idea, I scrapped the whole thing and did an Array renderer first. If you have the array output from the renderer, it's trivial to format it as JSON, or XML, or HTML, or anything. I believe even the exisitng Text_Highlighter renderers should be rewritten, to extend an Array renderer. Anyway, back to JSON.
Demo
To see the JSON renderer in action, you can go to my hiliteme.com site and check the JSON tab.
Source
The source code is available here - JSON.phps which extends Array.phps. To test, you need to add the two renderers to your PEAR repository under Text/Highlighter/Renderer
Example
So let's say you need to highlight the PHP code
<?php
echo "Hello Highlighted World!";
?>
You create an instance of Text_Highlighter and Text_Highlighter_Renderer_JSON and call the highlight() method, assuming that the code you need highlighted is in $source
// dependencies require_once 'Text/Highlighter.php'; require_once 'Text/Highlighter/Renderer/JSON.php'; // instance $json_options = array(); $json_options['tabsize'] = 4; $json_options['enumerated'] = true; $renderer =& new Text_Highlighter_Renderer_JSON($json_options); $highlighter =& Text_Highlighter::factory($_POST['language']); $highlighter->setRenderer($renderer); // do the highlighting $json_result = $highlighter->highlight($source);
Now $json_result will look like:
[["inlinetags","<?php"],["code"," \n "],["reserved","echo"],["code"," "],["quotes","""],["string","Hello Highlighted World!"],["quotes","""],["code","; \n"],["inlinetags","?>"]]
As you see the JSON output is an array, one element per highlighted keyword, and in this array there is a sub array - class/keyword. If you want to display this in your page (let's say you got it from an AJAX call), you can do a loop through the array and surround the keywords with span tags of the selected style:
// say your ajax call returned var src // var src = xmlhttp.responseText; var data = eval(src); var res = ''; for (var i in data) { res += '<span class="hl-' + data[i][0] + '">'; res += data[i][1]; res += '</span>'; } var el = document.getElementById('some-div'). el.innerHTML = '<pre>' + res + '</pre>';
Here I used innerHTML, you can also use DOM, but in this case you need a special case for the "\n" so that you can create a br element to address IE's habit of ignoring line feeds in a DOM-generated pre tag.
BTW, if you don't set the enumerated option to true, you'll get objects inside the main array, check hiliteme.com's JSON tab for an idea of how this would look like.
HTML2DOM
Thursday, September 14th, 2006Here's this HTML-2-DOM service - http://www.html2dom.com What it does is pretty simple - you paste some HTML code and the output is JS script code that uses DOM functions to produce the same result. Could be useful when you're working on an AJAX-style app that generates new content using JavaScript.
I build this simple script, inspired by this great book I was reading - "Build Your Own AJAX Web Applications". In the book, the author sometimes starts with writing up what is the HTML code for the result you want to achieve, and then goes ahead with giving the DOM code. Because, you know, DOM code can be quite verbose and sometimes a bit hard to follow. So I thought, why not write up a simple tool to automate this HTML to DOM transition.
The code is not complicated at all, it just takes the HTML, treats it as an XML document, then loops through all the elements of the XML doc and all the attributes for each element. The script is here, hopefully reusable and you can grab it for your own projects if you wish. You can check the source of html2dom.com's index page for an example how to use the html-2-dom class.
Some limitations of the script (that I know of) are result of the fact that I'm treating the HTML as XML document. So you might get some errors if the HTML you paste is not well-formed, with all closed tags and so on. Also you cannot use and other entities, because XML doesn't know about them. What XML knows is only the pre-defined 5. And last, out of the different node types, my script understands only three - element, attribute and comment. I think it's enough for the practical purposes I was aiming at, even the comment type is a bit of a stretch.
So enjoy and as always, any feedback is welcome!
Hello POV-Ray
Thursday, August 31st, 2006End-of-summer draft postings cleanup time! I found this piece of code I wanted to share but never had the time to. The code is in the POV-Ray programming language. "POV-what?" you might think. Well, from the hourse's mouth:
http://www.povray.org:
–
The Persistence of Vision Raytracer is a high-quality, totally free tool for creating stunning three-dimensional graphics. It is available in official versions for Windows, Mac OS/Mac OS X and i86 Linux. The source code is available for those wanting to do their own ports.
Maybe a year or so ago, I played with it, and here's the result.
Funny, isn't it? But don't judge me too harsh, I'm the first to admit my design and color matching abilities as trully very limited.
Anyway, here's the code, I hope you can make sense from the limitted amount of comments.
#include "shapes.inc" #include "colors.inc" #include "textures.inc" #include "shapesq.inc" #include "metals.inc" #include "skies.inc" // drop definition #declare drop = object { Piriform sturm rotate -90*z translate 0.5*y scale <0.5, 2, 1> texture { pigment { P_Cloud1 } finish { F_MetalB } } } // add 5 drops object { drop //pigment { Col_Fluorite_01 } translate -1.5*x } object { drop //pigment { Col_Fluorite_02 } translate 0.8*y translate 15.5*z translate 0.5*x } object { drop translate .5*z translate 1.9*x } object { drop translate 2.5*z translate 1.5*y translate -0.8*x } object { drop translate -1.5*z translate 1.8*y translate 2.5*x } // some clouds O_Cloud1 // this is the sky sky_sphere { pigment { gradient y color_map { [0 color Blue] [1 color Brown] } scale 1.5 translate -11 } } // the ground plane { y, -1.5 pigment { checker pigment{Jade}, pigment{Yellow} } //finish { reflection {1.0} ambient 0 diffuse 0 } finish { reflection { 0.03, 0.81 }} } // camera, light … shoot! camera { location <0, 1, -8> look_at 0 angle 43 } light_source { <200, 150, 100> White //projected_through {O_Cloud2} }
Warning before anyone dives into POV-Ray: It's a time killer! Once you get hooked you might suffer from sudden lapse of sleep.
BTW, in the pov-ray programming manual there are some clever bits that start with "You know you have been raytracing too long when …". I can totally relate to this one:
You know you have been raytracing too long when …
… You want to cheat and look at nature's source code.
— Mark Stock
In case you thought JavaScript could be tough…
phpDoc clip library for TextPad
Wednesday, August 30th, 2006Here's a little something I did to make it a bit easier to write API docs in TextPad, it's a clip library to save some typing when writing comments in the phpDoc format. I submitted it to the TextPad team, so at some point it will probably appear in the downloads section, but meanwhile you can get from here.
Installation
- Download the file phpdoc.tcl
- Copy to your Samples directory in the TextPad folder
- Make sure the Clip Library panel is on (menu option View -> Clip Library)
- Choose phpDoc clip from the dropdown in the Clip Library panel
Some screenshots
Type in some class description, highlight and then select "Class comment"