Skip to content

Instantly share code, notes, and snippets.

Avatar

Roy Claude roycrxtw

View GitHub Profile
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)
@roycrxtw
roycrxtw / getfiles.js
Last active Apr 11, 2017
Get all files in specific directory recursively. (Using node.js)
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);
});
@roycrxtw
roycrxtw / test.js
Created Mar 17, 2017
Test for space
View test.js
var foo = function(){
// first line
console.log('foo is cool.');
}
@roycrxtw
roycrxtw / json-to-html.js
Last active Mar 17, 2017
Convert json to html with a very simple html layout.
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){
@roycrxtw
roycrxtw / data.json
Created Mar 17, 2017
a sample data for htm-pdf post
View data.json
[{
"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 Mar 17, 2017
html-pdf簡易範例
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;