Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- PHP: add a download as pdf file button in report page
- How to blend adsense inside your post?
- Formatting my post
- Notepad++ - Add C++ compiler
- PHP connect IBM db2 database in XAMPP
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- Set up a child account and set screen time limit in Windows 8
Sunday, December 20, 2015
Microsoft Family Windows 10 Parental Controls Screen time not working and swtich to Norton family
I have windows 8, later upgraded to Windows 10. Parental Controls Screen time is not working anymore after upgrading. First screen time does not show correctly. My hourly rule and block all days are not working. I checked the solution by google. was told that On the Start screen, right click and the find run and click, and type C:\ProgramData\Microsoft\Windows\Parental Controls and press Enter.
Delete all contents of the Parental Controls folder. "
This will delete any corrupt files. Your settings will be downloaded again from familysafety.microsoft.com the next time you sign in."
I did find settings.bin, but inside almost empty, only "{}".
I think there is a problem in Microsoft family Windows 10 parental control. Finally I switched to Norton Family. Norton Family has same feature Microsoft family has, but has more, although I need to pay small money each year.
Norton family premier link:
https://onlinefamily.norton.com/familysafety/loginStart.fs
There is 30 days free trial. I am quite satisfied Norton family during trial.
Sunday, June 21, 2015
Set up a child account and set screen time limit in Windows 8
1) To set up a child account in Windows 8:
a) Click start menu and click control panel
b) Click User Account, click manage another account
c) Add a new account
d) Click add a child account with email or with email account
e) Click mange family safety online or directly go to your Microsoft account online
2)Set screen time limit for child account under parental control
a) Go to your microsoft account
https://account.microsoft.com/
b)click family and click screen time and select maximum time per day your child can use computer.
you can also choose which kind of websites, apps and games your child can access.
Video: Set up a child account and set screen time limit in Windows 8
Wednesday, June 10, 2015
MySQL data type timestamp auto-initialized and auto-updated
When we set MySQL data type timestamp, the default is auto-initialized. It is set to the current timestamp for inserted rows. This can be used in a column such as creation date. In PHPMyAdmin,
the attribute is empty.
When we set the attributes "on update current_timestamp" and type 'timestamp' in PHPMyAdmin, the column is auto-updated. It is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. The column remains unchanged if all other columns are set to their current values. This can be used in a column such as modification date.
MySQL:
ALTER TABLE `max_term_default_ttr_lut` ADD `CreateDate` TIMESTAMP NULL DEFAULT NULL ,
ADD `ModificationDate` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL DEFAULT NULL ,
ADD `creator` VARCHAR( 45 ) NULL DEFAULT NULL ,
ADD `modifier` VARCHAR( 45 ) NULL DEFAULT NULL ;
Parse JSON in JavaScript
In PHP, I used
$message['success'] = "Personal Information Updated";
echo json_encode($message);
to pass $message to Javascript .post
$.post('stakeholderInfo.php', $(".box#stakeholderInfo div #editInfoForm").serialize(), function(jsonMessage) {
obj = JSON.parse(jsonMessage);
alert(obj['success']);
});
Here I used JSON.parse to parse JSON in JavaScript, then display message alert(obj['success']);
Monday, June 8, 2015
phpexcel toggle expand and hide column in EXCEL and summary
PHP has built-in feature to read and write CSV files. PHPExcel extends this feature and allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.
PHPExcel can be downloaded from:
https://phpexcel.codeplex.com/
To start PHPExcel, PHPExcel library path should be included first, for example installed in _classes
include_once "./_classes/PHPExcel.php";
include_once './_classes/PHPExcel/Writer/Excel2007.php';
$objPHPExcel = new PHPExcel();
//choose the first page
$objPHPExcel->setActiveSheetIndex(0);
$objSheet = $objPHPExcel->getActiveSheet();
Toggle expand and hide columns A to C default expand:
foreach (range('A','C') as $column) {
$objSheet->getColumnDimension($column)->setOutlineLevel(1);
$objSheet->getColumnDimension($column)->setCollapsed(true);
}
Toggle expand and hide columns A to C default hide:
foreach (range('A','C') as $column) {
$objSheet->getColumnDimension($column)->setOutlineLevel(1);
$objSheet->getColumnDimension($column)->setVisible(false);
$objSheet->getColumnDimension($column)->setCollapsed(true);
}
Toggle expand and hide row 1
$objSheet->getRowDimension(1)->setOutlineLevel(1);
$objSheet->getRowDimension(1)->setVisible(false);
$objSheet->getRowDimension(1)->setCollapsed(true);
Set autosize
foreach (range('A','Z') as $column) {
$objSheet->getColumnDimension($column)->setAutoSize(true);
}
Set font size
$objSheet->getStyle("A1:AM1")->getFont()->setSize(14);
Set font bold
$objSheet->getStyle("A1:AM1")->getFont()->setBold(true);
Set column A1 header value
$objSheet->SetCellValue('A1', 'faculty');
Set cell column 1 row 2 value '4'
$objSheet->setCellValueByColumnAndRow(1, 2, '2');
Set number 1 as 0001 instead of 1
$objSheet->getStyle('F1:F'.$currentRow)->getNumberFormat()->setFormatCode('0000');
Set alignment left
$objSheet->getDefaultStyle()
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
Set column width
$objSheet->getColumnDimension('A1')->setWidth(15);
Set cell background color lightgreen
$objSheet->getStyle("A1:AM1")->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'C3FDB8')
)
));
Set line break using double quote to parse \n in PHP
$objSheet->SetCellValue('N1', "Instr\n contact \n hrs");
$objSheet->getStyle('N1')->getAlignment()->setWrapText(true);
Write out EXCEL file
ini_set('zlib.output_compression','Off');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
//the folowing two lines make sure it is saved as a xls file
header('Content-type: application/vnd.ms-excel');
//set the course offered id as page name
$objSheet->setTitle("Export");
$filename = " Export_".date("Ymd").".xls";
header('Content-Disposition: attachment; filename= "'.$filename.'"');
header("Content-Transfer-Encoding: binary");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
Sunday, May 31, 2015
jQuery autocomplete in PHP and force to pickup
jQuery autocomplete introduction
https://jqueryui.com/autocomplete/
My example: autocomplete data from php
Input box values force to come from autocomplete dropdown
Two files: jquery_autocomplete.php, tags.php
jquery_autocomplete.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#tags" ).autocomplete({
source: 'tags.php',
minLength : 0,
select : function(event, ui) {
newname = ui.item.label;
var url = '';
$.post(url, ui.item.label, function(data) {
//alert(ui.item.label);
});
},
change : function() {
curname = $("#tags").val();
if(curname.trim()!= newname) {
alert("You need to pick a tag from the tag list.");
$("#tags").val(oldname);
}
}
}).focus(function(){
$(this).autocomplete('search');
oldname=$(this).val();
});
});
</script>
</head>
<body>
<form onsubmit="return false" id="editContractInfo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input type="text" id="tags" name="tags">
</div>
</form>
</body>
</html>
tags.php
<?php
$availableTags = array(
array("label"=>".Tbd", "value"=>".Tbd"),
array("label"=>"ActionScript", "value"=>"ActionScript"),
array("label"=>"AppleScript", "value"=>"AppleScript"),
array("label"=>"Asp", "value"=>"Asp")
);
echo json_encode($availableTags);
?>
Video: jQuery autocomplete in PHP and force to pickup
Saturday, May 30, 2015
Bootstrap Modal Dialog Example in PHP
This article is to show how to popup a dialog in Modal and post in PHP.
Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. Bootstrap can be downloaded from:
http://getbootstrap.com/
Two files for this demo:
modal_dialog.php, mydialogexample.js
modal_dialog.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="mydialogexample.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Dialog Example</h2>
<!-- Universal Modal -->
<h4>Student Number: <input type="text" name="student_number">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="searchBtn_studentNum">Search Student</button> </h4>
<div class="modal fade" id="universalModal" tabindex="-1" role="dialog" aria-labelledby="universalModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:1000px;">
<div class="modal-content">
<form role="form" id="universalModalForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only"> Close</span></button>
<h4 class="modal-title"><span class="glyphicon glyphicon-pencil"></span> Edit<span class="modal-title">.model-title</span></h4>
</div>
<div class="alert alert-danger fade in" id="universalModal-alert" style="display: none;">
<span class="alert-body"></span>
</div>
<div class="modal-body">.modal-body</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" id="submitBtn"></button>
</div>
</form>
</div>
</div>
</div>
<!-- Result Modal-->
<textarea id="searchResultForm" style="display:none">
<table class="table table-striped table-hover" >
<tbody>
<tr>
<td><b>Last Name: </b></td>
<td> <input type="text" name="lname">
</td>
<td><b>First Name:</b> </td>
<td> <input type="text" name="fname"></td>
</tr> </tr>
</tbody>
</table>
</textarea>
<!-- Trigger the modal with a button -->
</div>
</body>
</html>
mydialogexample.js
$(document).ready(function(){
$('#universalModal form').submit(function (event){
event.preventDefault();
var formObj = {};
var inputs = $(this).serializeArray();
var url = '';
$.each(inputs, function(i, input) {
formObj[input.name] = input.value;
});
var len = inputs.length;
var dataObj = {};
for (i=0; i<len; i++) {
dataObj[inputs[i].name] = inputs[i].value;
}
//inputs['lname'];
$.post(url, inputs, function(data) {
$('#universalModal').modal('hide');
});
});
$('#searchBtn_studentNum').off('click').click(function(){
var student_num = $('input[name="student_number"]').val();
$('#universalModal').modal('show');
$('#universalModal .modal-title').html('<b>Enter Student Info</b>');
$('#universalModal .modal-body').html($('#searchResultForm').val());
$('#universalModal .modal-footer button#submitBtn').html('Save and Exit');
});
});
Video:Bootstrap Modal Dialog Example in PHP
Monday, April 6, 2015
Daily backup MySQL database to another computer
Assume MySQL server is example.ca, I want to dump MySQL database test to dev2.ca daily.
1) In PHPMyAdmin, click Users, add new user jiansenbk and host dev2.ca and database test
grant all
2) In dev2.ca
create MySQLdump1.sh (no line break below)
mysqldump -h example.ca -u jiansenbk -pPass2 test
| gzip >/home/jiansen/mysqldump/MySQLDB_`date +"%Y%m%d"`.sql.gz
3) chmod +x MySQLdump1.sh
4) crontab -e
and enter (no linebreak, chnage server and user name password and database to yours)
45 23 * * * /home/jiansen/mysqldump/MySQLdump1.sh 2>&1>>/home/jiansen/mysqldump/mysqlbackup.log
Every night 11:45. MySQL database test is dump to /home/jiansen/mysqldump with different timestamps
Video: Daily backup MySQL database to another computer
Add login screen and second user login in PHPMyAdmin
1) Default PHPMyAdmin without login screen. To add login screen:
Go to Users, find root@localhost and edit privileges and change password. Use same password in XAMPP configuration
2) Under xampp/phpMyAdmin/config.inc.php
change
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
to
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'test';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
3) To add second name and password in login scrren:
Go to Users tab in PHPMyAdmin, Add new User, type username and password, select host as localhost and check all and click go.
Video: Add login screen and second user login in PHPMyAdmin
Sunday, February 8, 2015
Install XAMPP 5.6.3 in Windows 8
Install XAMPP 5.6.3 in Windows 8
XAMPP is an easy to install Apache distribution containing MySQL, PHP, and Perl.
To install XAMPP 5.6.3 in Windows 8:
1) Go to
https://www.apachefriends.org/download.html
2) save exe file and run
3) Ignore anti-virus warning,
4) For UAC control warning, change install directory not in
under C:\Program files or Program files (x86)
5) Finish XAMPP installation and run XAMPP control panel, start Apache and MySQL
6) type localhost and click English, click PhpMyAdmin to see your MySQL database
7) Go to htdocs under XAMPP installation directory, create a folder (for example jinasentest) and a file test.php under jiansentest and run test.php under localhost/jiansentest/test.php
test.php:
<?php
echo "This is a test";
?>
Video: Install XAMPP 5.6.3 in Windows 8
Open Google homepage instead of Yahoo in new tab in Firefox
In Firefox, when you open a new tab, you may find the default is yahoo website while you want to set it as Google homepage. To set the default address for new tab, the following steps should be followed:
1. type about:config in web address
2. Accept warning
3. type newtab in search box
4. Double-click the browser.newtab.url,
change address from Yahoo to https://google.com
Video: Open Google homepage instead of Yahoo in new tab in Firefox
Saturday, January 31, 2015
PHP and JavaScript, check a string contains a substring
In PHP, we use strpos to check if a string contains a substring.
strpos function— Find the position of the first occurrence of a substring in a string, it may return 0 as it's index value.
If you do a
==
compare that will not work, you will need to do a ===.
A
==
sign is a comparison and tests whether the variable
/ expression / constant to the left has the same value as the variable /
expression / constant to the right. A
===
sign is a comparison to see whether two variables / expressions / constants are equal AND
have the same type - i.e. both are strings or both are integers.Example:
1) to check $contract string contains "Sessional" substring in PHP
if(strpos($contract, 'Sessional') ! = = false)
2) to check $contract string does not contain "Sessional" substring in PHP
if(strpos($contract, 'Sessional') = = = false)
In JavaScript, we use indexOf function
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.
Example
1) to check contract string contains "Sessional" substring in JS
if( contract.indexOf("Sessional")!=-1)
2) to check contract string does not contain "Sessional" substring in JS
if( contract.indexOf("Sessional") = = -1)
More about string operation in Javascript
In JavaScript, To get the the first character of string contract, we use
contract.charAt(0)
To get a substring of a string for example
term1=(term).substring(0,4);
where 0 is start position, and 4 is end position, but not included.
To trim a string for example term
term.trim();
or using jQuery
$.trim(term)
Similarly in PHP we have substr function,
for example
echo substr('abcdefg', 0, 4);
return abcd, also not including end position.
Sunday, January 25, 2015
Remove ads agent and improve Internet security in FireFox
You may not notice there are some background ads agent running when you use Firefox even you installed Anti-virus. In the worst case, your personal information may be posted to other websites and stolen.
To check and remove suspicious programs in your computer:
1. In Firefox, go to menu and click Add-ons, go to Extension,
enable anti-virus, go to plugins, select "never activate" or
remove suspicious programs.
2. Go to control panel, go to programs and features, uninstall programs in Windows, find suspicious programs installed lately (click installed on to sort by installation date) and remove.
3. In Firefox, go to google.com or other address, go to Firefox menu, click developer and click network and reload, find if your data are posted to some suspicious websites.
Video: Remove ads agent and improve Internet security in Fire Fox
Subscribe to:
Posts (Atom)