Skip to content

Instantly share code, notes, and snippets.

View anyinan's full-sized avatar

Yinan An anyinan

  • Vancouver
View GitHub Profile
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible.
return clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
document.body.appendChild(textarea);
@anyinan
anyinan / gist:bb2a01ca6f1b497446c84bbfde26ab07
Created November 5, 2017 01:49
usage of node http.require() and with url
https://nodejs.org/api/http.html#http_http_get_options_callback
const postData = querystring.stringify({
'msg': 'Hello World!'
});
const options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
@anyinan
anyinan / gist:113b8e99cbb3d1b2843b566aaeb2a762
Created November 5, 2017 01:46
useage of Node http.get()
http.get('http://nodejs.org/dist/index.json', (res) => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
let error;
if (statusCode !== 200) {
error = new Error('Request Failed.\n' +
`Status Code: ${statusCode}`);
} else if (!/^application\/json/.test(contentType)) {
error = new Error('Invalid content-type.\n' +