Skip to content

Instantly share code, notes, and snippets.

View lopezjurip's full-sized avatar
🎯
Focusing

Patricio López Juri lopezjurip

🎯
Focusing
View GitHub Profile
@lopezjurip
lopezjurip / example.ts
Last active September 27, 2023 17:22
How to define objects representing webhooks or reducer's actions ( useReducer) as TypeScript definitions to be able to switch/case them up.
/** Action identifiers. */
export const WEBHOOKS_EVENTS = [
"user.created",
"user.updated",
// ...
] as const;
/** Action types. */
export type WebhookEvent = typeof WEBHOOKS_EVENTS[number];
@lopezjurip
lopezjurip / example.tsx
Last active September 25, 2023 16:52
Tailwind buttons and input plugins (btn-*, input-*)
import { clsx } from "clsx"
export function UserFieldset({ disabled, className, ...props } : React.ComponentProps<fieldset>) {
// fieldset has built-in disabled management for inputs and buttons inside of it.
return (
<fieldset className={clsx("grid grid-cols-1 gap-4", className)} disabled={disabled} {...props}>
<div className="col-span-1">
<label htmlFor="name">Name</label/>
<input id="name" name="name" className={clsx("input input-4 sm:input-3 input-blue", "w-full mt-1")} />
</div>
@lopezjurip
lopezjurip / .vscode extensions.json
Last active November 10, 2022 14:55
Easy Rome Tools setup
{
"recommendations": [
"rome.rome",
]
}
@lopezjurip
lopezjurip / gist:cd92f879bc92af698f85ad0433a953cd
Created March 29, 2021 14:11
Migrate Postgres string field to integer if present else null
ALTER TABLE "public"."usage_stats"
ALTER COLUMN "resSize" TYPE INT USING CASE WHEN "resSize" ~ '^[-+0-9]+$' THEN "resSize"::integer ELSE NULL END;
@lopezjurip
lopezjurip / App.tsx
Created December 30, 2020 13:27
React useReducer useContext with Typescript types
import React, { useReducer, useContext, Dispatch } from "react";
import "./styles.css";
// Local types, example: box, product, venue, etc
type MyItem = {
id: number;
name: string;
};
// Reducer types
@lopezjurip
lopezjurip / Dockerfile
Last active May 28, 2020 19:38
A great Dockerfile for Node.js with Typescript and Yarn (multi-step build) and NPM Token for private modules
##
# First stage: prepare image
FROM node:12-alpine AS base
ARG NPM_TOKEN
ARG WORKDIR=/usr/src/app
WORKDIR ${WORKDIR}
# Install container build dependencies
RUN apk --no-cache add g++ ca-certificates lz4-dev musl-dev openssl-dev \
make python gcc zlib-dev libc-dev bsd-compat-headers py-setuptools git bash
@lopezjurip
lopezjurip / gitlab-ci.yml
Created May 23, 2020 17:34
pipenv, zappa and Gitlab CI
image: python:latest
stages:
- deploy
variables:
WORKON_HOME: .pipenv/venvs
PIP_CACHE_DIR: .pipenv/pipcache
cache:
@lopezjurip
lopezjurip / css.json
Created May 22, 2020 19:13
Flexbox snippet for VSCode. Setup this on the CSS lang so it is available in styled-components etc.
{
"Setup basic flexbox styling": {
"prefix": "flex",
"body": [
"display: flex;",
"flex-direction: ${1:column};",
"justify-content: ${2:flex-start};",
"align-items: ${3:flex-start};",
"$0"
],
@lopezjurip
lopezjurip / apollo-quick-client.js
Last active May 12, 2020 19:05
Quickstart Apollo
import { ApolloClient } from "apollo-boost";
import { setContext } from "apollo-link-context";
import { InMemoryCache } from "apollo-cache-inmemory";
export default class APIClient {
constructor(context = {}, options = {}) {
this.context = context;
this.options = { fetchPolicy: "no-cache", ...options };
const authLink = setContext((_, context) => {
return {
@lopezjurip
lopezjurip / hi.js
Created October 28, 2019 09:36
Hi there
console.log("Hello world!");