Showing posts with label snippet. Show all posts
Showing posts with label snippet. Show all posts

Thursday, November 13, 2008

Code snippets - lets unite!!

As I was browsing for some help for doing a simpel task I came across a site which contains Snippets - http://snipplr.com. Wow! That sounded interesting - the snippet I first clicked on was: "Opacity Hack. I was a litle disapointed, not with the snippet in question, but the fact that it was nothing but simpel text...

For years in the back of my head I have had the thought that code snippets should unite! :-) My hopes that snipplr.com was such a united snippet spot was spoiled...

But I tried to write my POWs about snippets - which was not 100% allowed by their comment system, so here goes - a (hopefully) working copy of what I tried to write about snippets standardlization:


Hi, In general I like the Idea of snippets, no doubt about that! But I would love to see some kind of standardilzation of them, preferable in a combination of XML, XSD (schema). You could then transform your XML snippet to what ever purpose you would need it in - say a HTML context. You can validate the input to the snippet using XSD. And some clever programmer might create add-ins for say MS Visual Studio 2008 or other commenly used development tools.
Here is my first thoughts about how it could be put together - based on this snippet for opacity:
<?xml version="1.0" encoding="utf-8"?>
<snippets>
<snippet>
<name>Opacity hack</name>
<version>1.0</version>
<context>CSS</context>
<template>
<outputRaw><![CDATA[selector { filter: alpha(opacity=60); /* MSIE/PC */ -moz-opacity: 0.6; /* Mozilla 1.6 and older */ opacity: 0.6;}]]></outputRaw>
<output>
<input id="alpha" type="string" default=".selector" /> {
filter: alpha(opacity=<input id="opacity" type="int" default="60"/>); /* MSIE/PC */
-moz-opacity: <eval id="moz-opacity"><![CDATA[opacity/100]]></eval>; /* Mozilla 1.6 and older */
opacity: <eval id="moz-opacity"><![CDATA[moz-opacity]]></eval>;
}
</output>
</template>
</snippet>
</snippets>

Friday, November 7, 2008

Snippet: External javascript Eval window

Below a code which (especially) in MSIE will be helpfull when debugging a webpage in frontend. The script opens a small window containing a textarea where you may enter your javascript code. When you Evaluete the code it will be in the context of the current window, so you can examine or edit the DOM tree of the document which is in the window where you clicked the Snippet.

You should create your snippet by

  1. Create a bookmark (any page)
  2. Place the bookmark in the "links" area, so that it will be available in your toolbar
  3. Edit the bookmark (right click) and paste the code below into the URL
  4. Rename it (to say "EVAL")

Here is the code: