Skip to content

Instantly share code, notes, and snippets.

View akirattii's full-sized avatar

Akira TANAKA akirattii

View GitHub Profile
@akirattii
akirattii / example-read-write-mysql-blob.js
Created April 17, 2018 05:47
node-mysql example: How to write & read BLOB
/*
DDL:
CREATE TABLE `bindata` (
`id` INT NOT NULL AUTO_INCREMENT,
`data` BLOB,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
*/
const fs = require("fs");
@akirattii
akirattii / generate-entropy-on-mouse-moving.js
Created August 26, 2018 23:07
JS: How to generate a random entropy by mouse-moving on browser
// const entropy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
const entropy = [];
let captureStart = false;
/**
* Mouse Moving Entropy Generator on browser.
* Returns an entropy which is 16 bytes long array of unsigned char integer (0-255).
*/
$(document).on("mousemove", "html", function(e) {
const MAX_LEN = 16; // size of entropy's array
@akirattii
akirattii / check-ripple-address-seed.js
Created August 12, 2017 09:28
Ripple: How to check if a ripple address (also seed) is valid or not
const crypto = require('crypto');
const hashjs = require('hash.js');
const baseCodec = require('base-x');
const codec = baseCodec("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"); // for ripple
// npm install --save ripple-keypairs ripple-binary-codec ripple-hashes
const Keypairs = require('ripple-keypairs');
// const Binary = require('ripple-binary-codec');
const {
computeBinaryTransactionHash
} = require('ripple-hashes');
@akirattii
akirattii / app.js
Created February 23, 2014 02:32
Draggable & Movable popup example using pure javascript.
(function(){
var SCROLL_WIDTH = 24;
var btn_popup = document.getElementById("btn_popup");
var popup = document.getElementById("popup");
var popup_bar = document.getElementById("popup_bar");
var btn_close = document.getElementById("btn_close");
var smoke = document.getElementById("smoke");
@akirattii
akirattii / docker-mysql-slow-query-log.md
Last active July 14, 2023 22:12
memo: MySQL docker container settings for slow query log

Check running mysql container:

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
26137efa979f        mysql               "docker-entrypoint..."   8 months ago        Up 10 minutes       0.0.0.0:3306->3306/tcp   container-mysql

Check docker container mysql version:

$ sudo docker exec container-mysql mysqld --version`
mysqld  Ver 5.7.15 for Linux on x86_64 (MySQL Community Server (GPL))
@akirattii
akirattii / how-to-re-idex-auto-increment-id.sql
Last active July 14, 2023 06:37
[MySQL] How to re-index auto_increment id of a table to make use of resting sequence ids when it reached its max limit.
--
-- How to re-index the auto_increment id.
--
-- 0) Create an original table:
CREATE TABLE `hoge` (
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@akirattii
akirattii / background.js
Created December 2, 2016 03:45
Message passing of Chrome Extension example
/*****************************************************************
* onMessage from the extension or tab (a content script)
*****************************************************************/
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.cmd == "any command") {
sendResponse({ result: "any response from background" });
} else {
sendResponse({ result: "error", message: `Invalid 'cmd'` });
}
@akirattii
akirattii / example.js
Last active May 2, 2023 01:29
NodeJS: How to run a process (also a shell script etc) on background separated with the parent node process.
const spawn = require('child_process').spawn;
// a command you want to execute.
const command = "node cli/hoge.js --aaa --bbb=123";
const parts = command.split(" ");
const cmd = parts[0];
const args = parts.splice(1);
// a background process is running!
@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 / BarcodeScanner.js
Created January 31, 2019 01:39
HTML: Barcode Scanner on modern browser
/**
Barcode Scanner library
@author: Akira TANAKA <tanaka.akira.2006@gmail.com> (http://mint.pepper.jp)
@dependencies:
+ jquery
+ quagga (https://serratus.github.io/quaggaJS/)
## Usage example: