Skip to content

Instantly share code, notes, and snippets.

View andresgutgon's full-sized avatar
:octocat:
Coding things...

Andrés andresgutgon

:octocat:
Coding things...
  • Barcelona
View GitHub Profile
@andresgutgon
andresgutgon / ListDbSchema.php
Last active October 1, 2023 18:30
List database schema
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ListDbSchema extends Command
{
// db/schema/auth.ts
import {
int,
timestamp,
mysqlTable,
primaryKey,
varchar,
text
} from "drizzle-orm/mysql-core"
import type { AdapterAccount } from "@auth/core/adapters"
@andresgutgon
andresgutgon / api.ts
Last active July 15, 2023 15:53
API wrapper over window.fetch
import { compact } from './utilities'
import { AnyObject, HttpMethod, ApiDataConfig, ApiError, ApiErrorBody } from './types'
type ContentTypeHeader = 'json' | 'urlencoded'
type AllowedHeaders = {
contentType?: ContentTypeHeader
}
type BaseConfig = { params?: AnyObject; headers?: AllowedHeaders }
type VerbArgs<T extends HttpMethod> = T extends 'GET'
? BaseConfig : T extends 'DELETE' ? BaseConfig
@andresgutgon
andresgutgon / Error
Last active June 4, 2023 20:36
SST using aws SSO
// Running
AWS_PROFILE=<MY_USERNAME_PROFILE> pnpm sst dev
// I get this error
Errors
Site UPDATE_FAILED
stack: User: arn:aws:sts::<AWS_ACOUNT_ID>:assumed-role/AWSReservedSSO_sst-stack_<SOME_HASH>/<MY_USERNAME_PROFILE>
is not authorized to perform: cloudformation:DescribeStacks
on resource: arn:aws:cloudformation:us-east-1:<AWS_ACOUNT_ID>:stack/<MY_USERNAME_PROFILE>-local-app-Site/*
because no identity-based policy allows the cloudformation:DescribeStacks action
@andresgutgon
andresgutgon / meter.ts
Last active March 14, 2022 14:59
Create File in Disk and validate size with `Meter`
import type { TransformCallback } from "stream"
import { Transform } from "stream"
export class Meter extends Transform {
public bytes: number
constructor(
public field: string,
public maxBytes: number
) {
@andresgutgon
andresgutgon / createfileUploadHandler-api.ts
Last active February 16, 2022 16:39
API of Remix createfileUploadHandler to handle form errors
// Documentation:
// https://remix.run/docs/en/v1/api/remix#unstable_createfileuploadhandler
const uploadHandler = unstable_createFileUploadHandler({
maxFileSize: 5_000_000,
file: ({ filename }) => filename
})
const fakeDb = createFakeDb()
export const action: ActionFunction = async ({ request }) => {
const formData = await unstable_parseMultipartFormData(
@andresgutgon
andresgutgon / docker_inspect_volume.sh
Last active November 12, 2021 12:06
Docker inspect Volume bash function
# Docker Inspect Volume
# ::::::::::::::::::::::::
# Found here
# https://www.freshblurbs.com/blog/2017/04/16/inspect-docker-volumes-on-mac.html
docker_inspect_volume () {
DOCKER_VOLUME_OUTPUT=$(docker volume inspect $1);
DOCKER_VOLUME_OUTPUT=$(echo "$DOCKER_VOLUME_OUTPUT" | grep -E '"Mountpoint": "[^,]*')
DOCKER_VOLUME_DIR=$(echo "$DOCKER_VOLUME_OUTPUT" | sed -r 's/("Mountpoint"\: ")(.*)(",)/\/docker\2/')
docker run --rm -it -w $DOCKER_VOLUME_DIR -v /:/docker alpine:edge
}
import { MeasuringSystem, MeasuringUnit, MeasuringUnitKind } from "db"
const COMMON = { unitless: { count: MeasuringUnit.count } }
type UnitGroup = Record<MeasuringUnitKind, Record<string, MeasuringUnit>>
type SystemUnits = Record<MeasuringSystem, UnitGroup>
export const units: SystemUnits = {
[MeasuringSystem.METRIC]: {
...COMMON,
@andresgutgon
andresgutgon / AdminCheck.tsx
Created August 2, 2021 08:02
Blitz.js Admin is ROLE 'SUPERADMIN'
import { Suspense, ReactNode } from 'react'
import { Routes, RedirectError, useSession } from "blitz"
import cn from "classnames"
import Layout from "app/core/layouts/Layout"
import type { LayoutProps } from "app/core/layouts/Layout"
const SUPERADMIN_ROLE = 'SUPERADMIN' as never
type CheckIsAdminProps = { children: ReactNode }
version: "3.3"
services:
traefik:
image: traefik:$TRAEFIK_VERSION
command:
- --log.level=DEBUG # DEBUG, INFO, WARN
- --global.sendAnonymousUsage=false
- --api.insecure