regex url parser

/^((http[s]?|ftp):/)?/?([^:/s]+)(:([^/]*))?((/w+)*/)([w-.]+[^#?s]+)(?([^#]*))?(#(.*))?$/gi

schema = 2,
domain = 3,
port = 5,
path = 6,
file = 8,
querystring = 9,
hash = 12

source

How To Check .Net Framework Version Installed

// Copy and paste that line of JavaScript code to IE Address bar and press ENTER key

javascript:alert(navigator.userAgent)

source

UI Thread Delegate

public Form1()
        {
            InitializeComponent();

            IntPtr handle = this.Handle;//force creation of handle

            ThreadStart ts = delegate
            {
                //UI operations
                progressBar1.Value = 80;
            };
            //executes synchronously on ts Thread
            Invoke(ts, null);
        }

source

Nim (play against PC, without winning algorithm)

import java.util.Random;
import java.util.Scanner;

public class Nim
{
  public static int total;
  public static Random generator = new Random();
  
  public static void main(String args[])
  {
    // Yada yada yada...
    System.out.println("This is the game of matches. As long as there are mathes left we alternate");
    System.out.println("between taking 1, 2 or 3 matches from the table. The one who takes the last");
    System.out.println("match looses. First, however, we need to know how many matches we will play with.
");
    System.out.print("Please enter a number from 25 to 100: ");
    
    // Get answer
    Scanner input = new Scanner(System.in);
    int num = input.nextInt();
    total = (num<25||num>100) ? 25 : num;
    
    // And boom goes the dynamite...
    System.out.println("
Okay. You may start.
");
    do {
      System.out.print("Your turn: ");
      int response = input.nextInt();
      if (response < 1 || response > 3) System.out.print("Not valid. You may only pick 1, 2 or 3 matches!
");
      else {
        total -= response;
        System.out.println("
Matches left: " + total); }
      myTurn();
    } while (total > 1);
    if (total == 1) System.out.println("Oh oh, you have to take the last match!. You loose, muhahaha.");
    else System.out.println("PC lost...");
  }
  
  public static void myTurn()
  {
    int take;
    
    // Nim algorithm goes here...
    // ...
    
    // No algorithm...
    take = generator.nextInt(3) + 1;
    
    // Subtract taken matches
    total -= take;
    
    // Report back
    System.out.println("PC's turn: " + take + "
");
    System.out.println("Total matches: " + total);
  }
  
}

source

Remove Dashboard Widgets

<?php 
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' );
?>

source

Shorten text class

public class CropText
{
    public CropText()
    {
    }

    public string ShortenText(string input, int MaxLenght, bool DoDots)
    {
        string result = input;
        int InputLength = input.Length;

        string lastChar = result.Substring(result.Length - 1);

        if (MaxLenght < InputLength)
        {
            result = input.Substring(0, MaxLenght);

            if (lastChar == " ")
            {
                result = result.Substring(0, result.Length - 1);
            }

            if (DoDots)
            {
                result += "...";
            }
        }
        return result;
    }
}

source

Scroll To Top

// javascript
$(function() {
  $window = $(window);
  $link = $("#scrollToTop"); // your link to show when user scrolls down
$link.click(function() {
 $("html, body").animate({ scrollTop: 0 }, "slow"); // this is the gist of the script, scroll to top (scrollTop: 0)
});

$window.scroll(function() {
   if ($window.scrollTop() <= 0) {
     $link.fadeOut("fast");
   } else {
     $link.fadeIn("fast");
     }
})

// css
#scrollToTop:link, 
#scrollToTop:visited {
  display: none;
  position: fixed;
  top: 15px;
  right: 15px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: bold;
  text-decoration: none;
  background: #ccc;
  color: #333;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
}

source

Http auth with httperf

httperf --server localhost --server-name foo.com --uri / --add-header 'Authorization: Basic XXXXXX=
' --num-conns 200 --rate 20

source

ucname / Title Case

function ucname($string) {
	$string = ucwords(strtolower($string));

	foreach(array('-', ''') as $delimiter) {
		if (strpos($string, $delimiter) !== false) {
			$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
		}
	}
	
	return $string;
}

source

AS3 Load External Text File

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class Main extends MovieClip
	{
		private var _txtFileToLoad:String = "myTextFile.txt";
		private var _txtLoader:URLLoader;
		private var _loadedTxt:String;
		

		public function Main():void
		{
			loadExternalTxtFile();
		}
		
		private function loadExternalTxtFile():void
		{
			_txtLoader = new URLLoader();
			_txtLoader.addEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.addEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_txtLoader.load(new URLRequest(_txtFileToLoad));
		}
		
		private function onTxtLoader_COMPLETE(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_loadedTxt = String(event.target.data);
			trace(_loadedTxt);
		}
		
		private function onTxtLoader_IO_ERROR(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			trace(event.target.text);
		}

	}
}

source