Skip to content

Instantly share code, notes, and snippets.

View egm0121's full-sized avatar
⚛️
https://www.generationatomic.org/why-nuclear/

Giulio Dellorbo egm0121

⚛️
https://www.generationatomic.org/why-nuclear/
View GitHub Profile
@egm0121
egm0121 / spread_vs_objectAssign.js
Created December 20, 2023 16:11
Performance Comparison of reduce+spread vs reduce+Object.Assign
const arrOfMaps = new Array(40000).fill(0).map((k,i) => {
return { [i]:`testdsfsdfdsfsdfsdfsdf${i}`};
})
console.time('functional')
const finalMap = arrOfMaps.reduce((acc, current) => ({ ...acc, ...current }), {});
console.log('finalMap keys', Object.keys(finalMap).length);
console.timeEnd('functional')
console.time('object assign')
@egm0121
egm0121 / content-script.js
Created August 12, 2021 15:44
linkify-content-script for chrome extensions: wraps a page phone numbers into clickable links ( uses XPATH and event delegation for performance)
var linkifyExtension = (function(){
var LINKIFY_EXTENSION_CLASS = 'linkify-phone-match';
var EXCLUDE_NODES = ['script', 'style', 'input', 'select', 'textarea', 'button', 'a', 'code', 'head', 'noscript'];
var PHONE_MATCHERS = {
US : {
reg : /(^|\s)((\+1\d{10})|((\+1[ \.])?\(?\d{3}\)?[ \-\.\/]{1,3}\d{3}[ \-\.]{1,2}\d{4}))(\s|$)|(^|\s)\+(?:[0-9] ?){6,14}[0-9](\s|$)/gm,
match : 2
} ,
PERMISSIVE : {
reg : /(^|\s)(?:\+?(\d{1,3}))?([-. (]*(\d{3})[-. )]*)?((\d{3})[-. ]*(\d{2,4})(?:[-.x ]*(\d+))?)(\s|$)/gm,
@egm0121
egm0121 / deflatten.js
Last active January 15, 2021 14:57
pipe in a new line delimitated log file serialized using flatten -> get json serialized log file (circular refs discarded)
#!/usr/bin/env node
const Flatted=function(n){"use strict";
/*! (c) 2020 Andrea Giammarchi */var t=JSON.parse,r=JSON.stringify,e=Object.keys,a=String,u="string",f={},i="object",c=function(n,t){return t},l=function(n){return n instanceof a?a(n):n},o=function(n,t){return typeof t===u?new a(t):t},s=function(n,t,r){var e=a(t.push(r)-1);return n.set(r,e),e};return n.parse=function(n,r){var u=t(n,o).map(l),s=u[0],p=r||c,v=typeof s===i&&s?function n(t,r,u,c){for(var l=[],o=e(u),s=o.length,p=0;p<s;p++){var v=o[p],y=u[v];if(y instanceof a){var g=t[y];typeof g!==i||r.has(g)?u[v]=c.call(u,v,g):(r.add(g),u[v]=f,l.push({k:v,a:[t,r,g,c]}))}else u[v]!==f&&(u[v]=c.call(u,v,y))}for(var h=l.length,d=0;d<h;d++){var w=l[d],O=w.k,S=w.a;u[O]=c.call(u,O,n.apply(null,S))}return u}(u,new Set,s,p):s;return p.call({"":v},"",v)},n.stringify=function(n,t,e){for(var a=t&&typeof t===i?function(n,r){return""===n||-1<t.indexOf(n)?r:void 0}:t||c,f=new Map,l=[],o=[],p=+s(f,l,a.call({"":n},"",n)),v=!p;p<l.length;)v=!0,o[p]=r(l[p++],y,e);return"
@egm0121
egm0121 / middleware.js
Last active February 12, 2021 14:40
simple middleware with sync && async functions support
const middy = (middList) => {
return (event) => {
let middStack = [...middList];
let lastRetValue;
const next = () => {
const curr = middStack.shift();
if (curr) {
const retVal = curr(event, next);
lastRetValue = retVal;
if (retVal instanceof Promise && middStack.length){
@egm0121
egm0121 / gist:910575b3760766a0c2e606f2a48c204c
Created August 9, 2018 13:07
pen for draft.js handle paste html with filtering/ validation
https://codepen.io/anon/pen/yqQOxv?editors=0010
@egm0121
egm0121 / config.json
Last active November 21, 2019 15:41
VSCode config
// Place your settings in this file to overwrite the default settings
{
"editor.fontSize": 13,
"editor.roundedSelection": false,
"typescript.check.npmIsInstalled": false,
"window.restoreWindows": "all",
"workbench.colorTheme": "Nord",
"editor.tabSize": 2,
"window.zoomLevel": 0.75,
"javascript.updateImportsOnFileMove.enabled": "always",
@egm0121
egm0121 / .eslintrc.json
Created April 27, 2017 08:33
eslint rules extending reccomanded
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
@egm0121
egm0121 / getWatchers.js
Created March 10, 2017 13:14
angular.js Dom based active watchers counter
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
var scopeArr = [];
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
@egm0121
egm0121 / style.less
Created January 12, 2016 14:52
atom custom styles
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/
@egm0121
egm0121 / gist:d8a48d137b215b11b74f
Created May 7, 2014 08:28
hide console.log in prod
!function(a,b){var c,d={},e=function(){},f=function(){d.history=d.history||[],d.history.push(arguments),this.console&&original.log(Array.prototype.slice.call(arguments))},g=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],h=g.length,i=window.console=window.console||{};try{for(;h--;)c=g[h],i[c]="log"==c?f:e}catch(j){}b._unlockConsole=function(){i.log=a,d.history.map(function(a){i.log.apply(i,Array.prototype.slice.call(a))})}}(null!=console&&"object"==typeof console&&"log"in console?console.log:function(){},this);