This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = function(){ | |
// first line | |
console.log('foo is cool.'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"name":"Tainan", | |
"date":"2017-03-13", | |
"avg":21, | |
"max":26.2, | |
"min":17.8 | |
}, | |
{ | |
"name":"Tainan", | |
"date":"2017-03-14", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |