Skip to content

Instantly share code, notes, and snippets.

View Malien's full-sized avatar
🍌
what am I doing here?

Yaroslav Petryk Malien

🍌
what am I doing here?
  • National University of Kyiv-Mohyla Academy
  • Kyiv
View GitHub Profile
@Malien
Malien / TypesafeConfiguration.swift
Last active February 22, 2026 20:25
A POC for the typesafe API for the swift-configuration package
@attached(member, names: named(ConfigProperties))
@attached(extension, conformances: ConfigShape)
public macro ConfigShape() = #externalMacro(module: "TypesafeConfigurationMacros", type: "ConfigShapeMacro")
@attached(peer)
public macro ConfigProperty(key: String) = #externalMacro(module: "TypesafeConfigurationMacros", type: "ConfigPropertyMacro")
import Configuration
protocol ConfigShape {
@Malien
Malien / 1. Using Web Animations API.jsx
Last active November 17, 2024 11:11
Exit animations in react
function Modal({ onClose }) {
const ref = useRef(null)
useLayoutEffect(() => {
// Enter animation
const animation = ref.current.animate(
{ opacity: [0, 1], transform: ["transitionY(-200px)", "transitionY(0)"] },
{ duration: 200, easing: "ease-in" }
)
return () => animation.cancel()
@Malien
Malien / cartesian.swift
Last active October 24, 2024 14:30
Variadic type-safe eager cartesian product in Swift 6
func liftOptional<each Ts>(_ values: repeat (each Ts)?) -> (repeat each Ts)? {
for value in repeat each values {
if value == nil { return nil }
}
return (repeat (each values)!)
}
struct PartialResult<each Element> {
var contents: (repeat (each Element)?)
@Malien
Malien / IDB Bulk Extraction Takeaways.md
Last active July 24, 2024 10:13
IDB Bulk Extraction Benchmark

Was trying to see which method for bulk retrieving data from IndexedDB would perform the best on different data distribution.

Key takeaways:

  • Use Promise.all(keys.map(key => store.get(key))) for most cases (random lookups or even contigiuos-ish cases are mostly fine).
  • Use store.get(KeyRange.bound(lower, upper) when you know you are interested in a contigious range.
  • Avoid cursor API whenever possible. If you are fine with a bit more memory usage, just fetch everything via getAll() and do filtering afterwards.
  • The chunked retrieval is honestly pretty descent, for contigious/contigiuos-ish lookups.
  • When the loads start to look like full-table retrieval (ie. retrieving 80% of the records), Promise.all starts to fall behind. Consider doing full-table retrieval, or, if you are memory constrained, chunked iteration/full-table scan via getAll or cursor API.

Duh.