View test-vision.py
#!/usr/bin/python3 | |
# coding=utf8 | |
import io | |
import json | |
import os | |
# Imports the Google Cloud client library | |
from google.cloud import vision | |
from google.cloud.vision import types |
View uploadImage.py
def uploadImage(): | |
with open("temp.jpg", "rb") as fs: | |
binary_data = fs.read() | |
url = 'https://api.imgur.com/3/image' | |
payload = {'image': binary_data} | |
files = {} | |
headers = { | |
'Authorization': 'Client-ID ' + client_id | |
} | |
response = requests.request('POST', url, headers = headers, data = payload, files = files, allow_redirects = False, timeout = 10000) |
View getfiles.js
/** | |
* Get all files in specific directory recursively. | |
*/ | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
var getFiles = function(path){ | |
console.log('-----------------------------------'); | |
console.log('Now on: ', path); |
View topdf.js
var pdfOptions = {format: 'Letter'}; //輸出成Letter size(216 x 279 mm) | |
pdf.create(html, pdfOptions).toFile('./weather.pdf', function(err, result){ | |
if(err){ | |
console.log('error in pdf.create(), err=', err); | |
} | |
console.log('result=', result); | |
}); |
View test.js
var foo = function(){ | |
// first line | |
console.log('foo is cool.'); | |
} |
View json-to-html.js
var fs = require('fs'); | |
// load json file | |
var obj = fs.readFileSync('data.json', 'utf8'); | |
var htmlStart = '<html><body>'; //因示範用途,故簡化html結構 | |
var htmlEnd = '</body></html>'; | |
var htmlContent = ''; | |
for(var i in obj){ |
View data.json
[{ | |
"name":"Tainan", | |
"date":"2017-03-13", | |
"avg":21, | |
"max":26.2, | |
"min":17.8 | |
}, | |
{ | |
"name":"Tainan", | |
"date":"2017-03-14", |
View demo.js
// source: html格式之變數,來源可以是從檔案輸入(fs.readFileSync) | |
// 或是儲存html tags的string變數 | |
var source; | |
var pdfOptions = {}; // 設定pdf轉換之選項 | |
// 將source檔輸出至filePath指定之位置 | |
pdf.create(source, pdfOptions).toFile(filePath, function(err, result){ | |
if(err){ | |
console.log('error in pdf.create(), err=', err); | |
} |
View gist:e07e4f705dd09608fabc287f08a4dbc4
var arr = [127, 1128, 5, 31]; | |
function toHexString(array){ | |
var result = []; | |
for(var i in array){ | |
// directly toString() | |
result.push(array[i].toString(16)); | |
} | |
return result; |