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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Router js</title> | |
| </head> | |
| <body> | |
| <h1 id="title"><?=!empty($_GET['page']) ? strip_tags($_GET['page']) : 'Home';?></h1> | |
| <ul> | |
| <li><a onclick="Router.go('/'); return false;" href="/">Home</a></li> |
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
| RewriteEngine On | |
| RewriteBase / | |
| RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
| RewriteRule ^(.*)$ http://%1/$1 [R=301,L] |
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
| <form enctype="multipart/form-data"> | |
| <input type="file" name="files" id="files" multiple onchange="File.set(this)"> | |
| </form> | |
| var File = (function(){ | |
| var files = [], | |
| set = function(obj){ | |
| for(var i in obj.files) | |
| { |
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
| $.fn.fData = function(_data) { | |
| var $form = this; | |
| if (!_data) { | |
| return $form.serializeArray().reduce(function(obj, field) { | |
| obj[field.name] = field.value; | |
| return obj; | |
| }, {}); | |
| } |
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
| const CustomPromise = function(callback) { | |
| const res = (fn, ...args) => fn && callOnce(fn, args); | |
| const rej = (fn, ...args) => fn && callOnce(fn, args); | |
| let callOnce = (fn, args) => { | |
| fn.apply(null, args); | |
| callOnce = () => { }; | |
| }; |
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
| // Promise | |
| const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
| // or pseudo Promise | |
| const delay = (time) => ({ | |
| then: (cb) => setTimeout(cb, time) | |
| }); | |
| // usage | |
| delay(5000).then(…); |
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
| const Stack = new function() { | |
| let data = []; | |
| this.pop = () => data.pop(); | |
| this.push = (el) => data.push(el); | |
| this.peek = () => data[data.length - 1]; | |
| }; | |
| Stack.push(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
| function Queue() { | |
| var collection = []; | |
| this.dequeue = () => collection.shift(); | |
| this.enqueue = (el) => collection.push(el); | |
| this.peek = () => collection[0]; | |
| this.size = () => collection.length; | |
| this.get = () => collection.slice(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
| var a = [...Array(5000000).keys()]; | |
| var chunk = (data, center) => { | |
| const chunks = []; | |
| while (data.length) | |
| chunks.push(data.splice(0, center)); | |
| return chunks; | |
| } | |
| var treeBuild = (array, tree = []) => { | |
| if (!array.length) return tree; |
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
| const data = [1, [2, [3], 4], 5]; | |
| const sum = (data) => { | |
| return data.reduce((res, el) => { | |
| if (el.length) { | |
| return res + sum(el); | |
| } | |
| return res + el; | |
| }, 0); | |
| } |