Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
ricardodantas / footer-always-at-the-bottom.css
Created March 12, 2021 09:05
Keep footer always at the bottom of the page using only flex (no position absolute).
@ricardodantas
ricardodantas / nvm.sh
Last active December 11, 2020 13:56
Changing node versions automatically per directory
# NVM Changing node versions automatically per directory - place this after nvm initialization on .zshrc file
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
@ricardodantas
ricardodantas / breadcrumb-with-arrows.css
Created October 22, 2020 08:05
CSS/HTML Breadcrumb with arrows
/**
* Preview at: https://codepen.io/iamglynnsmith/pen/BRGjgW
**/
$base: 38px;
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {
height: 100%;
background-color: #333;
@ricardodantas
ricardodantas / vertical-align-center.html
Created October 22, 2020 08:02
CSS/HTML Vertical Centering with flex
.Aligner {
display: flex;
align-items: center;
justify-content: center;
}
.Aligner-item {
max-width: 50%;
}
@ricardodantas
ricardodantas / FluxDiagramMakefile
Created August 19, 2020 10:32
Create flux diagram
build:
@for f in *.diag; do \
seqdiag -T svg $$f; \
base=$$(basename $$f .diag); \
cairosvg -o $${base}.pdf $${base}.svg; \
echo "$$f --> $$base.pdf"; \
done
clean:
rm -rf *.pdf *.svg
@ricardodantas
ricardodantas / back-end.js
Created June 22, 2020 08:31
Web Push Notifications
const subscriptions = {};
var crypto = require("crypto");
const webpush = require("web-push");
const vapidKeys = {
privateKey: process.env.WEB_PUSH_NOTIFICATIONS_PRIVATE_KEY,
publicKey: process.env.WEB_PUSH_NOTIFICATIONS_PUBLIC_KEY
};
webpush.setVapidDetails("mailto:[email protected]", vapidKeys.publicKey, vapidKeys.privateKey);
@ricardodantas
ricardodantas / regex-string-to-valid-utf8.js
Created April 8, 2020 06:27
Convert string to a valid utf8 string (remove emojis)
const mystringVar = "abcde \x31\xE2\x83\xA3"
myStringVar.replace(/[^\x20-\x7E]+/g, "")
@ricardodantas
ricardodantas / postgresql_uuid.sql
Last active February 10, 2020 13:24
Using uuid postgresql
-- https://stackoverflow.com/questions/20342717/postgresql-change-column-type-from-int-to-uuid
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
ALTER TABLE tableA ALTER COLUMN colA SET DATA TYPE UUID USING (uuid_generate_v4());
@ricardodantas
ricardodantas / convertArrayToObject.js
Created September 24, 2019 07:10
Converting an Array of Objects to an Object
const arrayToObject = (array, keyField) =>
array.reduce((obj, item) => {
return {...obj, [item[keyField]]: item}
}, {});
const peopleObject = arrayToObject(peopleArray, "id");
console.log(peopleObject);
@ricardodantas
ricardodantas / remove_duplicated_objects_from_array.js
Last active July 16, 2019 10:05
Removing duplicates in an Array of Objects in JS with Sets
const addresses = [...];
const uniqueAddresses = Array.from(new Set(addresses.map(a => a.id)))
.map(id => {
return addresses.find(a => a.id === id)
});