Archive for September, 2007|Monthly archive page

google video converter

kultiras.net google video converter

or just use this extremely small program (44K) to convert GVI to AVI

Source code

Rubik’s CubeImageCube is a program written by Lars Vandenbergh to show images of Rubik’s cube where you define what stickers to show.

I wrote a version of ImageCube that can also be used as a model of the Rubik’s Cube. I decided to give away the code, because that’s how cool I am. If you’re only into cubing and not into programming at all, you should just check out what I did with it at the algorithm database or my Rubik’s cube site.

And now for the source. If you have any comments, feel free to leave them here.

<?
/*
Cube object

Copyright (C) 2007 Michiel van der Blonk - <a href="mailto:blonkm@gmail.com">blonkm@gmail.com</a> - All Rights Reserved
Based on C++ code by Joël van Noort

This software is licensed as per the MIT License below:
MIT License: <a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

/*
 * To generate the imagecube sticker codes, this program first simulates the
 * cube, using a  string that represents the cube state. Every elementarty move
 * (UDLRFB) is then executed as five 4-cycles of stickers. Example: the
 * sticker permutations corresponding with the move U are:
 *
 * U: (53, 51, 45, 47) (50, 52, 48, 46) (2, 38, 29, 11)
 *     (1, 37, 28, 10,) (0, 36, 27, 9)
 */

// just for debugging
class Debug
{
 function out($s)
 {
  echo '<div class="debug">';
  print_r($s);
  echo '</div>';
 }
}

// post, get
class Page
{
 function get($s)
 {
  if (isset($_GET[$s]))
   return $_GET[$s];
  if (isset($_POST[$s]))
   return $_POST[$s];
 }
}

// handy functions
class Util
{
 //swaps two elements in an array
 function  swap(&amp;$var, $a, $b){

  $temp = $var[$a];
  $var[$a] = $var[$b];
  $var[$b] = $temp;
 }
}

// model of a Rubik's cube
class Cube
{
 var $stickers;
 var $mode;

 // constructor
 function Cube()
 {
  // initialize stickers
  $this->stickers = "rrrrrrrrrgggggggggwwwwwwwwwooooooooobbbbbbbbbyyyyyyyyy";
 }

 //this function uses swap function 3 times to make a 4-cycles of stickers:
 function execute_permutation($a, $b, $c, $d){
  Util::swap($this->stickers, $a, $b);
  Util::swap($this->stickers, $a, $c);
  Util::swap($this->stickers, $a, $d);
 }

 // perform a move and update stickers member variable
 // for multiple moves in the string $token the moves are done one by one
 function move($token)
 {
  $moveTransforms = array('u'=>'UEEE', 'd'=>'DE', 'f'=>'FS', 'b'=>'BSSS', 'l'=>'LM', 'r'=>'RMMM', 'x'=>'rLLL', 'y'=>'uDDD', 'z'=>'fBBB');

  // recursive calls to walk through the translated lowercase moves
  if (strlen($token) > 1)
   foreach (str_split($token) as $ch)
    $this->move($ch);

  switch($token)
  {
    case 'U':
    //one of the elementary move functions. Uses the execute_permutation function
    //five times to make five 4-cycles of stickers:
    $this->execute_permutation(53, 51, 45, 47); // top layer
    $this->execute_permutation(50, 52, 48, 46);
    $this->execute_permutation(2, 38, 29, 11);
    $this->execute_permutation(1, 37, 28, 10);
    $this->execute_permutation(0, 36, 27, 9);
    break;
    case 'D':
    $this->execute_permutation(20, 26, 24, 18);
    $this->execute_permutation(23, 25, 21, 19);
    $this->execute_permutation(8, 17, 35, 44);
    $this->execute_permutation(7, 16, 34, 43);
    $this->execute_permutation(6, 15, 33, 42);
    break;
    case 'F':
    $this->execute_permutation(2, 8, 6, 0);
    $this->execute_permutation(5, 7, 3, 1);
    $this->execute_permutation(9, 20, 44, 51);
    $this->execute_permutation(12, 19, 41, 52);
    $this->execute_permutation(15, 18, 38, 53);
    break;
    case 'B':
    $this->execute_permutation(29, 35, 33, 27);
    $this->execute_permutation(32, 34, 30, 28);
    $this->execute_permutation(47, 36, 24, 17);
    $this->execute_permutation(46, 39, 25, 14);
    $this->execute_permutation(45, 42, 26, 11);
    break;
    case 'R':
    $this->execute_permutation(11, 17, 15, 9);
    $this->execute_permutation(14, 16, 12, 10);
    $this->execute_permutation(2, 47, 33, 20);
    $this->execute_permutation(5, 50, 30, 23);
    $this->execute_permutation(8, 53, 27, 26);
    break;
    case 'L':
    $this->execute_permutation(38, 44, 42, 36);
    $this->execute_permutation(41, 43, 39, 37);
    $this->execute_permutation(0, 18, 35, 45);
    $this->execute_permutation(3, 21, 32, 48);
    $this->execute_permutation(6, 24, 29, 51);
    break;
   case 'M':
    $this->execute_permutation(4, 22, 31, 49 );
    $this->execute_permutation(1, 19, 34, 46 );
    $this->execute_permutation(7, 25, 28, 52 );
    break;
   case 'E':
    $this->execute_permutation(4, 13, 31, 40);
    $this->execute_permutation(5, 14, 32, 41);
    $this->execute_permutation(3, 12, 30, 39);
    break;
   case 'S':
    $this->execute_permutation(49, 13, 22, 40);
    $this->execute_permutation(50, 16, 21, 37);
    $this->execute_permutation(48, 10, 23, 43);
    break;
   case '':
    break;
   default:
    // u,d,f,b,l,r,x,y,z
    $this->move($moveTransforms[$token]);
  }
 }

 // clean from certain tokens
 // note: only cleans up space, minus, quote
  function clean($input)
  {
  if ($input=='')
   return $input;

  $tokens = " ()-\\'";
  $input_clean = '';
  $prevCh = '';
  // delete magic quotes
  $input = str_replace("\\\\", '', $input);
  foreach (str_split($input) as $ch)
  {
   if (!strpos($tokens, $ch))
       $input_clean .= $ch;

   // only add prime when right after a move token, e.g. R'
   // so skip R2' (becomes R2)
   if ($ch=='\\'' &amp;&amp; $prevCh!='2')
    $input_clean .= $ch;
   $prevCh = $ch;
  }
  return $input_clean;
 }

 // normalize algorithm
 // e.g. R2L'FD' becomes R2L3F1D3
 function normalize($input_clean){
  $temp = str_replace('\\'', '3', $input_clean);
  foreach (str_split($temp) as $ch)
  {
   // when both ch and prev are moves, insert a 1 between them
   // RL becomes R1L
   if (preg_match("/\\D/", $prevCh) &amp;&amp; preg_match("/\\D/", $ch))
    $alg_normal .= '1';
   $alg_normal .= $ch;
   $prevCh = $ch;
  }
  if (preg_match("/\\D/", $ch))
   $alg_normal .= '1';
  return $alg_normal;
 }

 // reverse moves
 // used to show an algorithm that solves a cube
 function  inverse($alg_normal){
  // split into separate moves
  $moves = str_split($alg_normal, 2);
  // reverse those
  $moves_inverse = array_reverse($moves);
  // back to string
  $alg_inverse = implode("", $moves_inverse);
  // inverse quantifiers
  $alg_inverse = str_replace('1', '#', $alg_inverse); // temp ch for 3
  $alg_inverse = str_replace('3', '1', $alg_inverse);
  $alg_inverse = str_replace('#', '3', $alg_inverse);

  return $alg_inverse;
 }

 // several predefined sticker modes
 function setMode($mode='')
 {
  if ($mode!='')
   $this->mode = $mode;

  switch (strtoupper($this->mode))
  {
   case "F2L":
    $this->stickers =  "xxxrrrrrrxxxggggggwwwwwwwwwxxxooooooxxxbbbbbbxxxxyxxxx";
    break;
   case "SHORTCUT":
    $this->stickers = "xxxxrrxrrxxxggxggxxwwwwwxwxxxxxoxxoxxxxxbxxbxxxxxyxxxx";
    break;
   case "OLL":
    $this->stickers = "xxxrrrrrrxxxggggggwwwwwwwwwxxxooooooxxxbbbbbbyyyyyyyyy";
    break;
   case "PLL":
    $this->stickers = "rrrrrrrrrgggggggggwwwwwwwwwooooooooobbbbbbbbbyyyyyyyyy";
    break;
  }
 }

 // execute an algorithm
 function  execute($alg, $mode='')
 {
  // prepare with a certain mode if given
  if ($preset!='')
   $this->setMode($mode);

  // walk through all moves in a normalized alg
  for ($i=0; $i < strlen($alg); $i+=2)
  {
   // define operation (move) and quantifier
   $op = $alg[$i];
   $q = $alg[$i+1];
   // move a face n times
   foreach (range(1, $q) as $value)
    $this->move($op);
  }
  return $this->stickers;
 }

 // applet sticker for RubikPlayer are
 // the same as the stickers member variable
 function toAppletStickers()
 {
  return $this->stickers;
 }

 // return only visible faces for imagecube
 // i.e. U, F, R
 function toImageCubeStickers()
 {
  // split into 9 faces
  $faces = str_split($this->stickers, 9);

  // create string for up, right, front
  $upFace = $faces[5];
  $frontFace = $faces[0];
  $rightFace = $faces[1];
  $imageStickers = $upFace . $frontFace . $rightFace;

  return $imageStickers ;
 }

 // perform an algorithm given
 // done in the steps
 // 1. clean up
 // 2. normalize (add quantifiers)
 // 3. optionally inverse
 // 4. execute
 function performAlg($input, $inverse = false)
 {
    $input_clean = "";
    $alg_normal = "";
    $alg_inverse = "";

  // clean input leaves only the moves
  $alg = $this->clean($input);

  // process to get normalized alg (e.g. R2F1L3)
  $alg = $this->normalize($alg);

  // process inverse of alg
  if ($inverse)
   $alg = $this->inverse($alg);

  // perform inverse on the stickers
  $this->stickers = $this->execute($alg);
 }
}
?>

convert google video to avi – or any type actually

Bush the next American Idol?

Finally Mr. Bush got some text right.

glumbert – Sunday Bloody Sunday performed by George W. Bush

Busy fighting spam, viruses and spyware

Yeah it’s that time of year again: I have a disease and it’s spreading. I caught a mean spyware, and I was unprotected. I have AVG installed, so I thought I was relatively safe. But using bittorrent to get official Microsoft stuff is not a good idea (or maybe it is if you know where to look, I don’t apparently). Anyway, I caught ‘access.exe’ and it’s not Microsoft Access. It’s a program that spies on my browser. I found out pretty quickly because the windows firewall just blocked all internet access (and isn’t it ironic, don’t you think…).

So here are some tips for you if you haven’t learned about this topic the hard way

  • For anti-virus I used to have Norton, now I have AVG-free. Just as good (better?) and free.
  • For anti-spyware I have Windows Defender. Also free, and not very annoying, although it seems to have a bit of a quarrel with Norton sometimes. Not a big download (4MB).
  • For anti-spam I have Cactus-antispam. This lovely program does not put an annoying message under each email I sent, as most free services do. It’s also small, and it learns very well. Unfortunately it also has a bit of a learning curve itself. But: it does integrate with Outlook Express, actually with almost any client I know, and some I don’t know.

More free software, a lot more…

These people RULE! (literally)

Ok, that sound vague. Let me explain what this is exactly: it’s a Flash application where you can select companies and view their board of directors. That is not too interesting. Then you can select on what other board of directors they are. That becomes interesting. And then… you can select a x-degrees-of-separation from some other company’s board of directors. Sort of a chain of command. And that’s really interesting.

Also check out the who owns what in media companies. This can explain a lot when you’re browsing and you see ads that you wouldn’t expect.

pepsi-coke

How to find free software on the internet

Yes, perfectly legal.

Savannah

Follow

Get every new post delivered to your Inbox.