- App features:
- public blog posts pages (anyone can see)
- login / logout
- create / update / delete for user's own posts
- signed-in user can view their posts (include draft posts)
- Unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Post { | |
| title: string; | |
| } | |
| interface FetchPostsArgs { | |
| skip: number; | |
| limit: number; | |
| } | |
| const BATCH_SIZE = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/index.ts | |
| async function main() { | |
| const tmpFile = new TmpFile(); | |
| const data = { name: "foo", age: 30 }; | |
| await tmpFile.write("users/1.json", JSON.stringify(data)); | |
| console.log(await tmpFile.read("users/1.json")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| # Use Active Record Encryption for newer version of Rails | |
| # https://edgeguides.rubyonrails.org/active_record_encryption.html | |
| module ReversibleEncryptedAttribute | |
| extend ActiveSupport::Concern | |
| COLUMN_PREFIX = "encrypted" | |
| class_methods do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Original Article: https://thesmartcoder.dev/awesome-react-hooks/ | |
| // | |
| // I just wrote hooks that I'm interested in. | |
| import { useRef, useEffect, useState } from "react"; | |
| function useTimeout(callback: Callback, delay: number) { | |
| const savedCallback = useRef<Callback>(); | |
| useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fileToBase64(file: File): Promise<string | ArrayBuffer | null> { | |
| return new Promise((resolve, reject) => { | |
| const r = new FileReader() | |
| r.onload = () => resolve(r.result) | |
| r.onerror = (err) => reject(err) | |
| r.readAsDataURL(file) | |
| }) | |
| } | |
| async function base64ToFile(str: string, fileName: string = "newfile.txt", type: string = "text/plain"): Promise<File> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @see https://react-redux.js.org/api/hooks | |
| * | |
| * This code is just a sample code for learning | |
| * and several expected features are lacked. | |
| */ | |
| import { ChangeEvent, KeyboardEvent } from "react"; | |
| import { createStore, Reducer } from "redux"; | |
| import { Provider, useDispatch, useSelector } from "react-redux"; |
- This is not religious or philosophy, but art and practice.
- Pursuit rationality and mental health.
- You can apply this to both company projects and your own private project because who u r today is different from who is yesterday.
- Simple and clear, the 1st line is a summary of the commit:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const SECONDS = 1000; | |
| const MINUTES = SECONDS * 60; | |
| const HOURS = MINUTES * 60; | |
| interface Result { | |
| hours: number; | |
| minutes: number; | |
| seconds: number; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| require "bundler/inline" | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "virtus" | |
| end |