Posts

=================================

Python - How to get current date time and format its output | DzQ39 |

This is a quick summary of how to get the current date and time and format its output in Python.

The Code

import datetime
print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

The Result


Reference:

How to view cookies in Chrome and Firefox | DzQ39 |

This post is a quick summary of how to view cookies info. using Chrome and Firefox.



Chrome

1. Launch Chrome web browser and visit the site that you want to check for cookies.


2. Right click on the web page to bring up the menu and left click on the last item (Inspection) in the list.


3. The info. for cookies is under Application.

Note, Chrome doesn't support local cookies. For local cookies support, use Firefox / IE

Firefox

1. Install "View Cookies" (https://addons.mozilla.org/zh-tw/firefox/addon/view-cookies/).

2. Restart Firefox.

3. Visit the website that you want to check for cookies, once there, right click on any part of the webpage to bring up the menu. The View Cookies add-on is under View Page Info..


4. Click on Cookies to see cookies info. There is no domain info. because the page is launched locally.


How to get the selected option in a drop down list | DzQ39 |

This post is about how to get the selected option in a drop down list. The source of the code is at https://www.w3schools.com/js/tryit.asp?filename=try_dom_select_option.

Code


 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<script>
function getOption() {
var obj = document.getElementById("mySelect");
document.getElementById("demo").innerHTML =
obj.options[obj.selectedIndex].text;
}
</script>
</head>
<body>

<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br><br>
<input type="button" onclick="getOption()" value="Click Me!">
</form>

<p id="demo"></p>

</body>
</html>

Reference:

JavaScript HTML Input Examples
https://www.w3schools.com/js/js_input_examples.asp


Working with cookies | DzQ39 |

This is a quick summary of how to work with cookies.

The code below is from https://www.w3schools.com/js/js_cookies.asp.


 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
<script>

function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

function checkCookie() {
var user=getCookie("username");
if (user != "") {
alert("Welcome again " + user);
} else {
user = prompt("Please enter your name:","");
if (user != "" && user != null) {
setCookie("username", user, 30);
}
}
}

</script>
</head>
<body onload="checkCookie()">
</body>
</html>

Note that Chrome doesn't support local cookies. That is, the above code won't work if it's run from a local storage (it will run fine if it's run from a server). However, Internet Explorer, Firefox, Safari, and Opera don't have such problem. For detail, see the discussion at https://productforums.google.com/forum/#!topic/chrome/iow88FsnNhQ.

How to get input text field using HTML and JavaScript | DzQ39 |

This is a quick example of how to get the input value from the input text filed, display it and reset it back to the original content.

Code




 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<body>

Enter something: <input type="text" id="myText" value="" placeholder="Enter anything">

<p>Enter anything in the above field and click on the Submit button to display the value of the value attribute of the text field.</p>
<p>To clear, click on the Reset button.</p>

<button onclick="getInputText()">Submit</button>
<button onclick="resetInputField()">Reset</button>

<p id="demo"></p>

<script>
function getInputText() {
var x = document.getElementById("myText").value;
document.getElementById("demo").innerHTML = x;
}

function resetInputField() {
document.getElementById("myText").value = "";
document.getElementById("myText").placeholder = "Enter anything";
document.getElementById("demo").innerHTML = "";
}

</script>
</body>
</html>

Result

Reference:

https://www.w3schools.com/jsref/prop_text_value.asp

https://www.w3schools.com/tags/att_input_placeholder.asp

How to use swipe gestures to change webpages | DzQ39 |

The original post of is at http://stackoverflow.com/questions/23797331/using-swipe-gestures-to-change-pages-in-multi-page-jquery-mobile-application.

Note that because of minor differences, the code at http://jsfiddle.net/Gajotres/JB22E/3/ doesn't work. The code below is from the stackoverflow post and has been tested to work.


The Code

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<title>Share QR</title>
<meta name="viewport" content="width=device-width,height=device-height,minimum-scale=1,maximum-scale=1"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>

<script>
$(document).on('swipeleft', '.ui-page', function(event){
if(event.handled !== true) { // This will prevent event triggering more then once
var nextpage = $.mobile.activePage.next('[data-role="page"]');
// swipe using id of next page if exists
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
}
event.handled = true;
}
return false;
});

$(document).on('swiperight', '.ui-page', function(event){
if(event.handled !== true) { // This will prevent event triggering more then once
var prevpage = $(this).prev('[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
}
event.handled = true;
}
return false;
});
</script>
</head>

<body>
<div data-role="page" id="article1">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 1</p>
</div>
</div>

<div data-role="page" id="article2">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 2</p>
</div>
</div>

<div data-role="page" id="article3">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 3</p>
</div>
</div>

</body>
</html>

Result

Remote surveillance camera based on plain old USB Webcam | DzQ39 |

I recently developed a solution that turns any plain old USB Webcam into a remote surveillance camera. The images taken by the camera can be viewed from anywhere in the world on any device that supports browser and gmail.

The solution is very easy to setup. It doesn't require punching a hole on your router, obtaining dynamic DNS, having a fixed IP address, installing custom-made software on your device, etc. And, aside from your regular internet service charge, there is ZERO operating cost associated with using this solution


How it works

1. Connect your existing USB Webcam to the USB Webcam Controller.

2. Connect the USB Webcam Controller to the Wireless Router at Home / Office / etc.


3. Login to the Web UI of the USB Webcam Controller and enter the account name and password for the free gmail account that you apply for the USB Webcam Controller.

Set the interval at which the USB Webcam takes the photo and send to your gmail account.


4. The images taken are stored in your personal gmail and could be viewed from anywhere in the world on any device that supports browser and e-mail.

5. The possible applications are infinite (pet cam, baby cam, patient cam, security cam, etc.).


Technical Specifications

- Input Voltage: DC 9V (via AC 110V/220V to DC 9V adapter. Can be powered by DC 9V battery in case of power outage);

- USB 2.0 Host x 1 (for connecting to the USB Webcam);

- WiFi: Single input single output (1T1R) Wi-Fi 802.11 b/g/n.

Price & Shipping

- MSRP: US$49.99/ea (including English user's manual and AC 110V/220V to DC 9V adapter);

- Shipping: Shipping cost not included. Can ship via major carriers such as EMS / FedEx / DHL as requested.

- Item Location: Taipei, Taiwan.