Skip to content

Instantly share code, notes, and snippets.

View valterbarros's full-sized avatar
👊
Code makes me happy

Valter Barros valterbarros

👊
Code makes me happy
View GitHub Profile
// setupFiles.ts
const { warn, log } = console;
const fnOverride = (callback: Function, ...msg: Array<[]>) => {
// if (!Object.getPrototypeOf(msg[0])) return callback(...msg);
const shouldIgnore = !!msg.find((m) => /Vue|mountOptions|FetchError/gi.test(String(m)));
if (!shouldIgnore) callback(...msg);
}
console.warn = (...args) => fnOverride(warn, ...args);
const sortSignaturesByDiagonalDistance = (a, b) => {
// await nextTick();
console.log('sort');
if (!a.signatureRef) return 0;
// Get the absolute position of the child relative to the parent
const { top: distanceFromTopA, left: distanceFromLeftA } = a.signatureRef.getBoundingClientRect();
const { top: distanceFromTopB, left: distanceFromLeftB } = b.signatureRef.getBoundingClientRect();
import { processCoordinateForBackend } from '..';
import { groupBy, merge } from 'lodash';
export const useMountPositionSignPayload = (archives, signatures) => {
if (signatures.value.length === 0) {
return archives.value.reduce((acc, curr) => {
const url = curr.links.rubrics;
acc[url] ||= { rubric: [] };
@valterbarros
valterbarros / get-page-size.js
Created September 22, 2023 18:16
get original pdf page size
/** @typedef {import("pdfjs-dist/lib/display/api.js").PDFDocumentProxy} PDFDocumentProxy */
/**
* @param {String} pdfUrl
* @param {PDFDocumentProxy} documentProxy - pdf.js document proxy object
*/
const handleGetPageSize = async ({ pdfUrl, documentProxy }) => {
const documentKey = archives.value.find((archive) => archive.documentPdfUrl === pdfUrl).key;
const pageBaseList = Array.from({ length: documentProxy.numPages });
const pageOriginalSizePromise = pageBaseList.map(async (_item, index) => {
import {
isTimeElapsedBeforeEndTime,
getDateTimeElapsedSincePageLoaded,
getDurationBetweenTimes,
} from '@/utils/date';
class myMap extends Map {
deleteByValue(valueToRemove) {
console.log('delete', this, valueToRemove)
this.forEach((value, key) => {
#!/bin/bash
git diff --name-only --staged > .vscode/staged && \
docker exec -i tavola bash -c "yarn eslint --fix $(cat .vscode/staged) | grep -E 'warning|error'; " && \
docker exec -i tavola yarn run lint:styles --fix $(cat .vscode/staged) && \
git add $(cat .vscode/staged)
import { query, emitEvent, setDaysToDate, getIsoDate } from '/static/assets/js/helpers.js';
class DateField extends HTMLElement {
constructor() {
super();
this.innerHTML = `
<style>
</style>
const sheet = new CSSStyleSheet();
// border border-[#B0B0B0] mt-1 rounded outline-none py-1 px-3 h-8
sheet.replace(`
*, ::after, ::before {
box-sizing: border-box;
}
:host {
max-width: 100%;
width: auto;
class PromiseResolver {
constructor() {
this.promise_ = new Promise((resolve, reject) => {
this.resolve_ = resolve;
this.reject_ = reject;
})
}
get promise() { return this.promise_ }
get resolve() { return this.resolve_ }
get reject() { return this.reject_ }
@valterbarros
valterbarros / active_admin.js
Created April 25, 2023 19:53
handle toggle enablement reactivity
// vendor/assets/javascripts/active_admin.js
//= require active_admin/toggles_change_handling