A PHP function to generate a random password

  function generatePassword ($length = 8)
  {

    // start with a blank password
    $password = "";

    // define possible characters - any character in this string can be
    // picked for use in the password, so if you want to put vowels back in
    // or add special characters such as exclamation marks, this is where
    // you should do it
    $possible = "23467890bcdfghjkmnpqrtvwxyz";

    // we refer to the length of $possible a few times, so let's grab it now
    $maxlength = strlen($possible);
  
    // check for length overflow and truncate if necessary
    if ($length > $maxlength) {
      $length = $maxlength;
    }
    
    // set up a counter for how many characters are in the password so far
    $i = 0; 
    
    // add random characters to $password until $length is reached
    while ($i < $length) { 

      // pick a random character from the possible ones
      $char = substr($possible, mt_rand(0, $maxlength-1), 1);
        
      // have we already used this character in $password?
      if (!strstr($password, $char)) { 
        // no, so it's OK to add it onto the end of whatever we've already got...
        $password .= $char;
        // ... and increase the counter by one
        $i++;
      }

    }

    // done!
    return $password;

  }

Connecting to an MSSQL database from PHP with a Username and Password, Performing a Query, Looping Records and Echoing the Results

define('MY_DATABASE','');
define('MY_USERNAME','');
define('MY_PASSWORD','');
define('SERVER_NAME','');
define('MY_TIME_ZONE','Europe/Dublin');


date_default_timezone_set(MY_TIME_ZONE);
$connectionOptions = array(
"Database"=>MY_DATABASE,
"UID"=>MY_USERNAME,
"PWD"=>MY_PASSWORD
); $conn = sqlsrv_connect( SERVER_NAME, $connectionOptions); if( $conn === false ) die( print_r(sqlsrv_errors()) ); $tsql = "SELECT * FROM [dbname].[dbo].[table]"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false) { echo "Error in query preparation/execution.\n"; die( print_r( sqlsrv_errors(), true)); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) { $Name = $row['name']; $Address = $row['address']; echo $Name . " - " . $Address . "<br>"; } sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn);

Getting an array from a MySQL query PHP

function qet_sql_as_array($conn,$tsql){

    $rows = array();

	$stmt = sqlsrv_query( $conn, $tsql);
	if( $stmt === false)
	{
		die( print_r( sqlsrv_errors(), true));
	}
	while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
	{
		$rows[] = $row;
	}

	return $rows;
    
}

This means you can use it like this:

function ItemCode_array($conn,$counter) {
$tsql = "SELECT ItemCode FROM InventoryItem"; return qet_sql_as_array($conn,$tsql); }

SEO friendly urls in PHP

/** 
  * Return URL-Friendly string slug
  * @param string $string 
  * @return string 
  */

function seoUrl($string) {
        //Unwanted:  {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
        $string = strtolower($string);
        //Strip any unwanted characters
        $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
        //Clean multiple dashes or whitespaces
        $string = preg_replace("/[\s-]+/", " ", $string);
        //Convert whitespaces and underscore to dash
        $string = preg_replace("/[\s_]/", "-", $string);
        return $string;
}

A red gradient for your CSS

.redgradient {
background: #990000; /* Old browsers */
background: -moz-linear-gradient(top,  #990000 0%, #9b3434 50%, #990000 51%, #990000 71%, #870000 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#990000), color-stop(50%,#9b3434), color-stop(51%,#990000), color-stop(71%,#990000), color-stop(100%,#870000)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #990000 0%,#9b3434 50%,#990000 51%,#990000 71%,#870000 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #990000 0%,#9b3434 50%,#990000 51%,#990000 71%,#870000 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #990000 0%,#9b3434 50%,#990000 51%,#990000 71%,#870000 100%); /* IE10+ */
background: linear-gradient(to bottom,  #990000 0%,#9b3434 50%,#990000 51%,#990000 71%,#870000 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#990000', endColorstr='#870000',GradientType=0 ); /* IE6-9 */
text-shadow: 0px 0px 1px #000,0px 0px 3px #000;
}

angrydinosaur:

Made a mug today. Thinking of making a lot more. Would any of you guys be interested in buying one?

(Source: angrydinosaur)

angrydinosaur:

Chuckle Brothers easter egg found in Black Mesa: Source. Thanx @pilchardfish for the screenshot. To me, to you…

(Source: angrydinosaur)

‘Conein’ Mediterranean Veg Flavour - Mini Review

Intro

I found these random snacks in a local shop in the fridge. Frozen, and needing a microwave I was up to the challenge. They looked pizza related, and I’m fucking good at pizza. Lets get started.

Challenge Accepted

The Idea

These things look like Cornettos. Sugarless, chocolateless hot Walls Cornettos with too much cheese in them. My initial impressions were right. These couple of bad boys are super bad for me, but for science I’m going to test them on myself and let you know how it went.

Preparation

These beasts need microwaving and for 3 minutes each. The instructions tell me I have to stand them up on their end inside the boxes and stand them on the edge of the spinny bit. Initially I had problems; my microwave was not big enough to accomodate the height of these coney swine so it kept falling over. A quick squash down of the box and we were away!

[3 minutes pass: DING!]

OW these are hot. If there was a warning on the package I failed to read it. You are supposed to take the box off now. I do that.

Cones

This is the fun part. Look at the pictures, you can see the pizzaness inside the cones. The cheese is melty (and super hot) and the cone has a little thing you remove to make it into a Cornetto. This is a great way to have portable food and I eat one.

Burnt

Though the cone warned me (as you can see in the image) it might be hot I fail to heed the warning. Molten cheese dripped on my hand as I was chowing down and i temporarily spaz out, flicking hyperboiling cheese all over my macbook. Great job bro. I clean it up. I am embarrassed.

Taste

They are fatty and cheesy with no real shape inside. There are no ‘bits’ of vegetable as I had imagined, but this snack worked out ok. The pastry and the cheesy slop inside work well together.

Final Word

I would buy these again. Their simple preparation in conjunction with their edible and portable nature make them a great geek snack.

Till next time. Happy eating.

- GC

Addendum

Fever gone but itchy. Hungry and eat doggy food. Itchy Itchy Scott came. Ugly face so killed him. Tasty.

Sep 2012

angrydinosaur:

martinekenblog:

Pixel Heart Heat Changing Mug

GOOD MORNING ♥

Want.

(via angrydinosaur)

©Gabriel Crowe, All rights reserved Buy Custom Mugs