Skip to content

Instantly share code, notes, and snippets.

View jsmolina's full-sized avatar

Jordi Sesmero jsmolina

  • Barcelona
View GitHub Profile
@jsmolina
jsmolina / gist:394625ee50fe660a0d076334647f8f3e
Created June 6, 2023 16:31
YUP: Validating a dynamic field object (profiles) that appears when another field (selected_groups) is checked.
profiles: Yup.lazy((value, { parent }) => {
if (value && parent.selected_groups?.length) {
const newEntries = parent.selected_groups.reduce(
(acc, val) => ({
...acc,
[val]: Yup.string().test("hasValue", "item cannot be empty", (value) => {
return !!value;
}),
}),
{}
@jsmolina
jsmolina / TextField.js
Last active June 2, 2023 13:08
Working with a dynamic array of multiple Fields in React Formik (very basic example)
export const TextField = ({name}) => {
const { touched, values, errors, handleBlur, handleChange } = useFormikContext();
const isTouched = getIn(touched, name);
const value = getIn(values, name);
const error = getIn(errors, name);
// getIn automates for you getting values["text"][0]
const isTouched = getIn(touched, name);
const value = getIn(values, name);
@jsmolina
jsmolina / MuiTable.js
Last active June 14, 2023 14:05
Generic Material UI table component, simple! Compatible with mui-datatables
import PropTypes from "prop-types";
import { useCallback, useMemo, useState } from "react";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import TableSortLabel from "@mui/material/TableSortLabel";
import Box from "@mui/material/Box";
// disables weird keyboard behaviours in mac ~/Library/KeyBindings/DefaultKeyBinding.dict
{
"\UF729" = moveToBeginningOfLine:; // home
"\UF72B" = moveToEndOfLine:; // end
"$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home
"$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end
"@\UF700" = noop:; // command-up
"@\UF701" = noop:; // command-down
"$@\UF700" = noop:; // shift-command-up
"$@\UF701" = noop:; // shift-command-down
import os, glob
import shutil
import string
# generates RLOADER https://github.com/marco-sacchi/RLoader LIST.txr
translation_table = dict.fromkeys(map(ord, ' [](),.~!@#$%^&*{}: '), None)
OUT = "/Users/jordism/Downloads/DOS/GAMES"
ROOT = ["./DIST/games1",
"./games2",
"./games3"]
@jsmolina
jsmolina / main.py
Created October 23, 2022 16:42
generates menu for dos launching games
import os, glob
import shutil
import string
translation_table = dict.fromkeys(map(ord, ' [](),.~!@#$%^&*{}: '), None)
# todo use argparse to parametrize
OUT = "./games"
ROOT = ["./DIST/games1",
"./DIST/games2",
"./DIST/games3"]
@jsmolina
jsmolina / gist:5550a0490e1dd327599790c863c706e4
Created April 26, 2022 14:00
Open Macos keyboardAssistant
sudo open /System/Library/CoreServices/KeyboardSetupAssistant.app/Contents/MacOS/KeyboardSetupAssistant
@jsmolina
jsmolina / ec2_monitoring.py
Last active March 21, 2022 15:26
Simple ec2 monitoring for opentelemetry
import botocore.session
from botocore import monitoring
from opentelemetry.trace import get_tracer
from opentelemetry import trace
from opentelemetry.trace import SpanKind
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.instrumentation.utils import (
http_status_to_status_code,
)
@jsmolina
jsmolina / snippet.js
Created March 15, 2022 15:45
React snippet for tracking user enters or leaves a page
const [lastVisit, setLastVisit] = useState(null);
useEffect(
() =>
history.listen((e) => {
logEvent(TrackEvents.PAGE_VISIT, { route: e.pathname });
const now = Date.now() / 1000;
lastVisit &&
logEvent(TrackEvents.PAGE_LEAVE, {
route: lastVisit.path,
@jsmolina
jsmolina / http-servers.go
Created January 27, 2022 12:26
Go Thrift decode server without IDL
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
import "github.com/thrift-iterator/go"
import "github.com/thrift-iterator/go/general"