Skip to content

Instantly share code, notes, and snippets.

View mmyoji's full-sized avatar
🙃

mmyoji mmyoji

🙃
View GitHub Profile
@mmyoji
mmyoji / commit_message.md
Created December 26, 2020 08:46
Commit message is important

Premises

  • 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.

Good commits and commit messages

  • Simple and clear, the 1st line is a summary of the commit:
@mmyoji
mmyoji / App.tsx
Last active January 13, 2021 13:52
react-redux hooks example in a single file
/**
* @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";
@mmyoji
mmyoji / base64file.ts
Last active July 27, 2021 06:32
Browser JS: File <-> Base64 String
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> {
@mmyoji
mmyoji / AwesomeReactHooks.tsx
Last active July 6, 2021 10:17
8 Awesome React Hooks in TypeScript
// 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(() => {
@mmyoji
mmyoji / reversible_encrypted_attribute.rb
Last active July 8, 2021 09:35
Reversible encryption in RoR
# 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
@mmyoji
mmyoji / for-pg-app.md
Last active June 17, 2022 02:07
TODO list when you create a playground app for new lang, framework or library

Create a playground App

TODO

  • 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
@mmyoji
mmyoji / index.ts
Created September 27, 2021 04:09
[Node.js] TmpFile class
// 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"));
@mmyoji
mmyoji / 0_setup.ts
Last active October 1, 2021 08:40
[Blog][Node.js] stream.Readable
interface Post {
title: string;
}
interface FetchPostsArgs {
skip: number;
limit: number;
}
const BATCH_SIZE = 2;
@mmyoji
mmyoji / main.ts
Created October 2, 2021 06:31
Meta programming in TypeScript
class User {
name: string;
age: number;
#createdAt: Date;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
@mmyoji
mmyoji / query.sql
Last active October 6, 2021 02:19
[SQLime] Check INNER JOIN
SELECT *
FROM orgs
INNER JOIN users
ON users.org_id = orgs.id
AND users.active = true
INNER JOIN users_tasks
ON users_tasks.user_id = users.id
AND users_tasks.status = "active"
INNER JOIN tasks
ON tasks.id = users_tasks.task_id