Friday, September 30, 2011

Network file sharing in Windows 7 using password protection

I have a  laptop  and a desktop, both of them are Windows 7.
I want to share files in these two computers with password protection during sharing.

1. To choose home network and password protection
start->Control panel->Network and Internet->Network and Sharing center
Under "View your active networks" click and choose "Home network"

Under left panel to choose Advanced sharing settings, under home or work:
all select Turn on.  Under HomeGroup connections,
select Use user accounts and passwords to connect to other computers.

2. Select the file or folder to share

Right click mouse to select properties, select share with everyone

3. View the network file
Under My Computer, click network in left panel, you can select another computer. Click that icon,
enter your  user name and password in that remote computer, you can see the network file to share.

I am able to my file in my laptop to desktop via network file share. It is much fast than using USB
stick to copy twice in two computers.

Sunday, September 25, 2011

Design a editable webpage and keep ten revisions using PHP MySQL

Design a editable webpage and keep ten revisions.
Procedure using PHP/MySQL
1) Create two tables.
First table  web_content store current content of webpage
CREATE TABLE web_content (
  `content_id` mediumint(8) unsigned NOT NULL auto_increment,
  `revision` mediumint(8) unsigned NOT NULL default '0',
  `title` varchar(255) NOT NULL,
  `text` text NOT NULL,
  PRIMARY KEY  (`content_id`)
Another table web_content_rev to store 10 revison
CREATE TABLE web_content_rev (
  `content_id` mediumint(8) unsigned NOT NULL auto_increment,
  `revision` mediumint(8) unsigned NOT NULL default '0',
  `title` varchar(255) NOT NULL,
  `text` text NOT NULL,
  PRIMARY KEY  (`content_id`, `revision`)
2) page_id as a dynamic varable, create save, cancel,  restore revision buttons, load external editor, display page content and the content in the editor at the same time.

  //page_id from web site for example index.php?page_id=1
   else {
    // The "i" after the pattern delimiter indicates a case-insensitive search
       if (preg_match("/index.php/i",$_SERVER['PHP_SELF']))  $content_id=1;

//Jiansen Lu, Sept 23, 2011
     global $db;
    $sql = "SELECT text, revision  FROM web_content WHERE content_id=$content_id";
    $result = mysql_query($sql, $db);

    while ($row = mysql_fetch_assoc($result)) {
        $content = $row['text'];
        $revision = $row['revision'];
    $sql_3 = "SELECT revision  FROM web_content_rev WHERE content_id=$content_id";
    $result_3 = mysql_query($sql_3, $db);
    while ($row = mysql_fetch_assoc($result_3)) {   
        $revision_1[$i] = $row['revision'];
        //if you are admin and the page editable ie edit=1, index.php?edit=1&page_id=1
    if($_GET['edit']==1&&isset($_SESSION['portal_status']) && $_SESSION['portal_status']['admin'] == STATUS_ADMIN){
        if ($_POST['save']=="Save") {
           $sql_1 = "INSERT INTO web_content_rev SELECT * FROM web_content  WHERE content_id=$content_id";
           $result0 = mysql_query($sql_1, $db);
           //delete revisions,investigaor and references older than 10 ago
           $sql_2 = "DELETE FROM  web_content_rev WHERE content_id=$content_id AND revision < ($revision-9)";
//prevent MySQL injection using  mysql_real_escape_string
           $sql0 = "UPDATE web_content set text='".mysql_real_escape_string($_POST['doc_body'])." ', revision=revision+1 WHERE content_id=1";
           $result0 = mysql_query($sql0, $db);
        else if ($_POST['cancel']=="Cancel") {
           header('Location: /index.php');
     if ($_POST['restore']=="Restore Revision") {
            $msg->addError('You must select a revision first.');
            $sql_5 = "SELECT text  FROM web_content_rev WHERE content_id=1 AND revision=".$_POST['rid'];
            $result_5 = mysql_query($sql_5, $db);
            while ($row = mysql_fetch_assoc($result_5)) {
            $content = $row['text'];
    echo ($content);
    if($_GET['edit']==1&&isset($_SESSION['portal_status']) && $_SESSION['portal_status']['cesei'] == STATUS_ADMIN){
<form action="<?php echo $_SERVER['PHP_SELF'].'?edit=1&content_id='.$content_id; ?>" method="post" name="form_1_global">
<input type="submit" class="input-button" value="Save" name="save" class="input-button"/>
<input type="submit" name="cancel" value="Cancel" class="input-button" />
<input type="submit" name="restore" value="Restore Revision" class="input-button" />
<?php foreach($revision_1 as $revision1): ?>
         <tr valign="middle"><input type="radio" name="rid" value="<?php echo $revision1; ?>" id="p_<?php echo $revision1; ?>" /></tr>
         <tr><?php echo $revision1."&nbsp&nbsp&nbsp&nbsp"; ?></tr>
<?php endforeach; ?>
<textarea name="doc_body" id="doc_body" rows="5" class="mce-editor" style="width:100%; height:700px;"><?php echo (htmlspecialchars($content)); ?></textarea>
//local external mce editor


Wednesday, September 21, 2011

Encrypt and decrypt data in PHP

The class to encrypt and decrypt a string or password: (save in file EncrptClass.php)


class Encryption {
    var $skey = "yourSecretKey"; // you can change it

    public  function safe_b64encode($string) {
        $data = base64_encode($string);
        $data = str_replace(array('+','/','='),array('-','_',''),$data);
        return $data;

    public function safe_b64decode($string) {
        $data = str_replace(array('-','_'),array('+','/'),$string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        return base64_decode($data);

    public  function encode($value){
        if(!$value){return false;}
        $text = $value;
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv);
        return trim($this->safe_b64encode($crypttext));

    public function decode($value){
        if(!$value){return false;}
        $crypttext = $this->safe_b64decode($value);
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv);
        return trim($decrypttext);

In myencrypt.php, encrypt the string "mypassword" ad decrypt it.



$password = "mypassword";

$converter = new Encryption;
$encoded = $converter->encode($password);
$decoded = $converter->decode($encoded);   

echo "Encoded password: $encoded <br />";
echo "Decoded password: $decoded";


Sunday, September 18, 2011

Switch blue characters in HP laptop

To go to blue character mode, press ctrl + Shift. To go back to the normal keys, click ctrl + shift twice.

Thursday, September 15, 2011

Resize image using button in actionscript 3

The steps to design a "+" and "-" button to increase an image in actionscript 3.0
Here the button is not real button in AS3, it is a Movie Clip.
1) Click Adobe Flash CS3 Professional:
2) File->New ->ActionScript 3
3)  In layer 1,  import an image, draw a button using rectangular tool and duplicate it.
4) Create a new layer "text", type "+" and "-" in each button
5) Using selection tool (v), convert image and two buttons as "Movie Clip", and set
image instance name m_whale (click property), "+"button as m_plus, "-" button as m_minus
6) Create new layer " action",
press F9 to import following actionscript
m_plus.addEventListener(MouseEvent.CLICK, IncreaseSize);
m_minus.addEventListener(MouseEvent.CLICK, DecreaseSize);
function DecreaseSize(evt:MouseEvent){
    m_whale.scaleX -= 0.1;
    m_whale.scaleY -= 0.1;
function IncreaseSize(evt:MouseEvent){
    m_whale.scaleX += 0.1;
    m_whale.scaleY += 0.1;
4) Control + Test Movie (ctrl+enter) to test movie. Export movie to swf file.
5. The swf  is below

onRelease in As2 should be changed to ddEventListener(MouseEvent.CLICK, myfunc) in AS3, or you will get Flash Warning #1090.
In AS2:
m_plus.onRelease = function () {
//Do Something

In AS3: 
m_plus.addEventListener(MouseEvent.CLICK, IncreaseSize);
function IncreaseSize(evt:MouseEvent){
   //do something

Wednesday, September 14, 2011

Display microphone volume level in actionscript 3

The steps to design a circle, whose size increases as microphone volume increases in actionscript 3.0
1) Click Adobe Flash CS3 Professional:
2) File->New ->ActionScript 3
3)  In “layer 1, press F9 to import following actionscript
var myMic:Microphone = Microphone.getMicrophone();

stage.addEventListener(Event.ENTER_FRAME, stage_EnterFrame);
var zw:Number = stage.stageWidth/2;
var zh:Number = stage.stageHeight/2.;
function stage_EnterFrame(e:Event)
var num:Number = myMic.activityLevel*5;
graphics.drawCircle(zw, zh, num);

4) Control + Test Movie (ctrl+enter) to test movie. Export movie to swf file.
5. The swf  is below: you can not see the circle until you turn on microphone and speak
(Reference: )

Tuesday, September 13, 2011

Access Webcam in actionscript 3.0

The steps to access webcam in actionscript 3.0
1) Click Adobe Flash CS3 Professional:
2) File->New ->ActionScript 3
3)  In “layer 1, press F9 to import following actionscript
var camera = Camera.getCamera();
var video = new Video(camera.width*2,camera.height*2);
4) Control + Test Movie (ctrl+enter) to test movie. Export movie to swf file.
5. The swf file is below:

Monday, September 12, 2011

Google book search

Google book search:

Google Books (previously known as Google Book Search and Google Print) is a service from Google that searches the full text of books that Google has scanned.
If you want to search book content, it is more convenient to search via
Google book search ( than

Friday, September 9, 2011

Design your logo free online

Go to:
After input your company name and your text, you can have more than
100 selections. Pick up one, edit it and download..

Check your network connection speed online

This website can help you check your network connection speed online:
This is my test result for wireless and wire network connection:
wireless: ping 3ms Download speed 1.35 Mbps, upload speed 10.40 Mbps
wire: ping 8ms Download speed 71.49 Mbps, upload speed 74.50 Mbps

It seems that wireless is much slower.

Wednesday, September 7, 2011

Power of illusion and brain plasticity

After Clicking play, click video to watch video and click ^ in bottom control bar to return to main menu

Tuesday, September 6, 2011

Embed pdf file in your website

The following code embed pdf file myfile1.pdf in your html code:
<object type="application/pdf" data="myfile1.pdf" width="100%" height="1000" ></object>

Generate favicon icon online

A favicon is nothing a 16 pixels by 16 pixels icon with .ico file extension.
The favicon icon is displayed at beginning of the browser URL bar, and the navigation tabs. You can generate favicon icon from pictures online from

The image I input:

The favicon I generated:

To insert favicon, insert the following code between <head></head>
<link rel="shortcut icon" href ="/favicon.ico">
(favicon.ico file is put under your web root) 

Friday, September 2, 2011

Add and remove programs in Windows 7

In Windows XP, it is quite straightforward to add or remove programs.
When you click control panel, you can see "Add or remove programs" icon.
In Windows 7, it is a little different.
1) Click control panel;
2)Click programs and features icon ( no more "Add or remove programs" icon.)
3)Choose a program, right click mouse to uninstall/change a program.

Thursday, September 1, 2011

Add excutable path in Windows 7

1. Right-click Computer on desktop and click Properties.
2. Click Advanced system setting in the popup Windows
3. Click on the Advanced tab and click Environment Variables button.
4. Highlight variable Path line and click edit
5. Append the semi-colon ; and the executable path
C:\Program Files;C:\Winnt;C:\Winnt\System32