Skip to content

Instantly share code, notes, and snippets.

@izszzz
izszzz / alphaTexExporter.ts
Last active January 20, 2023 19:05
AlphaTexExporter memo
import { model as Model } from "@coderline/alphatab";
import { match, P } from "ts-pattern";
export const exportTex = (score: Model.Score) => {
let result = "";
const [tracks, metaData] = compileScore(score);
result += metaData;
result += tracks
.map((track) => {
let result = "";
const [staves, metaData] = compileTrack(track);
@izszzz
izszzz / respond_with.rb
Last active July 7, 2022 13:23
respond_with.rb
# frozen_string_literal: true
RSpec.shared_examples 'respond_with' do |http_status, openapi: false|
# openapi
openapi = { summary: metadata[:example_group][:parent_example_group][:parent_example_group][:description] } if openapi
describe '', openapi: openapi do
let(:id) do
super()
rescue StandardError
nil
@izszzz
izszzz / README.md
Last active July 7, 2022 13:17
svg_use_tag

Rails View use tag

Description

  1. instllation svg file

app/assets/images/svg/icon-filename.svg

  1. edit svg file

add attribute id for svg tag

@izszzz
izszzz / getIDfromYoutubeURL.ts
Last active August 15, 2021 14:52
getIDfromYoutubeURL
// https://www.youtube.com/watch?v=:ID
// https://www.youtube.com/channel/:ID
const getIDfromYoutubeURL = (url: string): string | null => {
const newURL = new URL(url);
const { pathname } = newURL;
if (pathname.includes("watch")) return newURL.searchParams.get("v");
if (pathname.includes("channel")) return pathname.split("/")[2];
return null;
};
@izszzz
izszzz / getIDfromURL.ts
Created August 15, 2021 08:34
getIDfromURL
// http://example.com/:ID
const getIDfromURL = (url: string): string =>
new URL(url).pathname.replace(/\//g, "");
export default getIDfromURL;
@izszzz
izszzz / README.md
Last active July 11, 2021 15:37
React usePaginate.ts

usePaginate

Example

import Pagination from '@material-ui/lab/Pagination';

const [page, handlePage] = usePaginate()
<Pagination page={page} onChange={handlePage} />
@izszzz
izszzz / create_user_relationships.rb
Created June 29, 2021 18:45
Rails5 following migration file
class CreateUserRelationships < ActiveRecord::Migration[5.2]
def change
create_table :user_relationships do |t|
t.references :follower, foreign_key: { to_table: :users }
t.references :followed, foreign_key: { to_table: :users }
t.timestamps
t.index [:follower_id, :followed_id], unique: true
end
@izszzz
izszzz / README.md
Last active July 16, 2021 19:56
React useOpen.ts

useOpen

Example

const [open, handleOpen, handleClose] = useOpen()
@izszzz
izszzz / ControlTextField.tsx
Last active September 21, 2021 06:16
react-hook-form&material-ui/TextField
import React, { ChangeEvent } from "react";
import {
Control,
DeepMap,
FieldError,
FieldValues,
RegisterOptions,
useController,
} from "react-hook-form";
import { ErrorMessage } from "@hookform/error-message";
@izszzz
izszzz / README.md
Last active July 19, 2021 19:37
redux-toolkit&devise_token_auth

ReduxToolkit DeviseTokenAuth CurrentUser

Description

save currentUser & header support monky patch

Example