Skip to content

Instantly share code, notes, and snippets.

View roycrxtw's full-sized avatar

Roy Cooper roycrxtw

  • ViewSonic
  • Japan
View GitHub Profile
#!/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
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)
@roycrxtw
roycrxtw / getfiles.js
Last active April 11, 2017 17:17
Get all files in specific directory recursively. (Using node.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);
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);
});
@roycrxtw
roycrxtw / test.js
Created March 17, 2017 16:08
Test for space
var foo = function(){
// first line
console.log('foo is cool.');
}
@roycrxtw
roycrxtw / json-to-html.js
Last active March 17, 2017 16:58
Convert json to html with a very simple html layout.
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){
@roycrxtw
roycrxtw / data.json
Created March 17, 2017 15:59
a sample data for htm-pdf post
[{
"name":"Tainan",
"date":"2017-03-13",
"avg":21,
"max":26.2,
"min":17.8
},
{
"name":"Tainan",
"date":"2017-03-14",
@roycrxtw
roycrxtw / demo.js
Last active March 17, 2017 17:02
html-pdf簡易範例
// 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);
}
@roycrxtw
roycrxtw / gist:e07e4f705dd09608fabc287f08a4dbc4
Last active February 18, 2017 02:43
Convert array to Hex String
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;