Skip to content

Instantly share code, notes, and snippets.

View mmyoji's full-sized avatar
🙃

mmyoji mmyoji

🙃
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / datediff.ts
Last active July 27, 2021 01:19
Get Date diff (sec, min, hours) like moment.diff with Vanilla JS
const SECONDS = 1000;
const MINUTES = SECONDS * 60;
const HOURS = MINUTES * 60;
interface Result {
hours: number;
minutes: number;
seconds: number;
}
@mmyoji
mmyoji / bundler-inline.rb
Created July 11, 2018 06:36
bundler/inline usage
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "virtus"
end
@mmyoji
mmyoji / dev-team-should-be.md
Last active June 17, 2022 01:42
Dev team should be
  • Using GitHub, GitLab or similar de facto git hosting/collaborating services
  • Many public chat messages, a few private ones
  • Preferring remote/asynchronous communication to synchronous one
  • Well-tested and -documented applications
  • No routine meetings: discuss whenever necessary
  • Higher priority for code review with respecting team mates' motivation
  • Make code/projects public as mush as possible rather than trying hard to write "tech blog"
  • CI/CD
  • linter/formatter: not discuss code styles or preferences during code review
@mmyoji
mmyoji / gem_deprecate.rb
Created May 31, 2018 07:31
Usage of Gem::Deprecate.deprecate
class Test
extend Gem::Deprecate
# DEPRECATED
def foo
puts "foo"
end
def bar
puts "bar"