Skip to content

Instantly share code, notes, and snippets.

View rawnly's full-sized avatar
🧨
fixing my printer

Federico rawnly

🧨
fixing my printer
View GitHub Profile
import { useRef, useEffect, useCallback, useState } from 'react';
const useIsMounted = (): () => boolean => {
const ref = useRef(false);
useEffect(() => {
ref.current = true;
return () => {
ref.current = false;
};
import { useState } from 'react'
const Card = ({ title, onClick }) => (
<div onClick={onClick} className="card">
<h1>{title}</h1>
</div>
)
const Modal = ({ title, onClose }) => (
<div>
import escape from 'sql-template-strings';
import { Except } from 'type-fest';
import { query } from '../lib/db';
import { QueryOutput } from '@interfaces/util';
export interface Schoolr_Partner {
id?: number;
name: string;
deleted: boolean;
}
extension URL {
var canBeOpened: Bool {
return UIApplication.shared.canOpenURL(self)
}
init(string main: String, fallback secondary: String) {
let url = URL(string: main)
@rawnly
rawnly / Field.tsx
Created February 14, 2020 13:46
FormGenerator
import { ValidationOptions, useFormContext, ErrorMessage } from 'react-hook-form';
import {FunctionComponent, useEffect} from 'react';
import cx from 'classnames';
import { ClassValue } from 'classnames/types';
import Select from "./Select";
export interface Props {
label?: string;
name: string;
placeholder?: string;
@rawnly
rawnly / useStorage.ts
Last active February 11, 2020 00:11
Use Session/Local Storage in your react application throught this hook
import { useState } from 'react';
type StorageType = 'local' | 'session';
type SetValueFn<T> = ((item: T) => T) | T;
interface StorageModifiers<T extends {}> {
set: <K extends keyof T = keyof T>(key: K, value: SetValueFn<T[K]>) => void;
get: <K extends keyof T = keyof T>(key?: K) => T[K];
}
function toTS(text: string): string {
return text
.replace(/\n/, '')
.split(';')
.map((row) =>
row
.replace(/public|private|internal|static/gi, '')
.trim()
.replace(/String|Boolean/gi, (v) => v.toLowerCase())
.replace(/Int|Long|Double/gi, 'number')
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
enum Section: CaseIterable {
case one
case two
}
//
// AppDelegate.swift
// Advanced Clock
//
// Created by Federico Vitale on 20/05/2019.
// Copyright © 2019 Federico Vitale. All rights reserved.
//
import Cocoa
@rawnly
rawnly / usePagination.d.ts
Last active November 4, 2019 17:08
Hook to handle SpringBoot (Pageable) pagination.
declare interface PageableParams<T> {
page: number;
size?: number;
sort?: string[];
sortDirection?: 'asc' | 'desc';
query?: string;
}
// The result of the endpoint will be
declare interface Pageable<T> {