Skip to content

Instantly share code, notes, and snippets.

View eoguvo's full-sized avatar
🔥
A todo vapor

Gustavo Henrique eoguvo

🔥
A todo vapor
  • Itu, São Paulo, Brazil
View GitHub Profile
import { isNumeric } from "@core/Utils/index";
const DateDuration = function (milliseconds?: number, hasSeconds = true, hasMinutes = true): string {
if (!milliseconds) {
return "0s";
}
if (milliseconds <= 0 || milliseconds === Infinity) {
return "0s";
}
@eoguvo
eoguvo / getDateRangeFromPresets.ts
Last active August 9, 2024 18:02
transform preset date ranges (the morning of yesterday) into timestamp dates
import { subDays, format, parse, startOfWeek, addWeeks, startOfMonth, subMonths, subWeeks, addMonths, addDays } from "date-fns";
import { ReportFields } from "../WindowDeviceReport.asset";
const getDateRangeFromPresets = function ({ range, timeRange, startTime: customStartTime, endTime: customEndTime, customRange }: ReportFields) {
const rangeToOffset = {
today: [new Date(), new Date()],
yesterday: [subDays(new Date(), 1), subDays(new Date(), 1)],
two_days_ago: [subDays(new Date(), 2), subDays(new Date(), 2)],
three_days_ago: [subDays(new Date(), 3), subDays(new Date(), 3)],
import jsPDF from "jspdf";
import html2canvas from "html2canvas";
import { ServicePdfComponentsImage } from "@core/Services/Pdf/Components";
type ImagesStructure = {
id: string;
positions: [
{
page: number;
=============== CNUCASH ===================
CREATE TABLE TRANSACTION (
ID VARCHAR(256) NOT NULL,
NUM VARCHAR(256),
DESCRIPTION VARCHAR(512),
DATE CHAR(10)
)
CREATE TABLE SPLIT (
ID VARCHAR(256) NOT NULL,
@eoguvo
eoguvo / parseFirebaseSnapshot.ts
Last active June 5, 2024 14:38
transform the crazy firebase output in a generic type, the way it should be since the init
import { DocumentData, DocumentSnapshot, QuerySnapshot } from "firebase-admin/firestore";
type withDocId<T> = T & { docId: string }
type SingleDocument = DocumentSnapshot<DocumentData>;
type QueryDocuments = QuerySnapshot<DocumentData>;
type Snapshot = SingleDocument | QueryDocuments;
type SnapshotNullable = Snapshot | null;
const checkSingle = (snapshot: Snapshot): snapshot is SingleDocument => {
@eoguvo
eoguvo / rastreio.http
Created May 9, 2024 18:05
api to track a package without any pricing or validation
POST https://api.melhorrastreio.com.br/graphql HTTP/1.1
Content-Type: application/json
{
"query": "mutation searchParcel ($tracker: TrackerSearchInput!) { result: searchParcel (tracker: $tracker) { id createdAt updatedAt lastStatus lastSyncTracker trackingEvents { createdAt translatedEventId originalTitle to from location { zipcode address locality number complement city state country } additionalInfo } } }",
"variables": {
"tracker": {
"trackingCode": "CODIGO_CORREIOS",
"type": "correios"
}
// @computer_modules
import { useSystem, useSession } from "@/Stores/index.tsx";
import { MenuLink, MenuLogo, MenuNotifications, MenuProfile, MenuSearch } from "@/Modules/Computer/Components/index.tsx";
const MenuLeft = function() {
const { user } = useSession();
const { Translation } = useSystem();
return (
<div className="flex justify-center items-center gap-4">
const userSnapshot = useRef<Unsubscribe|null>(null);
const [isFirstUser, setIsFirstUser] = useState(false);
const [firstUserFinded, setFirstUserFinded] = useState(false);
useEffect(function () {
if (userSnapshot.current && firstUserFinded) {
userSnapshot.current();
// history
alert: history.alrm || history.alrt || "no_alert",
event: String(history.evt || history.res || "no_event"),
acceleration,
rpm,
date,
driver,
engine,
locked,
moving,
{
by: "",
active: true,
static: false,
name: "",
description: "",
permissions: {
// Permissões sobre nodes abaixo
// (passível de ser removido, feito agora por `type` na node)
clients: { read: true, write: true, delete: true },