Skip to content

Instantly share code, notes, and snippets.

View yurkimus's full-sized avatar
💞

yurkimus yurkimus

💞
View GitHub Profile
@yurkimus
yurkimus / mix.js
Created January 5, 2024 17:08
Average of 3-color tuples
const hexs = [
// Karjala
[ '538854', 'be2928', '000000' ],
// Ludic
[ '529f54', 'be2928', '3d3b7b' ],
// Veps
[ '16b370', 'ffff00', '155cdc' ],
// Russian-side Finnish
[ 'ffd301', 'ef2d20', '0167b3' ],
// Izhorian
@yurkimus
yurkimus / source.js
Last active September 2, 2023 14:27
Reactive URLSearchParams with ramda and react-router
const [searchParams, setSearchParams] = useSearchParams({ [searchParam]: defaultValue, })
useEffect(() => {
setSearchParams(
tap(
when(
compose(anyPass([isEmpty, isNil]), invokeGet(tabSearchParam)),
invokeSet(searchParam, defaultValue)
)
)
@yurkimus
yurkimus / example.js
Last active September 2, 2023 14:28
Building URL with filtered URLSearchParameters
const url = createUrl.bind(null, 'https://jsonplaceholder.typicode.com')
const todosUrl = url('todos', { _limit: 10, _offset: undefined, id: null })
todosUrl.toString() // => 'https://jsonplaceholder.typicode.com/todos?_limit=10'
@yurkimus
yurkimus / source.js
Last active September 2, 2023 14:32
Composing asynchronous functions with ramda
import { request, takeParsed } from 'base-fetch'
import { assoc, __, call, pipeWith, andThen } from 'ramda'
const result = { user: null, todo: null }
const getUser = (properties = result) =>
request('https://jsonplaceholder.typicode.com/users/1')
.then(takeParsed)
.then(assoc('user', __, properties))