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
| <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script> | |
| <button id="btnShow">Show</button> | |
| <button id="btnHide">Hide</button> | |
| <div class="container"> | |
| <div id="foo"> | |
| I am #foo | |
| </div> | |
| </div> | |
| <div id="console"> |
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
| # create user | |
| adduser gitrepo | |
| usermod -aG gitrepo akirattii | |
| # create remote git repos | |
| su - gitrepo | |
| mkdir hoge.git | |
| cd hoge.git # pwd: `foo_server:/home/gitrepo/hoge.git/` | |
| git --bare init --shared | |
| git update-server-info |
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
| ## Install browserify: | |
| $ npm install -g browserify | |
| # Install uglify-js: | |
| ### First remove already installed one: | |
| $ npm remove uglify-js -g | |
| ### Install the ES2015 compatible version from 'harmony' branch: | |
| $ npm install -g https://github.com/mishoo/UglifyJS2.git#harmony | |
| # Try uglify of ES2015 code: |
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
| // Load elements having `id` attr on `document` as global variables (in directly under `window`) | |
| // They are loaded as jQuery object named as camelcase with prefix "$". | |
| // eg. An element is loaded as a variable named like this: id="ipt-name" -> `$iptName` | |
| exports.loadElements = function() { | |
| console.log(`[${moduleName}] auto-loading elements as jQuery elements...`); | |
| check(); | |
| let els = document.getElementsByTagName("*"); | |
| let el, camelId, varname; |
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
| // fire `hoge` event. | |
| window.dispatchEvent(new Event('hoge')); | |
| window.addEventListener('hoge', function(e) { | |
| // callbacked on `hoge` event fired. | |
| console.log('"hoge" event fired.'); | |
| }); |
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
| var foo, baz; | |
| notEmpty({ foo, baz }); // Error "'foo', 'baz', required" thrown | |
| function notEmpty(obj) { | |
| let names = ""; | |
| for (let key in obj) | |
| if (!obj[key]) names += `'${key}', `; | |
| if (names) | |
| throw Error(`${names}required`); |
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
| let url = "http://example.host/"; // target to post form | |
| let params = [ | |
| { name: "a", value: encodeURIComponent("1") }, | |
| { name: "b", value: encodeURIComponent("2") }, | |
| ]; | |
| crossDomainPost(url, params); | |
| function crossDomainPost(url, params) { |
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
| // Headers you want to modify. | |
| let modifyingHeaders = { | |
| "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.100 Safari/537.36", | |
| "Origin": "http://example", | |
| "Referer": "http://example/foo/bar", | |
| "Cookie": 'key1="value1"; key2="value2";', | |
| }; | |
| let requestFilter = { | |
| // urls: ["<all_urls>"] |
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
| <button>test</button> | |
| <div id="hoge"></div> | |
| <script type="text/javascript"> | |
| var hoge = document.querySelector("#hoge"); | |
| var obj = { | |
| set name(val) { | |
| obj._name = val; | |
| hoge.innerText = val; // change `hoge` pane's text | |
| }, |
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
| let items = [ | |
| {"id": "aaa"}, | |
| {"id": "bbb"}, | |
| {"id": "ccc"}, | |
| {"id": "bbb"}, | |
| ]; | |
| let idx; | |
| idx = items.findIndex(x => x.id == "aaa"); // idx => 0 | |
| idx = items.findIndex(x => x.id == "bbb"); // idx => 1 // returns idx of "bbb" first found |