Skip to content

Instantly share code, notes, and snippets.

@maruware
maruware / Form.tsx
Created November 28, 2019 05:08
form with preventDefault to default
import React, { useCallback } from 'react'
export interface FormProps
extends React.DetailedHTMLProps<
React.FormHTMLAttributes<HTMLFormElement>,
HTMLFormElement
> {}
export const Form: React.FC<FormProps> = ({ onSubmit, ...rest }) => {
const handleSubmit = useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
@maruware
maruware / use-field.ts
Last active October 31, 2019 06:06
react hooks for form fields
import { useState, useCallback } from 'react'
export function useTextField(
initialValue?: string
): [
string | undefined,
(e: React.ChangeEvent<HTMLInputElement>) => void,
React.Dispatch<React.SetStateAction<string | undefined>>
] {
const [val, setVal] = useState(initialValue)
@maruware
maruware / typescriptreact.json
Created September 30, 2019 02:38
VS Code Sinippet: React FC Typescript
{
"React FC": {
"prefix": "rfc",
"body": [
"import React from 'react'",
"export interface ${TM_FILENAME_BASE}Props {",
"}",
"",
"export const ${TM_FILENAME_BASE}: React.FC<${TM_FILENAME_BASE}Props> = () => {",
"}"
@maruware
maruware / wav-to-mp3.sh
Created September 19, 2019 02:34
batch ffmpeg encode
for i in *.wav; do ffmpeg -i $i `basename -s '.wav' $i`.mp3; done
@maruware
maruware / base64_utils.ts
Created September 4, 2019 08:58
Trim Base64 Prefix from Data URL
export const trimBase64TypePrefix = (b64str: string) => {
return b64str.replace(/data:.+;base64,/, '')
}
@maruware
maruware / ImageFileInput.tsx
Created September 4, 2019 07:40
Material UI - Image File Input
import React, { useState, useEffect } from 'react'
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary'
import Button from '@material-ui/core/Button'
import { makeStyles } from '@material-ui/core/styles'
import PlaceholderImage from './PlaceholderImage'
const useStyles = makeStyles(theme => ({
textContainer: {
paddingTop: 0
@maruware
maruware / BasicFileInput.tsx
Created September 4, 2019 07:30
Material UI - Basic File Input
import React from 'react'
import Button from '@material-ui/core/Button'
export interface BasicFileInputProps {
label: string
accept: string
value: File | null
onChange: (file: File | null) => void
}
const BasicFileInput: React.FC<BasicFileInputProps> = ({
@maruware
maruware / QRCodeImage.tsx
Last active August 14, 2019 07:30
React QRCode Element
import React, { useState, useEffect } from 'react'
import QRCode from 'qrcode'
export interface QRCodeImageProps {
value: string
}
const QRCodeImage: React.FC<
QRCodeImageProps & React.ImgHTMLAttributes<HTMLImageElement>
> = ({ value, ...rest }) => {
const [dataUrl, setDataUrl] = useState('')
@maruware
maruware / PlaceholderImage.tsx
Created August 9, 2019 09:02
materil-ui placeholder image
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import ImageIcon from '@material-ui/icons/Image'
interface PlaceHolderImageProps {
width: number
height: number
}
@maruware
maruware / bearer_auth_client.go
Created August 7, 2019 08:34
[go] BearerAuthClient
package test_helper
import (
"fmt"
"io"
"net/http"
)
type BearerAuthClient struct {
token string