PHP Filesize Converter

I found a script a while back which could convert a filesize into bytes, kilobytes, megabytes etc.  I had made a few adjustments to it because of limitations.  Enjoy:

function convert($size, $from, $to)
 $unit = null;
 $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'YB');
 $f = array_search($from, $units);
 $t = array_search($to, $units);
 if ($f < $t)
  for ($i = $f; $i < $t; $i++)
   if($size > 1024)
    $size = $size / 1024;
  for ($i = $f; $i > $t; $i--)
   $size = $size * 1024;
 $unit = $units[$i];
 return round($size, 2)." ".$unit;
echo convert(5368709120, 'B', 'GB'); // 5 GB
echo '<p>';
echo convert(3, 'TB', 'MB'); // 3145728 MB

PHP D20 Dice

Here is a simple PHP D20 Dice rolling script that I wrote to simulate the one in Open RPG.  It takes the following string: 1d20*13+14 and outputs something similar to: [5d8] => [3,2,5,4,3] = 17
// PHP 5
class dice {
 // format 1d20*13+14 
 function roll($input)
  $math = array("+", "-", "*", "/");
  // split the string into individual characters
  $characters = str_split($input);
  // loop through array and halt when it finds a character in
  // math array
  foreach($characters as $char)
   if(!in_array($char, $math))
    $die .= $char;
   } else {
  $parts = explode("d", $die);
  $num = $parts[0]; // number of dice to roll
  $sides = $parts[1]; // number of sides on the dice
  // to figure out equation
  // final $char should be one of the math symbols
  $extra = explode($char, $input);
  // roll x number of die
  for($i=1; $i <= $num; $i++)
   // add to array
   $rolls[$i] = rand(1, $sides);
  // creates string of numbers
  foreach($rolls as $roll)
   $numbers .= $roll . ',';
  // removes trailing , from string of numbers to form [ numbers ]
  $numbers = substr($numbers, 0, -1);
  // sum array - get total of all dice rolled
  $total = array_sum($rolls);
  // solves error with calc_string method...
  // if it doesn't contain something like *2 (2d*2) which is 2 characters in length
  // don't bother with attempting to calculate the string otherwise,
  // build the string to be calculated
  if(strlen($extra[1] >= 2))
   // build equation string
   $eq = $total . ' ' . $char . '' . $extra[1];
   // compute final total
   $final = $this->calc_string($eq);
   $final = $total;
  echo '[' . $input . '] => ['.$numbers.'] = ' . $final . '<br>';
 function calc_string( $mathString )
  $cf_DoCalc = create_function("", "return (" . $mathString . ");" );
  return $cf_DoCalc();
 $times = $_POST['times'];
 $dice = new dice();
 for($i=1; $i <= $times; $i++)
<title>Roll Dice</title>
<form method="post" action="<?php echo $PHP_SELF; ?>">
Roll: <input type="text" name="roll"><br>
Number of Times to Roll: <input type="text" name="times"><br>
<input type="submit" value="roll" name="submit">

Install Java JDK7 on Mac OSX Snow Leopard 10.6.8

1. Download the latest JDK 7 from the Oracle web site.  jdk-7u21-macosx-x64.dmg

2. I ran and mounted the JDK 7 dmg file.  A volume appeared on my desktop called JDK 7 Update 21.

3. I extracted the contents of the installer using a program called Pacifist which I downloaded from to a folder I created on the desktop.  You have to first click on Open Package within Pacifist and then load the JDK 7 Update 21 / JDK 7 Update 21.pkg package.  Once you load the package, select all the contents and drag it into a folder on the desktop.

4. At this point, you'll want to navigate to the JavaVirtualMachines directory located at [hd] / System / Lbrary / Java / JavaVirtualMachines.  You'll probably see 1.6.0.jdk package already listed.  Copy this file to the desktop and rename it to 1.7.0.jdk.  Now delete the contents within the 1.7.0.jdk package.  

5. Open  the directory where you extracted the installer contents to on the desktop.  You'll see 2 folders: JDK 7 Update 21 Folder and JDK 7 Update 21 Folder-1.  

6. Navigate to JDK 7 Update 21 Folder / Contents Directory.  There is a file called Info.plist and 2 folders called Home and MacOS.  Drag these into the 1.7.0.jdk package.

7.  Now open the JDK 7 Update 21 Folder-1 / Contents directory and drag everything into the package as well.  You do not need to replace any files or folders that already exist.

8.  Now drag the modified 1.7.0.jdk package into System / Library / Java / JavaVirtualMachines directory and double click to open it.  You should see the java preferences dialog at this point which should now list Java SE 7 as an option.  Drag it to the top and close.

If you are using NetBeans and started a project in 1.6 and continuing it in 1.7, you may need to change the Source/Binary Format located under Sources in the Project Properties.  You should see a drop down that lists JDK 6.  You need to change this to JDK 7.

When you open a Netbeans project or create a new one, you should notice the 1.7 library already loaded.  I ran the following to make sure it worked correctly:
public static void main(String[] args) {
and the following displayed in the console:

Explorer Freezes and Quits

If windows freezes and you lose your desktop, folders and start menu, open the task manager (ctrl+alt+del) and then click on Start Task Manager.  From the task manager, click on File > New Task (Run).  Type in explorer and click ok.

Keys mysteriously change

Every now and then the keys on my keyboard get screwed up.  For example, a P key will input a * and the A key changes to a 0 and it becomes impossible to type.

I've recently figured out that the Num Lock for whatever reason gets turned on.

To disable it, press the FN (Function Key) + the Delete Key / Num LK key.

While it's an easy fix, for some reason I couldn't figure out what was going on.

Auto Disable Synaptic Touch pad When USB Mouse Plugged In

Now, if you are like me and hate the sensitivity of touch pads these days and want to disable it when you have your USB mouse plugged, you can easily do this with a registry edit.

1. Begin by going to run and type in regedit.
2. Under HKEY_LOCAL_MACHINE, navigate to Software\Synaptics\SynTPEnh.
3. If DisableIntPDFeature is not listed, you will need to add it.  Create a New DWORD by clicking on Edit > New and then selecting DWORD(32 bit) Value.  You can also right click and choose it from the list that pops up.
4. Rename it to DisableIntPDFeature and enter 33 in the textbox under Value data.  Make sure Hexadecimal is checked.  Click OK.
5. Open the Control Panel.  Where it says Control Panel in the URL, type in Control Panel\All Control Panel Items.
6. Double Click on Mouse and Click the tab for Device Settings.
7. You should see a check box for "Disable internal pointing device when external USB pointing device is attached".  Check this, click the apply button and close the window.

Instead of Navigating the Registry, you can open up notepad, copy and paste the following into it:


Save the file as AutoDisableMousePad.reg perhaps in the my documents folder or on the desktop.  Double click it.  If User Account Control (UAC) requires you to give it permission to make changes, click YES.

Win7 Delete Windows Media Player Frequently Played Files

On windows 7, when you right click on the Windows Media Player icon in the task bar, you notice a massive list that builds every time you play an audio or video file.  I used to have to go in and manually remove these files by right clicking on each one and then selecting remove from list.  While browsing through the Windows Media Player program, I stumbled into an easier way of doing this:

1. Open Windows Media Player
2. In the organize menu, click options.  Organize should be in the upper left hand corner of Windows Media Player.
3. Click on the Privacy tab.
4. To make life easier, within the history section at the bottom, uncheck everything.  Also, click on the "Clear History" button.  You might also want to clear the caches too.
5. Click Apply and close it.

Problem Solved : - )