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
| /** | |
| * Common regular expressions | |
| */ | |
| var rules = { | |
| alphabet: /^[a-zA-Z]+$/, | |
| numeric: /^[0-9]+$/, | |
| alphanumeric: /^[0-9a-zA-Z]+$/, | |
| alphadash: /^[0-9a-zA-Z_]+$/, | |
| ascii: /[\x00-\xff]/, | |
| nonascii: /[^\x00-\xff]/ |
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
| /** | |
| * Convert mouse events into touch events. | |
| * From: http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript/ | |
| */ | |
| function touchHandler(event) { | |
| var touch = event.changedTouches[0]; | |
| var simulatedEvent = document.createEvent("MouseEvent"); | |
| simulatedEvent.initMouseEvent({ | |
| touchstart: "mousedown", |
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
| #!/usr/bin/env bash | |
| # The "Common Name (CN)" can be "example.com" or "*.example.com www.example.com" | |
| # This command should be executed in non-root mode | |
| domain="$1" | |
| if [ -z "$domain" ]; then | |
| echo "need domain parameter" | |
| exit 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
| async function retry(fn, times = 0, ...args) { | |
| if (typeof times !== 'number') throw new Error('times must be a number') | |
| if (times < 0) throw new Error('times must not be less than 0') | |
| const totalTimes = times + 1 | |
| let result | |
| let firstError | |
| let i = 0 | |
| for (; i < totalTimes; i++) { | |
| try { | |
| result = await fn(...args) |
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
| /** | |
| * Get the current active element safely. | |
| * Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js | |
| */ | |
| function safeActiveElement(doc) { | |
| doc = doc || document; | |
| var activeElement; | |
| // Support: IE 9 only | |
| // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe> |
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
| /** | |
| * Description: Count a string (mixing English and Chinese characters) length. | |
| * A basic and rough function. | |
| * | |
| * Performance: | |
| * Multiple methods performance test on http://jsperf.com/count-string-length. | |
| * You can see that using regexp to check range is very slow from the above test page. | |
| */ | |
| function strLen(str) { | |
| var count = 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
| /** | |
| * Stop propagation behavior for scroll of the element but body. | |
| * Compatibility: IE9+ | |
| * Ref: | |
| * - http://stackoverflow.com/questions/5802467/prevent-scrolling-of-parent-element#answer-16324762 | |
| * - https://developer.mozilla.org/en-US/docs/Web/Events/wheel | |
| */ | |
| ;(function ($) { | |
| $.fn.scrollable = function () { | |
| this.on('wheel', function (event) { |
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 request = require('request'); | |
| var unzip = require('unzip'); | |
| var csv2 = require('csv2'); | |
| request.get('http://s3.amazonaws.com/alexa-static/top-1m.csv.zip') | |
| .pipe(unzip.Parse()) | |
| .on('entry', function (entry) { | |
| entry.pipe(csv2()).on('data', console.log); | |
| }) | |
| ; |
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
| class Perf { | |
| constructor () { | |
| this.init() | |
| this.phases = [] | |
| } | |
| init () { | |
| const now = Date.now() | |
| this.start = now | |
| this.lastTime = now |
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 promisify(func) { | |
| return (...args) => { | |
| const args1 = args.slice(0, args.length); | |
| return new Promise((resolve, reject) => { | |
| const callback = (err, ...rest) => { | |
| if (err) { | |
| reject(err); | |
| } else { | |
| resolve(...rest); | |
| } |
NewerOlder