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
Chrome >= 60
String.prototype.hashCode = function() {
var hash = 0,
i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
import { screen } from "@testing-library/vue";
import { createTestComponentRenderer } from "~~core/test";
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
import { routerKey, createRouter, createWebHistory } from '#vue-router';
import { XButton } from "~~base-ui";
let router: ReturnType<typeof createRouter>;
beforeEach(async () => {
router = createRouter({
// 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>