Skip to content

Instantly share code, notes, and snippets.

@jhonsore
jhonsore / Types.ts
Last active September 5, 2022 16:05
JS typescript enum with types
// Using a model as a type
const taco = 'taco';
type TacoType = typeof taco;
// type TacoType = 'taco'
let bell = 'bell';
type BellType = typeof bell;
// type BellType = string
@jhonsore
jhonsore / README.md
Last active February 8, 2022 12:17
Remove margin and padding from html/body in storybook doc iframe

How to remove margin and padding from html/body in storybook doc iframe

Create a file named preview-body.html in .storybook/ folder

@jhonsore
jhonsore / controler.ts
Created February 1, 2022 11:24
SCC(State, Controller and Component) Pattern
import { useMemo, useState } from "react"
type TController = {
}
export const useController = () => {
const [data, setData] = useState({} as TController);
const [] = useMemo(() => {
@jhonsore
jhonsore / button.tsx
Last active January 28, 2022 16:29
React tips
//found at: https://fettblog.eu/typescript-react/events/
import React, { Component, MouseEvent } from 'react';
export class Button extends Component {
/*
Here we restrict all handleClicks to be exclusively on
HTMLButton Elements
*/
handleClick(event: MouseEvent<HTMLButtonElement>) {
event.preventDefault();
import React from "react";
import ReactDOM from "react-dom";
import styled from "styled-components";
const { useState } = React;
const App = () => {
const [select, setSelect] = useState("optionA");
const handleSelectChange = event => {
@jhonsore
jhonsore / tokens-breakpoints.js
Last active December 9, 2021 14:16
Token categorization for Design System
{
breakpoints: {
}
}
@jhonsore
jhonsore / file-extension.js
Last active October 2, 2021 17:08
Get file extension
// methood 1
function getFileExtension(filename:string) {
return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}
// method 2
function getFileExtension(filename:string) {
filename.substring(filename.lastIndexOf('.')+1);
}
@jhonsore
jhonsore / README.md
Last active October 2, 2021 16:54
Wordpress update host sql

S0metimes, you start your wordpress website in your localhost. All posts and url's are created with your url. When deploying your application, the url must be updated to the new host.

This queries update the wordpress url to a new url.

@jhonsore
jhonsore / fir.js
Created September 22, 2021 20:04
Firestore tips
// Firestore data from a Cloud Function
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.getData = functions.https.onRequest((req, res) => {
const docRef = db.collection('my-collection').doc('doc-id');
const getDoc = docRef.get()
@jhonsore
jhonsore / tips.scss
Created August 8, 2021 01:04
Sass tips
@mixin mobile {
@media (max-width: 425px){
@content;
}
}
@use 'mixins';
p {
font-size: 35px;