Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcello di Simone MarcelloDiSimone

View GitHub Profile
@MarcelloDiSimone
MarcelloDiSimone / utf8-regex.js
Last active Jul 5, 2018 — forked from chrisveness/utf8-regex.js
Utf8 string encode/decode using regular expressions
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.
@MarcelloDiSimone
MarcelloDiSimone / WebComponentsExtend.html
Last active Aug 29, 2015
Web Component with extend and external API
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>
@MarcelloDiSimone
MarcelloDiSimone / circular_range.js
Last active Nov 23, 2020
Circular Array Range
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
@MarcelloDiSimone
MarcelloDiSimone / Gruntfile.js
Last active Dec 17, 2015
Modular Grunt.js config
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');
};
@MarcelloDiSimone
MarcelloDiSimone / gist:5532665
Created May 7, 2013
Display elements inside a specific position range
View gist:5532665
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
height: 100%;
width: 100%;
}
.wrapper {
@MarcelloDiSimone
MarcelloDiSimone / array_traverse.js
Last active Dec 12, 2015
Taverse an Array circularly in both direction by adding prev and next methods to the Array prototype
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];
@MarcelloDiSimone
MarcelloDiSimone / template.html
Last active Dec 11, 2015
A super basic template engine. This example builds a twitter feed list using a template string with placeholders.
View template.html
<!DOCTYPE html>
<html>
<head>
<title>Basic templating</title>
</head>
<body>
<div id="tweet-list">
</div>
@MarcelloDiSimone
MarcelloDiSimone / Prototyper.js
Last active Dec 11, 2015
A prototype inheritance helper
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;
You can’t perform that action at this time.