This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # nginx conf file example in the case of using: | |
| # - nodejs app server | |
| # - letsencrypt for SSL | |
| # version: nginx/1.10.3 | |
| # /etc/nginx/conf.d/example.com.conf | |
| # Permits for tester to access even if web server is under maintenance: | |
| geo $allow_ip_flag { | |
| default 0; # Not Allowed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # BACKUP | |
| ## Backup all tables of a specific database: | |
| mysqldump -h {HOST} -P{PORT} -u{USER} -p{DB} > {DB}.dump.sql | |
| ## Backup a specific table: | |
| mysqldump -h {HOST} -P{PORT} -u{USER} -p{DB} -t -c --skip-extended-insert {TABLE} > {DB}.{TABLE}.dump.sql | |
| # RESTORE | |
| ## Restore all tables of a specific database from backuped file: | |
| mysql -h {HOST} -P{PORT} -u{USER} -p{DB} < {DB}.dump.sql | |
| ## Restore a specific table from backuped file: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- MySQL | |
| -- 大文字と小文字を区別しない検索: | |
| select * from mytable where name like 'a'; -- <= "a", "A" どちらにもヒットする | |
| -- 大文字と小文字を区別する検索: | |
| select * from mytable where name like BINARY 'A'; -- <= likeの後に `BINARY` をつけることで "A" にだけヒットする |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Executes async functions in order using pure js | |
| /** | |
| * Loop async func in order | |
| * @param {Array} - array each object has below properties: | |
| * - fn: {Function} - function to loop | |
| * - param: {Object} - parameter to pass the function | |
| * @param {Function} - error-first style callback returns below params as argument: | |
| * - errs: array of error | |
| * - results: array of result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Shuffles array | |
| * @param {Array} - array | |
| */ | |
| function shuffle(a) { | |
| let len = a.length; | |
| for (let i = len; i; i--) { | |
| let j = Math.floor(Math.random() * i); | |
| [a[i - 1], a[j]] = [a[j], a[i - 1]]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TODO: Change your username/password: | |
| const TW_USER = "<YOUR_USERNAME>"; | |
| const TW_PASS = "<YOUR_PASSWORD>"; | |
| var Nightmare = require('nightmare'); | |
| var nightmare = Nightmare({ show: true }); | |
| nightmare | |
| .goto('https://twitter.com/login/') | |
| .insert('.js-username-field.email-input.js-initial-focus[name="session[username_or_email]"]', TW_USER) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| $ node member-page-scraping.js <loginId> <password> | |
| */ | |
| var request = require("request"); | |
| request = request.defaults({ jar: true }); | |
| var encoding = require('encoding-japanese'); | |
| const cheerio = require("cheerio"); | |
| const Step = require("step"); | |
| var config = require("config"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Read and write every line of input.txt into output.txt | |
| */ | |
| const fs = require("fs"); | |
| var writeStream = fs.createWriteStream("output.txt"); | |
| var lineReader = require('readline').createInterface({ | |
| input: require('fs').createReadStream("input.txt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| NOTE: deasync can not use on browser. | |
| */ | |
| var deasync = require('deasync'); | |
| // any async function error-first callback styled | |
| function asyncFn(p, cb) { | |
| let res = "hello " + p; | |
| let err = null; | |
| return cb && cb(err, res); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // npm install encoding-japanese | |
| const encoding = require('encoding-japanese'); | |
| urlEncode("餅", "EUCJP"); // "%CC%DF" | |
| function urlEncode(str, charset) { | |
| let eucArray = encoding.convert(Encoding.stringToCode(str), charset); | |
| return encoding.urlEncode(eucArray); | |
| } |