Skip to content

Instantly share code, notes, and snippets.

View MarcelloDiSimone's full-sized avatar

Marcello di Simone MarcelloDiSimone

  • Lotto24.de
  • Hamburg Germany
View GitHub Profile
@MarcelloDiSimone
MarcelloDiSimone / WebComponentsExtend.html
Last active August 29, 2015 14:17
Web Component with extend and external API
<!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 / Prototyper.js
Last active December 11, 2015 11:19
A prototype inheritance helper
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 / Gruntfile.js
Last active December 17, 2015 15:28
Modular Grunt.js config
'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
Last active December 14, 2021 22:50
Display elements inside a specific position range
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
height: 100%;
width: 100%;
}
.wrapper {
@MarcelloDiSimone
MarcelloDiSimone / array_traverse.js
Last active May 8, 2022 21:26
Taverse an Array circularly in both direction by adding prev and next methods to the Array prototype
function ExtendedArray() {
let arr = [];
arr.push.apply(arr, arguments);
arr.pos = 0;
arr.prev = function () {
return this[this.pos = (this.pos || this.length)-1];
};
arr.next = function () {
return this[this.pos = (++this.pos % this.length)];
};
@MarcelloDiSimone
MarcelloDiSimone / circular_range.js
Last active May 8, 2022 21:34
Circular Array Range
function ExtendedArray() {
let arr = [];
arr.push.apply(arr, arguments);
/**
* Returns a circulating 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
@MarcelloDiSimone
MarcelloDiSimone / closure.js
Created June 20, 2022 08:45
Closure function boilerplate
/**
* @module namespace/Closure
* @requires module:namespace/Model
* @lends namespace
*/
(function (window) {
'use strict';
/**
* @namespace
@MarcelloDiSimone
MarcelloDiSimone / ExpiringDataCache.ts
Created December 14, 2022 09:54
A Cache for data with a configurable ttl, useful for filtering duplicate events
class ExpiringDataCache {
private _cache: any[] = [];
public expirationTime = 100;
set cache(value: any) {
this.expiredCache.push({value, ttl: Date.now() + this.expirationTime});
}
get cache() {
return this.expiredCache.map(item => item.value);