Skip to content

Instantly share code, notes, and snippets.

View fResult's full-sized avatar

Sila Setthakan-anan fResult

View GitHub Profile
@fResult
fResult / is-not-odd.ts
Last active February 22, 2024 10:05
Make meme for the `is-odd` module
// Usage:
import isEven from "is-not-odd";
isEven(3); // false
isEven(4); // true
// In index.ts of `is-not-odd` module
import isOdd from "is-odd";
type PredicateFn<T> = (...args: [T, ...any[]]) => boolean;
@fResult
fResult / FutureResponseMapperForReactQuery.ts
Last active February 18, 2024 10:17
Higher Order Functions in mapping data fetching Strapi API integrate with React Query
import { compose, isEmpty, map } from 'lodash/fp';
import { useQuery } from '@tanstack/react-query';
// USAGE
// This makes us read "mapStrapiResponse toStaticContent AFTER fetchSomeStaticPageContent"
const fetchAndMapContent: () => Promise<SomeStaticContentAttrs> = compose(
mapStrapiResponse(toStaticContent),
fetchSomeStaticPageContent,
);
const pageContent: SomeStaticContentAttrs = await fetchAndMapContent();
@fResult
fResult / Maximum Sum Segment problem - Naive Solution.ts
Last active February 1, 2024 18:20
copy from the Haskell code in the "Mathematics for Working Programmer class - Day 3-4"
// MSS - Maximum Sum Segment problem
// MSS = maximum . map sum . concat . map inits . tails
// Playground - https://tsplay.dev/mpzE6w
function tail<T>(xs: T[]): T[] {
return xs.slice(1)
}
function init<T>(xs: T[]): T[] {
return xs.slice(0, -1)
}
export type UnaryFn<T, R> = (arg: T) => R;
export function compose<R>(fn: UnaryFn<any, R>): UnaryFn<any, R>;
export function compose<T1, R>(fn1: UnaryFn<T1, R>): UnaryFn<T1, R>;
export function compose<T1, T2, R>(
fn2: UnaryFn<T2, R>,
fn1: UnaryFn<T1, T2>
): UnaryFn<T1, R>;
export function compose<T1, T2, T3, R>(
fn3: UnaryFn<T3, R>,
import IconFacebook from '../components/icons/IconFacebook'
import IconTwitter from '../components/icons/IconTwitter'
function YourPage() {
const [hoveredIcons, setHoveredIcons] = useState({
fb: false,
tw: false,
ig: false,
pt: false,
})
function IconFacebook({ fill = "#FFF", width = 24, height = 24 }) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width={width} height={height}>
<path
fill={fill}
d="M22.675 0H1.325C.593 0 0 .593 0 1.325v21.351C0 23.407.593 24 1.325 24H12.82v-9.294H9.692v-3.622h3.128V8.413c0-3.1 1.893-4.788 4.659-4.788 1.325 0 2.463.099 2.795.143v3.24l-1.918.001c-1.504 0-1.795.715-1.795 1.763v2.313h3.587l-.467 3.622h-3.12V24h6.116c.73 0 1.323-.593 1.323-1.325V1.325C24 .593 23.407 0 22.675 0z"
/>
</svg>
)
}
@fResult
fResult / Day 05 - EP4 (Continue) Functors and natural transformations.md
Last active March 26, 2023 08:33
Day 05 - EP4 (Continue) Functors and natural transformations.md

Functors and natural transformations (Continue)

แบบฝึกหัดจากรอบที่แล้ว

แบบฝึกหัดใหม่

เราจะมารู้เรื่อง Category $\Bbb{Rel}$ กัน แต่ก่อนจะเข้าใจเรื่อง Relation ได้ ต้องเท้าความเรื่อง Category of Set ก่อน กำหนดให้มี Category $\Bbb{Set}$ ที่มี Object เป็น $Set$(s) ต่างๆ มี Morphism เป็น function(s) มี Identity Morphism เป็น $1_x=x$ (หรือ $f\ x=x$)

function cp(start = 0, end = 10) {
const spanParagraphs = document.querySelectorAll('[class^=transcript--underline-cue] > span')
const texts = Array.from(spanParagraphs)
.slice(start, end)
.map(mapInnerText)
.reduce(concat, [])
const result = texts.join(' ').replaceAll('. ', '.\n')
@fResult
fResult / zip.ts
Last active March 26, 2023 08:51
function zip(xs, ys) {
if (xs.length < ys.length) {
return xs.map((x, idx) => [x, ys[idx]])
} else {
return ys.map((y, idx) => [xs[idx], y])
}
}
// FP Style
@fResult
fResult / udemy-copy-subtitle.ts
Last active December 19, 2022 16:51
Write on Dec 15, 2022
// Udemy
function cp() {
copy(document.querySelector('span[class^=well--text]').innerText + ' ')
}
function playPause() {
document.querySelector('.vjs-tech').click()
}
// Linkedin
function cp() {