IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » corbanb's snipts The latest snipts from corbanb.

showing 1-20 of 46 snipts
  • Test for AIR Capabilities
    if(Capabilities.playerType == "Desktop") //test for AIR
    

    copy | embed

    0 comments - tagged in  posted by corbanb on May 13, 2010 at 12:15 p.m. EDT
  • AS3 Unicode Embeding
    Uppercase : U+0020,U+0041-U+005A
    Lowercase : U+0020,U+0061-U+007A
    Numerals : U+0030-U+0039,U+002E
    Punctuation : U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E
    Basic Latin : U+0020-U+002F, U+0030-U+0039, U+003A-U+0040, U+0041-U+005A, U+005B-U+0060, U+0061-U+007A, U+007B-U+007E
    
    //via http://blog.open-design.be/2008/06/12/set-unicode-range-in-embedded-font-using-flex-sdk-as3/
    

    copy | embed

    0 comments - tagged in  posted by corbanb on May 08, 2010 at 10:54 p.m. EDT
  • Trace DisplayObject Children
    traceDisplayList(allCon, "=>");
     
    function traceDisplayList(container:DisplayObjectContainer, indentString:String = ""):void {
        var child:DisplayObject;
       
        for (var i:uint=0; i <container.numChildren; i++) {
            child = container.getChildAt(i);
            trace(indentString, child.parent.name + " " + indentString + " " + child.name);
           
            if (container.getChildAt(i) is DisplayObjectContainer) {
                traceDisplayList(DisplayObjectContainer(child), indentString + "")
            }
        }
    }
     
     
    // => allCon => container00
    // => container00 => clipA
    // => container00 => clipB
    // => container00 => clipC
    // => ClipC => ClipC1
    // => ClipC => ClipC2
    // ...
    

    copy | embed

    0 comments - tagged in  posted by corbanb on May 03, 2010 at 1:02 p.m. EDT
  • AS3 Interface Class
    package
    {
    	public interface IMyInterface
    	{
    		
    	}
    }
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 30, 2010 at 9:08 a.m. EDT
  • AS3 Class File
    package
    {
    	import flash.display.MovieClip;
    
    	public class MyClass extends MovieClip
    	{
    		public function MyClass()
    		{
    		}
    	}
    }
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 30, 2010 at 8:59 a.m. EDT
  • Simple HTTP Server Anywhere
    //Run a simple webserver in any dir
    
    mkdir /miniserver
    cd /miniserver
    python -m SimpleHTTPServer
    
    //http://localhost:8000/
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 27, 2010 at 4:10 p.m. EDT
  • Format Currency
    function formatCurrency(n:Number):String{
    	var neg:Boolean = (n < 0);
    	n = Math.abs(n);
    	var dollars:Number = Math.floor(n);
    	var cents:Number = Math.round(100 * (n - dollars));
    	if (cents == 100){
    		cents = 0;
    		dollars++;
    	}
    	var dollarsStr:String = String(dollars);
    	var centsStr:String;
    	var dollarsStr2:String = "";
    	for (i = 0; i < length(dollarsStr); i++){
    		if (i > 0 and i % 3 == 0){
    			dollarsStr2 = "," + dollarsStr2;
    		}
    		dollarsStr2 = dollarsStr.substr(-i -1, 1) + dollarsStr2;
    	}	
    	if (cents == 0){
    		centsStr = "00";
    	}
    	else if (cents < 10){
    		centsStr = "0" + cents;
    	}
    	else{
    		centsStr = String(cents);
    	}
    	var output:String;
    	if (neg){output = "-$";}
    	else{output = "$";}
    	output += dollarsStr2 + "." + centsStr;
    	return output;
    }
    
    
    trace(formatCurrency(.2434)); //$0.24
    trace(formatCurrency(.096)); //$0.10
    trace(formatCurrency(1.5)); //$1.50
    trace(formatCurrency(10)); //$10.00
    trace(formatCurrency(543.06)); //$543.06
    trace(formatCurrency(8484.3)); //$8,484.30
    trace(formatCurrency(4205843323)); // $4,205,843,323.00
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 4:14 p.m. EDT
  • Array Last Index Of
    function wordCount(string:String):Number {
        var tmp:Array = string.split(" ");
        for (var i = tmp.length; i>0; i--) {
            if (tmp[i] == "") {
                tmp.splice(i,1);
            }
        }
        return tmp.length;
    }
    trace(wordCount("Here is a great sentence for you to count!"));
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 4:10 p.m. EDT
  • Create Ordinal Numbers
    function ordinalise(number:Number):String {
     var tmp:String = String(number);
     if (tmp.substr(-2, 2) != "13" && tmp.substr(-2, 2) != "12" && tmp.substr(-2, 2) != "11") {
      if (tmp.substr(-1, 1) == "1") {
       var end:String = "st";
      } else if (tmp.substr(-1, 1) == "2") {
       var end:String = "nd";
      } else if (tmp.substr(-1, 1) == "3") {
       var end:String = "rd";
      }
     }
     if (!end) {
      var end:String = "th";
     }
     return tmp+end;
    }
    trace(ordinalise(21));// Outputs 21st
    trace(ordinalise(102));// Outputs 102nd
    trace(ordinalise(33));// Outputs 33rd
    trace(ordinalise(13));// Outputs 13th
    trace(ordinalise(11));// Outputs 102th
    trace(ordinalise(112));// Outputs 112th
    trace(ordinalise(1));// Outputs 1st
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 4:08 p.m. EDT
  • Email RegExp
    var pattern:RegExp = (\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6});
    
    // PHP return preg_match('/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/', $value);
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:58 p.m. EDT
  • Is GIF, JPG, PNG
    var pattern:RegExp = ([^\s]+(?=\.(jpg|gif|png))\.\2);
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:56 p.m. EDT
  • Google Analytics
    import com.google.analytics.API;
    import com.google.analytics.AnalyticsTracker;
    import com.google.analytics.GATracker;
    //import com.google.analytics.debug.VisualDebugMode;
    
    import flash.events.Event;
    
    trace( API.version );
    
    //setup1
    /*
    GATracker.autobuild = false;
    var tracker:AnalyticsTracker = new GATracker( this, "UA-111-222" );
    tracker.mode = "AS3";
    tracker.visualDebug = true;
    tracker.debug.verbose = true;
    GATracker(tracker).build();
    */
    
    //setup2
    var tracker:AnalyticsTracker = new GATracker( this, "UA-6441425-4", "AS3", false );
    //tracker.debug.mode    = VisualDebugMode.advanced;
    //tracker.debug.traceOutput = true;
    //tracker.debug.GIFRequests = true;
    
    tracker.trackPageview( "/hello/world" );
    
    
    var onButtonClick:Function = function( event:Event ):void
    {
    	tracker.trackEvent( "Button", "click", "hello world", 123 );
    }
    
    mybutton.addEventListener( MouseEvent.CLICK, onButtonClick );
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:54 p.m. EDT
  • Array Last Index Of
    function arrLastIndexOf(arr:Array, object:Object):Number {
     for(var i:Number = arr.length - 1; i >= 0; i--) {
      if(arr[i] == object) {
       return i;
      }
     }
     return null;
    }
    
    
    var arr:Array = new Array("a", "b", "c", "a", "b", "c");
    trace(arrLastIndexOf(arr, "a")); //outputs 3
    trace(arrLastIndexOf(arr, "c")); //outputs 5
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:47 p.m. EDT
  • Find and Replace Function
    function strReplace(str:String, search:String, replace:String):String {
     return str.split(search).join(replace);
    }
    
    
    var str:String = "Hello World!";
    str = strReplace(str, "Hello", "Goodbye"); 
    trace(str); //outputs Goodbye World!
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:44 p.m. EDT
  • RegEx - Find and Replace
    var str:String = "Hello World!";
    
    var myPattern:RegExp = /Hello/g; //regex to remove all hellos
    str = str.replace(myPattern, "Goodbye");
    trace(str); // Goodbye World!
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Apr 01, 2010 at 3:39 p.m. EDT
  • Flash as3 clickTag solution
    public function handleClick(mouseEvent:MouseEvent):void {
    	var interactiveObject:InteractiveObject = mouseEvent.target as InteractiveObject;
    	var li:LoaderInfo = LoaderInfo(interactiveObject.root.loaderInfo);
    	var url:String;
    	for (var i:String in li.parameters) {
    		if (i.toLowerCase() == "clicktag") {
    			url = li.parameters[ i ];
    		}
    	}
    	if (url) {
    		if (ExternalInterface.available) {
    			ExternalInterface.call('window.open',url);
    		}else {
    			navigateToURL(new URLRequest(url),"_blank");
    		}
    	}else {
    		if(ExternalInterface.available) ExternalInterface.call('console.log', "ClickTAG: Couldn't find a valid clicktag variable");
    	}
    }
    myButton.addEventListener(MouseEvent.CLICK,handleClick);
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Feb 08, 2010 at 3:59 p.m. EST
  • Insert SQL via command line
    -- insert sql via command line
    mysql -u dbuser -p -h dbhost.yoursite.com dbname < /path/to/backup.sql
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Dec 07, 2009 at 1:59 p.m. EST
  • Flash quick distance, angle demo
    var a:Point = new Point(stage.stageWidth/2, stage.stageHeight/2);
    var lineDrawing:Shape = new Shape();
    addChild(lineDrawing);
    
    this.addEventListener(Event.ENTER_FRAME, loop);
    
    function loop(e:Event):void{
    	
    	lineDrawing.graphics.clear();
    	
    	var b:Point = new Point(mouseX, mouseY);
    	var distance = Point.distance(a, b);
    	
    	lineDrawing.graphics.lineStyle(1);
    	lineDrawing.graphics.moveTo(a.x,a.y); ///This is where we start drawing
    	lineDrawing.graphics.lineTo(b.x, b.y);
    	
    	
    	var angle:Number = Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI;
    	if(angle < 0) angle += 360;
    	
    }
    

    copy | embed

    1 comment - tagged in  posted by corbanb on Oct 14, 2009 at 4:59 p.m. EDT
  • Tint MovieClip
    function tintColor(mc:MovieClip,colorNum:Number,alphaSet:Number):void {
    	var colorTransform:ColorTransform =mc.transform.colorTransform;
    	colorTransform.color = colorNum;
    	mc.transform.colorTransform = colorTransform;			
    }
    
    tintColor(sprite1, 0xff0000, .6);
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Sep 21, 2009 at 2:34 p.m. EDT
  • random number as3
    var ran:int = Math.round(Math.random() * (high - low)) + low;
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Sep 08, 2009 at 5:33 p.m. EDT
Sign up to create your own snipts, or login.