Skip to content

Instantly share code, notes, and snippets.

View LucaColonnello's full-sized avatar
👋
Come say hello on Twitter!

Luca Colonnello LucaColonnello

👋
Come say hello on Twitter!
View GitHub Profile
@LucaColonnello
LucaColonnello / memo.js
Last active March 17, 2022 10:27
Memo higher order function that works with any number and type of params.
View memo.js
// https://jsbin.com/fumuwiqegu/edit?js,console
/*
Create a memo higher order function that works with any number and type of params.
This solution uses hashmaps to achieve fast performance.
cache = Map {
[[ValueSymbol]] => value,
arg1 => Map {
@LucaColonnello
LucaColonnello / tinyTpl.js
Created May 25, 2021 09:24
Tiny template - using ES6 native tiny template implementation
View tinyTpl.js
const propSelector = (prop, ctx) => (typeof prop === 'function' ? prop(ctx) : (prop ?? ''));
const tinyTpl = (parts, ...props) =>
(ctx) => parts.map((v, i) => v.concat(propSelector(props[i], ctx))).join('');
const get = (prop) => (ctx) => ctx[prop];
const template = tinyTpl`hello ${get('name')} ${'yay'}!`
console.log(template({ name: 'Luca' }))
@LucaColonnello
LucaColonnello / vsc-settings.py
Created September 10, 2020 18:11 — forked from wonderbeyond/vsc-settings.py
script to export vsc settings
View vsc-settings.py
#!/usr/bin/env python3
from os import path
import tempfile
import subprocess
import datetime as dt
import click
@click.group()
def cli():
@LucaColonnello
LucaColonnello / example.js
Created September 10, 2020 09:33
Custom Express like middleware system
View example.js
const task = (data) => {
console.log('perform task with', data);
};
const middlewares = [];
middlewares.push((data, next) => {
console.log('add custom data', data);
next({ ...data, type: 'humanoid', power: 'pizza tasting' });
});
@LucaColonnello
LucaColonnello / index.html
Last active August 7, 2020 11:11
Redux like store with per slice subscription - using bit masks to propagate changes
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
View git_speed.md

How Fast if Git?

The web is full of benchmarks showing the supernatural speed of Git even with very big repositories, but unfortunately they use the wrong variable. Size is not important, but the number of files in the repository really is!

Why is that? Well, that's because Git works in a very different way compared to Synergy. You don't have to checkout a file in order to edit it; Git will do that for you automatically. But at what price?

The price is that for every Git operation that requires to know which files changed (git status, git commmit, etc etc) an lstat() call will be executed for every single file

Wow! So how does that perform on a fairly large repository? Let's find out! For this example I will use an example project, which has 19384 files in 1326 folders.

@LucaColonnello
LucaColonnello / .zshrc
Created February 1, 2020 14:40
Automatically switch Node version with nvm
View .zshrc
# Past at the end of .zshrc file
# https://stackoverflow.com/questions/23556330/run-nvm-use-automatically-every-time-theres-a-nvmrc-file-on-the-directory
# nvm
export NVM_DIR="/Users/lucacolonnello/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
autoload -U add-zsh-hook
load-nvmrc() {
@LucaColonnello
LucaColonnello / projects.graphql
Created January 10, 2020 12:26 — forked from dahlbyk/projects.graphql
GraphQL to fetch GitHub Projects+Columns+Cards with issue/PR detail for a specific repo.
View projects.graphql
{
search(type: REPOSITORY, query: "org:huboard-testing spooky-octo-pug", first: 1) {
edges {
node {
__typename
... on Repository {
owner {
id
}
name
@LucaColonnello
LucaColonnello / git-delete-local-tag.sh
Created November 12, 2018 13:48 — forked from canhnt/git-delete-local-tag.sh
Delete local tags that do not exist in remote
View git-delete-local-tag.sh
git fetch --prune origin "+refs/tags/*:refs/tags/*"
@LucaColonnello
LucaColonnello / babel-named-exports-plugin.js
Last active May 27, 2019 10:31
Babel named default export React plugin
View babel-named-exports-plugin.js
const itReturnsJSX = () => true;
const createNamedComponentVisitor = {
ArrowFunctionExpression(path) {
const { functionName, types: t } = this;
if (itReturnsJSX(path)) {
path.parentPath.replaceWithMultiple([
t.variableDeclaration('const', [
t.variableDeclarator(