Skip to content

Instantly share code, notes, and snippets.

Marcello di Simone MarcelloDiSimone

Block or report user

Report or block MarcelloDiSimone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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;
@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 / 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 / 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 / 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 / circular_range.js
Last active Aug 13, 2016
Circular Array Range
View circular_range.js
var arr = [0,1,2,3,4,5,6,7,8,9];
/**
* Returns a circular range of an Array
* @param index {Number} starting position
* @param size {Number} size of the range
* @param [position] {Number} position of the range, negative values will return a range before the index
* @return {Array}
**/
Array.prototype.range = function(index, size, position){
@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 / 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.
You can’t perform that action at this time.