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
| function getRndInteger(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1) ) + min; | |
| } |
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
| function myFunction(arr) { | |
| arr.sort(function(a, b){ | |
| var x = a.type.toLowerCase(); | |
| var y = b.type.toLowerCase(); | |
| if (x < y) {return -1;} | |
| if (x > y) {return 1;} | |
| return 0; | |
| }); | |
| } |
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
| if (!String.prototype.trim) { | |
| String.prototype.trim = function () { | |
| return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | |
| }; | |
| } | |
| var str = " Hello World! "; | |
| alert(str.trim()); |
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 url = "https://developer.mozilla.org/en-US/Web/JavaScript"; | |
| var parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url); | |
| var [, protocol, fullhost, fullpath] = parsedURL; | |
| console.log(protocol); // выведет "https" |
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
| В js есть 3 способа назначить обработчика события: | |
| 1. Через HTML-атрибут, например, onclick | |
| 2. С помощью DOM объекта. document.getElementById('el').onclick = function() {...} | |
| Таким способом можно назначить только один обработчик. Отработает самый нижний по коду обработчик | |
| 3. Через метод addEventListener | |
| Данный метод может принимать в качестве третьего аргумента true/false или объект: | |
| { | |
| capture: false, | |
| once: false, |
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
| // package's composer.json file | |
| { | |
| "name": "vendor-name/package-name", | |
| "type": "library", | |
| "autoload": { | |
| "psr-4": { | |
| "namespace\\": "src/" | |
| } | |
| }, |
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
| git diff --color filename |
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
| Find out folder size: | |
| `du -sh file_path` | |
| du (disc usage) command estimates file_path space usage | |
| -s, --summarize | |
| display only a total for each argument | |
| -h, --human-readable | |
| print sizes in human readable format (e.g., 1K 234M 2G) |
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
| <?php | |
| setlocale(LC_ALL, 'ru_RU.CP1251', 'rus_RUS.CP1251', 'Russian_Russia.1251'); | |
| sort($example, SORT_LOCALE_STRING); |
NewerOlder