Skip to content

Instantly share code, notes, and snippets.

View alexrdz's full-sized avatar
🎥
working

alex rodriguez alexrdz

🎥
working
View GitHub Profile
@alexrdz
alexrdz / template-proposal-framework.md
Last active July 14, 2025 12:48
Simple framework when considering or planning a new component

What Problem Are You Solving?

  • What’s the repeatable problem this component solves? Is this a UI element you’ve needed more than once? Where? Link examples.
  • Why can’t an existing component solve it? Have you tried composing existing components or variants? Be specific.
  • What’s the one-line purpose of this component? “This component exists to [do what], so that users/devs can [why it matters].”*

Tip: If it’s doing more than one thing, you might be trying to build two components in one.

@alexrdz
alexrdz / useFetchWithAbort.ts
Last active March 23, 2025 16:19
Vue composable for fetch operations with Abort Controller
import { ref, computed } from 'vue';
export default function useFetchWithAbort<T>() {
const data = ref<T | null>(null);
const loading = ref(false);
const error = ref<string | null>(null);
const controller = ref<AbortController | null>(null);
async function fetchData(url: string) {
loading.value = true;
@alexrdz
alexrdz / form.php
Created October 10, 2022 01:15 — forked from jacmaes/form.php
Processwire: Front-end upload form example using ProcessWire Inputfields #pw
<?php
/**
* Front-end upload form example
* using ProcessWire Inputfields
*/
$sent = false;
$upload_path = $config->paths->assets . "files/.tmp_uploads/";
@alexrdz
alexrdz / fieldgroup.php
Created April 2, 2022 02:39
Processwire Using API to create and manipulate pages, templates, field, users etc..
<?php
$fg = $this->fieldgroups->get('FIELDGROUP_NAME');
// if not, create it
if(empty($fg)) {
$fg = new Fieldgroup();
$fg->name = 'NAME';
$fg->add($this->fields->get('title'));
$fg->add($this->fields->get('FIELD2'));
$fg->add($this->fields->get('FIELD3'));
@alexrdz
alexrdz / useDimensions.tsx
Created September 24, 2021 18:23
get container dimensions
const useRefDimensions = (ref: React.RefObject<HTMLDivElement>) => {
const [dimensions, setDimensions] = useState({ width: 1, height: 2 })
useEffect(() => {
if (ref.current) {
const boundingRect = ref.current.getBoundingClientRect();
const { width, height } = boundingRect;
setDimensions({ width: Math.round(width), height: Math.round(height) })
}
}, [ref])
@alexrdz
alexrdz / useFontSize.tsx
Last active September 24, 2021 18:20
font size based on container
const useFontSize = (ref: React.RefObject<HTMLDivElement>) => {
const [dimensions, setDimensions] = useState({ width: 100, height: 50 }); // not really needed but in case you need width and/or height
const [fontSize, setFontSize] = useState(14);
const setWidthAndFontSize = (ref: React.RefObject<HTMLDivElement>) => {
if (ref.current) {
const boundingRect = ref.current.getBoundingClientRect();
const { width, height } = boundingRect;
setDimensions({ width: Math.round(width), height: Math.round(height) })
setFontSize(() => width / 6);
@alexrdz
alexrdz / gist:2d4499c50d58ab3efcf5d208391c174a
Created January 4, 2021 14:41
avoid sudo on npm i -g npm
// source: https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92
npm config set prefix ~/.npm
echo 'export PATH="$HOME/.npm/bin:$PATH"' >> ~/.zshrc
@alexrdz
alexrdz / webstoemp-gulpfile.js
Created May 17, 2020 01:39 — forked from jeromecoupe/webstoemp-gulpfile.js
Gulp 4 sample gulpfile.js. For a full explanation, have a look at https://www.webstoemp.com/blog/switching-to-gulp4/
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@alexrdz
alexrdz / findInvalidControls.js
Created April 21, 2020 13:48
find any invalid controls in angular reactive form
const findInvalidControls = () => {
const invalid = [];
const controls = this.jobDetailsForm.controls;
for (const name in controls) {
if (controls[name].invalid) {
invalid.push(name);
}
}
return invalid;
};
@mixin utility-generator($prop, $direction, $iterator) {
@for $index from 1 through $iterator {
@if ($prop == 'padding') {
.p#{$direction}-#{$index} {
@if ($direction == 'x') {
#{$prop}-left: $index * $utility-unit;
#{$prop}-right: $index * $utility-unit;
}