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 / excel2psql.py
Last active Aug 11, 2021
A Python script to create SQL file from Excel
View excel2psql.py
# coding: utf-8
from __future__ import unicode_literals
import xlrd
import codecs
def output_insert_sqls(excel_path, output_path, sheet_names, table_names):
book = xlrd.open_workbook(excel_path)
out_f = codecs.open(output_path, "w", "utf_8")
@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.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],