Skip to content

Instantly share code, notes, and snippets.

Avatar

Hiroki Tanaka pirosuke

  • Japan
View GitHub Profile
@pirosuke
pirosuke / CREATE_FUNCTION_GET_LIST_SIMILARITY.sql
Created Aug 23, 2015
Function for checking list similarities on PostgreSQL
View CREATE_FUNCTION_GET_LIST_SIMILARITY.sql
CREATE OR REPLACE FUNCTION SF_GET_LIST_SIMILARITY(
p_list1 text[],
p_list2 text[]
) RETURNS NUMERIC(19,4) AS $$
DECLARE
w_list text[] := '{}';
BEGIN
IF p_list1 IS NULL OR p_list2 IS NULL THEN
RETURN 0;
END IF;
@pirosuke
pirosuke / CREATE_FUNCTION_IN_LIST.sql
Created Aug 23, 2015
in_list function for PostgreSQL
View CREATE_FUNCTION_IN_LIST.sql
CREATE OR REPLACE FUNCTION SF_IN_LIST(
p_list1 text[],
p_list2 text[]
) RETURNS BOOLEAN AS $$
DECLARE
w_is_in_list BOOLEAN := true;
BEGIN
IF p_list1 IS NULL OR p_list2 IS NULL THEN
RETURN false;
END IF;
@pirosuke
pirosuke / get_obj_attr.py
Last active Aug 30, 2015
A function to get value from multi level object. Usage: get_obj_attr(item, "ItemAttributes.Title")
View get_obj_attr.py
def get_obj_attr(root, str_path, default_val="", debug=False):
attr_path = str_path.split(".")
base_obj = root
for attr in attr_path:
if hasattr(base_obj, attr):
base_obj = base_obj.__dict__[attr]
else:
if debug:
print "No attribute: %s" % attr
base_obj = default_val
@pirosuke
pirosuke / hatebu.js
Created Feb 14, 2016
Node.js XMLRPC Client Sample
View hatebu.js
var xmlrpc = require('xmlrpc');
var Hatebu = {};
Hatebu.getHatebuCount = function (domain, callback) {
var client = xmlrpc.createClient({
host: "b.hatena.ne.jp",
path: "/xmlrpc"
});
client.methodCall('bookmark.getTotalCount', [domain], function (error, value) {
@pirosuke
pirosuke / app.js
Last active Feb 14, 2016
REST API Sample For IFTTT Maker Channel.
View app.js
var express = require('express')
, bodyParser = require('body-parser')
, ifttt = require('./ifttt')
, http = require('http')
, path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
@pirosuke
pirosuke / example_task.js
Created Jan 19, 2019
Example Using node-cron
View example_task.js
const cron = require('node-cron');
const exampletask = require('./exampletask');
cron.schedule('0 9 * * * *', () => {
exampletask.main();
console.log('task completed');
});
@pirosuke
pirosuke / fetch_data_from_sql_server.js
Created Jan 19, 2019
A Sample To Fetch Data From MSSQL using Windows Authentication
View fetch_data_from_sql_server.js
const msnodesql = require("msnodesqlv8");
async function fetchDataList(conn, query) {
return new Promise((resolve, reject) => {
conn.query(query, (err, rows) => {
if (err !== null) {
reject(err);
return;
}
@pirosuke
pirosuke / minecraft_set_block.js
Created Jan 19, 2019
Sample Program To Put Block In Minecraft From Node.js
View minecraft_set_block.js
const WebSocket = require('ws');
const app = require('express')();
const server = require('http').Server(app);
const uuid = require('uuid/v4');
// Creates a JSON string for "setblock" command request
function setBlockCommand(x, y, z, blockType) {
return JSON.stringify({
"body": {
"origin": {
@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 / 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',