1 2 3 4 5 6 7 8 9 10 11 | $.fn.replaceUrl = function() { var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; this.each(function() { $(this).html( $(this).html().replace(regexp,'<a href="$1">$1</a>‘) ); }); return $(this); } $('p').replaceUrl(); |
Month: January 2011
[JQUERY SNIPPET] Load an XML file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function loadXML(filename) { $.ajax({ type: "GET", url: filename, dataType: "xml", success: parseXml }) } function parseXml(xml) { // Parse your xml here } loadXML('example.xml') |
[AS3 SNIPPET] Box2D utility class
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 | package com.rblab.framework.utils { /** * @author Riccardo Bartoli */ public class Box2DUtil { public static const PIXELS_TO_METERS : Number = 30; public static const FLASH_CONVERSION : Number = 30.04; private static const ONEEIGHTYOVERPI : Number = 180 / Math.PI; public static function metersToPixels(m : Number) : Number { return m / PIXELS_TO_METERS; } public static function pixelsToMeters(p : Number) : Number { return p * (1 / PIXELS_TO_METERS); } public static function toWorld(input : Number) : Number { return input / FLASH_CONVERSION; } public static function toFlash(input : Number) : Number { return input * FLASH_CONVERSION; } public static function degToRad(input : Number) : Number { return input / ONEEIGHTYOVERPI; } public static function radToDeg(input : Number) : Number { return input * ONEEIGHTYOVERPI; } } } |