Tuesday, September 30, 2014

Windows 7 - connect to a projector




Windows 7 - connect to a projector
 press the Windows logo key Picture of Windows logo key+P).

Choose
  • Duplicate (This shows your desktop on both your computer screen and a projector.)

Monday, September 29, 2014

Vi: show line number




To display line number in v:
 :set number
To unset line number
 :set number!
Undo
u
Redo
ctrl r

Saturday, September 27, 2014

Design date and signature box in Latex



To design date and signature box in Latex:

\begin{tabular}{ | b{2.6cm} | b{0.5cm}  | b{4.7cm}  | b{0.5cm}  | b{3cm}  | b{0.5cm} | b{4.7cm} |}
        \multicolumn{4}{l}{\ftext{Department Approval}} &
        \multicolumn{3}{l}{\ftext{Accepted by Appointee}} \\
        \cline{1-1} \cline{3-3} \cline{5-5} \cline{7-7}

        \multicolumn{1}{|c|}{\multirow{2}{*}} & \ & \ & \ & \ & \ & \\
        \ & \ & \ & \ & \ & \ & \\
        \cline{1-1} \cline{3-3} \cline{5-5} \cline{7-7}

        \multicolumn{1}{l}{\ftext{Date}} & \multicolumn{1}{l}{\null}   &
        \multicolumn{1}{l}{\ftext{Signature}}  & \multicolumn{1}{l}{\null}   &
        \multicolumn{1}{l}{\ftext{Date}}  & \multicolumn{1}{l}{\null}   &
        \multicolumn{1}{l}{\ftext{Signature}}
\end{tabular} \\

\begin{tabular}{| b{2.6cm} | b{0.5cm}  | b{4.7cm}  |    }
        \multicolumn{2}{l}{\ftext{Faculty Approval}} &  \multicolumn{1}{l}{\ftext{}}  \\
        \cline{1-1} \cline{3-3}

        \multicolumn{1}{|c|}{\multirow{2}{*}} & \ & \\
        \ & \ &   \\
        \cline{1-1} \cline{3-3}

        \multicolumn{1}{l}{\ftext{Date}} & \multicolumn{1}{l}{\null}   &
        \multicolumn{1}{l}{\ftext{Signature}}

\end{tabular} \\
 

result:

Windows Live Movie Maker in Windows 8




Windows Live Movie  Maker is not  with Windows 8, you need to download
Windows essential 2012 from
http://windows.microsoft.com/en-ca/windows-live/movie-maker
which includes Windows Live Movie  Maker.

To upload video from  Windows Live Movie  Makerto youtube, you may get an error message. This is due to the security setting in your google account.

Go to Google setting,  click security:
https://www.google.com/settings/security/lesssecureapps?hl=en-GB
Change "Access to less secure apps" from disable to enable.

Friday, September 26, 2014

Linux, change all file ownership in a directory and all sub-directories recursively




For example, I want to change the ownership of all files in the directory "html" and its sub-directories recursively to jiansen in Linux:
sudo chown -R jiansen html

Thursday, September 25, 2014

Convert MySQl date format to PHP, convert date to term




In MySQl, the date format is yyyy-m-d.
To change to date format in PH, $dateMySQL below is MySQl date format  yyyy-m-d.
      $date = strtotime($dateMySQL);
        $year = date("Y", $date );
        $month = date("n", $date);
        $day = date("j", $date );


$year, $month, $day is to extract year, month and day. strtotime is to convert format time to to unix time.
Below is an example to convert MySQL date format to SFU term. and return the style of box shadow
in red.
    function style_for_initialcredit($termkey, $datecredit) {
        $date = strtotime($datecredit);
        $year = date("Y", $date );
        $month = date("n", $date);
        $day = date("j", $date );
        if($month>=1 && $month<=4) {$term  = ($year-1900)*10+1;}
        elseif($month>=5 && $month<=8) {$term  = ($year-1900)*10+4;}
        elseif($month>=9 && $month<=12) {$term  = ($year-1900)*10+7;}
        else  $term = 0;       

        $style = "";
        if($term==$termkey)
            $style .=" box-shadow: inset -10px 0 5px -5px hsla(0,100%,50%,0.5); ";
        return trim($style);
  
    }

Tuesday, September 23, 2014

Check if a given key exsits in an array in PHP




To check if a given key exsits in an array in PHP, PHP function array_key_exists is used.
Example: check if $var variable  exists in  array $search_array key.
<?php
$search_array 
= array('a' => 1'b' => 2);
$var = 'a';
if (
array_key_exists($var$search_array)) {
    echo 
"The var element is in the array";
}
?>

PHP, dump varailbes in a format way




var_dump function in PHP dumps the variable in un-formatted way.
To dump variable $var in a formatted manner in PHP:
echo "<pre>";
var_dump($var);
echo "</pre>";

Monday, September 22, 2014

Camtasia, record, pause, stop and upload to YouTube




In Camtasia studio, press F9 to record, press F9 again to pause, press F10 to stop.
Click edit, from the dropdown menu, select edit, enter new preset name such as JiansenYoutube, enter the parameter as following, disable control so we can disable html. I only need mp4, not swf and html.
About the file format to upload to Youtube:
video in MP4 format at 1280 x 720 best
Choose File Produce Video As > "Custom Production Settings" > Next > choose MP4/FLV/SWFNext Flash Options. For HD playback, we recommend setting the bitrate to 5000Kbps. You set the bitrate by clicking the Flash Options button.

Tuesday, September 9, 2014

Update One row from another row in same table in MySQL



Update the row with rank column with "Limited Term Senior Lecturer" from the row
 "Limited Term Lecturer" in same table contract_has_inserts as:
UPDATE contract_has_inserts as t1 INNER JOIN contract_has_inserts as t2 ON t1.Name = t2.Name SET t1.Insert = t2.Insert, t1.Header=t2.Header
WHERE t1.Rank="Limited Term Senior Lecturer" AND t1.ContractStatus="NEW" AND
t2.ContractStatus="New" AND t2.Rank="Limited Term Lecturer"
AND
(t2.Name = "Offer" OR t2.Name ="Responsibilities" OR t2.Name ="Freedom of Information"
OR t2.Name ="Membership" OR
t2.Name ="Closing Paragraph" OR t2.Name="Acceptance of Offer" OR t2.Name="Copyright")


Copy one table to another table (or same table) and update fields




Copy field1 and field2 in  table1 to table2 and update field3 as 'John' in MySQL
Insert into table2 (field1, field2, field3) select field1, field2, 'John' from table1;

  We can do the same in same table  if primarykey is AUTO_INCREMENT:

Insert into table1 (field1, field2, field3) select field1, field2, 'John' from table1 WHERE primarykey=1;

if primarykey is  not AUTO_INCREMENT, we can assign a new primary key such as 666:

Insert into table1 (primarykey, field1, field2, field3) select  666, field1, field2, 'John' from table1 WHERE primarykey=1;