Skip to content

Instantly share code, notes, and snippets.

View studiofu's full-sized avatar
😱
24 hours coding.....

Johnson Fu studiofu

😱
24 hours coding.....
View GitHub Profile
@studiofu
studiofu / quick select.js
Created July 25, 2023 15:57
quick select
/**
* 快速選擇法(從最小開始),使用迴圈來迭代。
*/
function quickselect(array, index) {
let start = 0;
let end = array.length - 1;
for (; ;) {
if (end === start) {
return start;
/**
* @param {number} k
* @param {number[]} nums
*/
var KthLargest = function(k, nums) {
this.tree = [];
this.k = k;
for(i=0;i<nums.length;i++) {
@studiofu
studiofu / insert.js
Created July 25, 2023 05:21
max heap
class MaxHeap {
constructor() {
this.values = [];
}
insert(val) {
if (val === undefined) return val;
this.values.push(val);
this.values.length > 1 && this.bubbleUp();
return this.values;
@studiofu
studiofu / use_note.ts
Created June 16, 2023 06:04
zustand sample
import { create } from 'zustand';
interface NoteModalStore {
notes: string[];
addNote: (note: string) => void;
removeNote: (note: string) => void;
}
const useNoteModal = create<NoteModalStore>((set) => ({
notes: [],
@studiofu
studiofu / react_hook_form.tsx
Created June 16, 2023 06:03
react hook form
'use client';
import { FieldValues, SubmitHandler, useForm } from 'react-hook-form';
import { ErrorMessage } from '@hookform/error-message';
const Page = () => {
const {
register,
handleSubmit,
@studiofu
studiofu / redux_toolkit_boilerplate_code.js
Last active June 12, 2023 03:51
redux toolkit boilerplate code
https://github.com/studiofu/my_redux_toolkit_test.git
---
implement reducer logic => createSlice => output (dispatch function, reducer (i.e. todoReducer) )
todoReducer => ConfigureStore => store
store => provider in main App
useSelector : get state
@studiofu
studiofu / old_redux_boilerplate_code.js
Last active June 5, 2023 05:02
old redux boilerplate code
https://github.com/studiofu/react-redux-boilerplate-code.git
initial state + root reducer + middleware => create store => store
post reducer => combine reducer => root reducer
initial state + action (type, payload) => reducer function => resolve state
define action function: async dispatch => dispatch actions
@studiofu
studiofu / clean_code.md
Created August 15, 2022 10:18 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

ok

ok

test