View utf8-regex.js
/** | |
* Encodes multi-byte Unicode string into utf-8 multiple single-byte characters | |
* (BMP / basic multilingual plane only). | |
* | |
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars. | |
* | |
* Can be achieved in JavaScript by unescape(encodeURIComponent(str)), | |
* but this approach may be useful in other languages. | |
* | |
* @param {string} strUni Unicode string to be encoded as UTF-8. |
View WebComponentsExtend.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.5.5/webcomponents-lite.min.js"></script> | |
<link rel="import" href="my-component.html" /> | |
<link rel="import" href="my-component-input.html" /> | |
<link rel="import" href="my-component-extend.html" /> | |
</head> |
View circular_range.js
const arr = [0,1,2,3,4,5,6,7,8,9]; | |
/** | |
* Returns a range of an Array | |
* @param index {Number} starting position | |
* @param size {Number} size of the range | |
* @param [reverse] {Boolean} reverse the range lookup | |
* @return {Array} The returned array length will not exceed the length of the original array if size > arr.length | |
**/ | |
Array.prototype.range = function(index, size, reverse){ | |
// make a copy |
View Gruntfile.js
'use strict'; | |
var path = require('path'), | |
fs = require('fs'), | |
matchdep = require('matchdep'); | |
module.exports = function (grunt) { | |
var gruntConfig = { | |
pgk: grunt.file.readJSON('package.json'); | |
}; |
View gist:5532665
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
html, | |
body { | |
height: 100%; | |
width: 100%; | |
} | |
.wrapper { |
View array_traverse.js
Array.prototype.pos = 0; | |
Array.prototype.next = function () { | |
return this[this.pos = (++this.pos % this.length)]; | |
}; | |
Array.prototype.prev = function () { | |
return this[this.pos = (this.pos || this.length)-1]; | |
}; | |
var a = [1, 2, 3, 4, 5]; |
View template.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Basic templating</title> | |
</head> | |
<body> | |
<div id="tweet-list"> | |
</div> |
View Prototyper.js
Prototyper = {}; | |
Prototyper.create = function (base) { | |
var empty = function () {}; | |
empty.prototype = base; | |
return new empty(); | |
}; | |
Prototyper.xtends = function (parent, instance) { | |
instance.prototype = this.create(parent.prototype); | |
instance.prototype.constructor = instance; | |
instance.prototype.__super__ = parent; |