Skip to content

Instantly share code, notes, and snippets.

Avatar

Hiroki Tanaka pirosuke

  • Japan
View GitHub Profile
@pirosuke
pirosuke / index.html
Created May 8, 2019
Image Convert With OpenCV.js
View index.html
<html>
<head>
<title>OpenCV.js Test</title>
</head>
<body>
<table>
<tr>
<th>source</th>
<th>output</th>
</tr>
@pirosuke
pirosuke / fetch_log.js
Last active Jan 24, 2019
An Example To Connect To Remote Server And Download PostgreSQL Log File
View fetch_log.js
const path = require('path');
const Ssh = require('node-ssh');
const moment = require('moment');
const tar = require('tar');
async function downloadSlowQueryLog(sshInfo, sshPassword, remoteSlowQueryLogDir, slowQueryLogFileName, localSlowQueryLogFilePath) {
const ssh = new Ssh();
const remoteSlowQueryLogFilePath = remoteSlowQueryLogDir + '/' + slowQueryLogFileName;
@pirosuke
pirosuke / remove_exif.js
Created Jan 21, 2019
A Sample Script To Remove EXIF Data From Image File.
View remove_exif.js
const path = require('path');
const fs = require('fs');
const piexif = require('piexifjs');
function removeExifFromImage(srcImgPath, destImgPath) {
const imgData = fs.readFileSync(srcImgPath).toString('binary');
const newImgData = piexif.remove(imgData);
fs.writeFileSync(destImgPath, newImgData, 'binary');
}
@pirosuke
pirosuke / check_exif.js
Last active Jan 21, 2019
A Sample Script To Get EXIF Data From Image File.
View check_exif.js
const path = require('path');
const fs = require('fs');
const piexif = require('piexifjs');
function getExifFromImage(imgPath) {
const imgData = fs.readFileSync(imgPath).toString('binary');
const exifRawData = piexif.load(imgData);
const exifData = {};
for (const exifType in exifRawData) {
@pirosuke
pirosuke / resize_images.js
Created Jan 20, 2019
An Example To Resize Image Files Using OpenCV And Node.js
View resize_images.js
const path = require('path');
const fs = require('fs');
const cv = require('opencv4nodejs');
function resizeImagesToMax(srcDirPath, destDirPath, maxWidthHeight) {
const srcFileList = fs.readdirSync(srcDirPath);
for (const srcFileName of srcFileList) {
if (!srcFileName.endsWith('.JPG')) {
continue;
@pirosuke
pirosuke / fetch_remote_db_data.js
Created Jan 19, 2019
Sample To Fetch Data From Remote Database Table Through SSH Tunnel With Node.js
View fetch_remote_db_data.js
const tunnel = require('tunnel-ssh');
import knexLib = require('knex');
async function main() {
const sshUserName = 'SSH_USER_NAME';
const sshPassword = 'SSH_PASSWORD';
let sshConfig = {
host: 'SSH_HOST_ADDRESS',
port: SSH_PORT,
@pirosuke
pirosuke / ssh_tunnel_template.js
Created Jan 19, 2019
Template To Control Server Through SSH Tunnel With Node.js
View ssh_tunnel_template.js
const tunnel = require('tunnel-ssh');
async function main() {
const sshUserName = 'SSH_USER_NAME';
const sshPassword = 'SSH_PASSWORD';
let sshConfig = {
host: 'SSH_HOST_ADDRESS',
port: SSH_PORT,
username: sshUserName,
@pirosuke
pirosuke / print_remote_file_list.js
Created Jan 19, 2019
Sample To Print Files In Directory Through SSH Using Node.js
View print_remote_file_list.js
const Ssh = require('node-ssh');
async function main() {
const ssh = new Ssh();
const sshPassword = 'SSH_PASSWORD';
// connect
await ssh.connect({
host: 'SSH_HOST_ADDRESS',
@pirosuke
pirosuke / convert_img_to_line_drawing.js
Created Jan 19, 2019
Convert Image Files To Line Drawings With OpenCV And Node.js
View convert_img_to_line_drawing.js
const path = require('path');
const fs = require('fs');
const cv = require('opencv4nodejs');
function convertImageToLineDrawing(img) {
const kernel = new cv.Mat([
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
@pirosuke
pirosuke / convert_img_to_line_drawing.py
Created Jan 19, 2019
Convert Image Files To Line Drawings With OpenCV
View convert_img_to_line_drawing.py
# -*- coding: utf-8 -*-
import os
import cv2
import numpy as np
def create_line_drawing_image(img):
kernel = np.array([
[1, 1, 1, 1, 1],