This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.channelFlow | |
import kotlinx.coroutines.isActive | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import kotlin.time.Duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type RefObject, useEffect, useState } from 'react'; | |
function checkOverflow(el: HTMLElement | null): boolean { | |
if (!el) return false; | |
return el.offsetHeight < el.scrollHeight || el.offsetWidth < el.scrollWidth; | |
} | |
export function useHasOverflow(ref: RefObject<HTMLElement | null>) { | |
const [overflow, setOverflow] = useState(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect, useRef, useState } from 'react'; | |
function wrapArray<T>(value: T | T[]): T[] { | |
return Array.isArray(value) ? value : [value]; | |
} | |
type UseFileOnSelectCallbackArg<TMultiple extends boolean | undefined> = | |
TMultiple extends true ? FileList : File; | |
type UseFileOnSelectCallback<TMultiple extends boolean | undefined = false> = ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback } from 'react'; | |
export function useDownload() { | |
return useCallback((obj: Blob | MediaSource, filename: string) => { | |
const url = URL.createObjectURL(obj); | |
const link = document.createElement('a'); | |
link.href = url; | |
if (filename) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -r -d '' INJECT << EOM | |
# Nix | |
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then | |
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' | |
fi | |
# End Nix | |
EOM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class EnumConverter<T : Enum<T>, V>( | |
private val entries: EnumEntries<T>, | |
private val dumpValue: (T) -> V | |
) : AttributeConverter<T, V> { | |
override fun convertToDatabaseColumn(enumValue: T?): V? { | |
return enumValue?.let { dumpValue(it) } | |
} | |
override fun convertToEntityAttribute(dbValue: V?): T? { | |
return dbValue?.let { value -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets a set of duplicates in the given iterable. | |
*/ | |
fun <T> Iterable<T>.duplicates(): Set<T> = duplicatesBy { it } | |
/** | |
* Gets a set of duplicates in the given iterable using the specified selector. | |
*/ | |
fun <T, K> Iterable<T>.duplicatesBy(selector: (T) -> K): Set<K> = | |
groupingBy(selector).eachCount().filterValues { it > 1 }.keys.toSet() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Observable do | |
@moduledoc """ | |
A module that provides creating an observible value that emits the values to | |
a stream. | |
""" | |
alias Observable.Server | |
defstruct [:producer, :consumer] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.redigital.rebased.ext.flow | |
import arrow.core.None | |
import arrow.core.Option | |
import arrow.core.some | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.transform | |
fun <T> Flow<T>.dedup(): Flow<T> = dedupBy { it } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AllowedFieldsWithType<TObj, TKey> = { | |
[K in keyof TObj]: TObj[K] extends TKey ? K : never; | |
}; | |
export type FieldsOfType<T, K> = AllowedFieldsWithType<T, K>[keyof T]; | |
// Usage Example: | |
// | |
// const obj = { | |
// foo: 'bar', |
NewerOlder