Skip to content

Instantly share code, notes, and snippets.

@ethansnow2012
ethansnow2012 / MemoMonad (abstract for dynamic programming)
Last active February 27, 2024 08:11
MemoMonad (abstract for dynamic programming)
--------------------- Lateset ----------------------------
interface MemoStructure<_memoState, _index> {
state: _memoState;
index: _index;
memoAction: (memo: _memoState, _index: _index) => unknown;// this should be passed and used in func in the input of compute
}
class MemoMonad<_memoState, _index, S extends MemoStructure<_memoState, _index>> {
public memo: S;
public rootState?: _memoState;
.text-twoLine{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2; /* number of lines to show */
-webkit-box-orient: vertical;
}
/**
* currying wrapper function that is magical
**/
function curry(f) {
function curried(args) {
if (args.length >= f.length) return f(...args);
return accumulator;
function accumulator(a) {
return curried([...args, a]);
@ethansnow2012
ethansnow2012 / myTypeUtility.txt
Last active November 21, 2023 09:12
Typescript: SameType
/**
* 由其他generic type組成的會優先保持generic的描述,這樣無法“直接”看到單一property的值。
* 用這個解構就可以看到property/value的值,debug或查詢蠻方便的。
*/
type FlatPrettified<T extends any> = {
[P in keyof T]:T[P]
}
/**
* 改變型別的Optional設定,在資料流的旅程中,有部分的路線是Optional的但又不想放寬整個型別設定。
@ethansnow2012
ethansnow2012 / RouterMeta.jsx
Last active April 12, 2022 06:44
React hoc that correct the url after redirected from 404 page.
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom'
export function RouterMeta(props) {
let navigate = useNavigate();
useEffect(()=>{
console.log('RouterMeta navigate')
const href = window.location.href
const newPath = href.split('/?gh-pages-alter')[1]
if(newPath){