Skip to content

Instantly share code, notes, and snippets.

View akirattii's full-sized avatar

Akira TANAKA akirattii

View GitHub Profile
@akirattii
akirattii / background.js
Last active June 4, 2021 11:04
an example of chrome extension, which can be opened as new tab by click its browser icon.
console.log("background");
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({
'url': chrome.extension.getURL('popup.html')
}, function(tab) {
// Tab opened.
});
});
@akirattii
akirattii / QRCodeScanner.js
Last active March 15, 2023 05:53
NodeJS: QRCode scanning library. Either file and webcam source scanning are available. (browser compatible)
/**
QRCode Scanner library
https://gist.github.com/akirattii/35b033000cd4479c337ae5abb09d7429
@author: akirattii <tanaka.akira.2006@gmail.com> (http://mint.pepper.jp)
@dependencies:
+ jquery
+ jsQR (https://github.com/cozmo/jsQR/)
@akirattii
akirattii / purejs-fire-event-example.js
Created February 23, 2018 04:34
Pure js event trigger
const el = document.qeurySelector("#input-x");
// Fire `input` event:
el.dispatchEvent(new Event('input', {
'bubbles': true,
'cancelable': true
}));
// or
@akirattii
akirattii / server.js
Created January 26, 2018 07:27
express: Implement a graceful shutdown handling `forever stop`
/*
Run server by forever with `--killSignal=SIGTERM`:
```
$ forever --killSignal=SIGTERM start ./server.js
```
Now `gracefulShutdown` function is called when you stop the server by `forever stop`:
```
@akirattii
akirattii / form-validator.js
Last active April 27, 2018 06:02
Form validation library using HTML5 + vue2 + bootstrap4, some complex validation also available.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Deprecated!!! 2018-04-27
// recommends HTML5 validator of Bootstrap (v4.1.0) instead.
// https://getbootstrap.com/docs/4.0/components/forms/#validation
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*
Simple Form Validator
@dependencies: vue.js, bootstrap4
@see: https://gist.github.com/akirattii/83937626062fc38f8f1ac5c91f172e72
@akirattii
akirattii / example-call-bitcoind.js
Created December 27, 2017 22:23
JS: JSON RPC client
//
// An example of a bitcoind JSON RPC request.
//
// Example request of curl:
// $ curl --data-binary '{"jsonrpc": "1.0", "id":"hoge", "method": "getblockhash", "params": [9999] }' http://rpc:rpc@127.0.0.1:18332/
//
const URL = "http://rpc:rpc@127.0.0.1:18332"; // bitcoind testnet. user:"rpc", password:"rpc"
const RpcClient = require("./rpc-client.js");
@akirattii
akirattii / mysql-check-dbsize-and-shrink.sql
Last active March 2, 2020 10:00
MySQL: Check database size and optimize to shrink size
-- https://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database
mysql>
SELECT table_schema
"DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
-- RESULT:
-- +-----------------------+---------------+
@akirattii
akirattii / server.js
Created December 6, 2017 00:17
[nodejs] How to catch unknown exception and shutdown the express instance on low level layer
var express = require('express');
var app = express();
var fs = require('fs');
app.get('/', function(req, res) {
res.send("hello");
// Notice: Make any uncaughtException happend on purpose
fs.readFile('no_such_file.txt', function(err, data) {
if (err) throw err;
console.log(data);
@akirattii
akirattii / cluster.js
Last active December 27, 2017 05:45
NodeJS: SharedMemory: Memory sharing on every worker of cluster
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
//
// ** SharedMemory which is shared among every worker:
//
// dont use `var`
SharedMemory = {
// shared data:
@akirattii
akirattii / AppError.js
Last active November 27, 2017 10:56
Example: How to make some error classes extended Error object.
/** application error base */
module.exports.AppError = class AppError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name
Error.captureStackTrace(this, this.constructor);
}
};
//