Skip to content

Instantly share code, notes, and snippets.

View bryanltobing's full-sized avatar
🏠
Working from home

Bryan Lumbantobing bryanltobing

🏠
Working from home
View GitHub Profile
@bryanltobing
bryanltobing / randomizeArray.tsx
Created January 11, 2023 17:06
A function that returns shuffled value from elements within array with equal possibility
const randomizeArray = <T>(arr: T[]): T => {
for (let i = arr.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr[0];
};
@bryanltobing
bryanltobing / zod-rhf-preview-input-file.tsx
Created August 12, 2022 04:53
zod validation and react hook form for input type file with file preview
import { zodResolver } from "@hookform/resolvers/zod";
import { useMemo } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
const getFileUrl = (file?: File) =>
file ? window.URL.createObjectURL(file) : "";
const FilePage = () => {
const schema = z.object({
@bryanltobing
bryanltobing / zod-file-validation.tsx
Last active April 30, 2024 14:57
Zod schema to validate input type file
import { z } from "zod"
const schema = z.object({
file:
typeof window === "undefined" // this is required if your app rendered in server side, otherwise just remove the ternary condition
? z.undefined()
: z
.instanceof(FileList)
.refine(file => file.length !== 0, {
message: "File is required",
@bryanltobing
bryanltobing / .eslintrc.json
Created July 28, 2022 07:41
Eslint configuration to support javascript and typescript in nextjs apps using airbnb configuration
{
"root": true,
// Javascript eslint configuration
"extends": [
"airbnb",
"airbnb/hooks",
"next",
"next/core-web-vitals",
"prettier"
import { memo } from "react";
import { TextFieldProps, TextField, MenuItem } from "@mui/material";
import { Path, Control, Controller } from "react-hook-form";
export type HookFormSelectProps<TFormValues> = {
name: Path<TFormValues>;
control: Control<TFormValues, any>;
children: React.ReactNode;
} & TextFieldProps;
import {
TextField,
Autocomplete,
AutocompleteProps,
UseAutocompleteProps,
} from "@mui/material";
import React, { memo } from "react";
import { Control, Controller, Path } from "react-hook-form";
type UseAutoCompleteNarrowed<T> = UseAutocompleteProps<
const filterFunction = (list, options) => {
switch (options.option) {
case 'age':
return filerByAgeRange(list, options.payload);
case 'name':
return filerByNames(list, options.payload);
case 'location':
return filterByLocation(list, options.payload);
}
};
#include <iostream>
using namespace std;
int main() {
char pilihan, ulangi;
int i,n=1;
// diketahui
double kb = 0.52, kf = 1.86, nTerlarut = 0.1;
@bryanltobing
bryanltobing / EnergiKinetik.cpp
Last active May 11, 2020 16:16
Mencari Energi kinetik menggunakan rumus ketetepan dan data frekuensi
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n, counter;
double penampungNilaiF[n], ek[n];
double f0 = 5000;