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 / overengineered-rot13.js
Last active July 11, 2025 23:27
overengineered rot13
function rot13(message){
return [...message].map((c) => (n = c.charCodeAt(0),String.fromCharCode(n >= 65 && n <= 90?((n - 65 + 13) % 26) + 65:(n >= 97 && n <= 122 ? (n - 97 + 13) % 26 + 97 : n)))).join('');
}
console.log(rot13('§""§$§Ruby is cool!')); // "grfg"
console.log(((s)=>[...s].map(c =>(n=c.charCodeAt(0),String.fromCharCode(n^(32*(n>=97&&n<=122))))).join(''))('a4raf32aso"§%&/fu4f22'));
const fizzbuzz = n => (n % 3 ? '' : 'Fizz') + (n % 5 ? '' : 'Buzz') || n;
arr = [...Array(100).keys()]
.map((i) => ++i)
.map((i) => fizzbuzz(i));
console.log(arr);
@MarcelloDiSimone
MarcelloDiSimone / lowercase.js
Last active July 4, 2025 11:49
arithmetic to lowercase
const uppercase = s => [...s].map(c =>(n = c.charCodeAt(0), String.fromCharCode(n - 32 * (n >= 97 && n <= 122)))).join('');
console.log(uppercase('a4raf32aso"§%&/fu4f22')) // "A4RAF32ASO'§%&/FU4F22"
@MarcelloDiSimone
MarcelloDiSimone / DeepEqual.ts
Created December 14, 2022 09:56
Method to equal nested objects
const deepEqual = (objA: any, objB: any, map = new WeakMap()) => {
if (Object.is(objA, objB)) {
return true;
}
if (objA instanceof Date && objB instanceof Date) {
return objA.getTime() === objB.getTime();
}
if (objA instanceof RegExp && objB instanceof RegExp) {
@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);
@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 / 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 / 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 / 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');
};